From 6f0e293c9a02c39bf38fa60794fc17626a1dd606 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 27 Aug 2018 14:17:38 +0300 Subject: [PATCH] test: cover `pipeline show` Signed-off-by: Ruslan Kuprieiev --- dvc/command/pipeline.py | 3 +-- tests/test_pipeline.py | 36 +++++++++++++++++++++++++++++++++++- tests/test_repro.py | 23 ++++++++++++++--------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/dvc/command/pipeline.py b/dvc/command/pipeline.py index 1c0b06263..36a8a8958 100644 --- a/dvc/command/pipeline.py +++ b/dvc/command/pipeline.py @@ -62,8 +62,7 @@ class CmdPipelineShow(CmdBase): edges.append((from_stage.relpath, to_stage.relpath)) nodes = list(nodes) - if len(nodes) == 0: - return + assert len(nodes) > 0 d = Dagascii(nodes, edges) d.draw() diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 265ed47e9..af5d9ea22 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -1,6 +1,6 @@ from dvc.main import main -from tests.test_repro import TestRepro +from tests.test_repro import TestRepro, TestReproChangedDeepData class TestPipelineShow(TestRepro): @@ -35,3 +35,37 @@ class TestPipelineShow(TestRepro): def test_non_existing(self): ret = main(['pipeline', 'show', 'non-existing']) self.assertNotEqual(ret, 0) + + +class TestPipelineShowDeep(TestReproChangedDeepData): + def test(self): + ret = main(['pipeline', 'show', self.file1_stage]) + self.assertEqual(ret, 0) + + def test_commands(self): + ret = main(['pipeline', 'show', self.file1_stage, '--commands']) + self.assertEqual(ret, 0) + + def test_outs(self): + ret = main(['pipeline', 'show', self.file1_stage, '--outs']) + self.assertEqual(ret, 0) + + def test_ascii(self): + ret = main(['pipeline', 'show', '--ascii', self.file1_stage]) + self.assertEqual(ret, 0) + + def test_ascii_commands(self): + ret = main(['pipeline', 'show', '--ascii', self.file1_stage, '--commands']) + self.assertEqual(ret, 0) + + def test_ascii_outs(self): + ret = main(['pipeline', 'show', '--ascii', self.file1_stage, '--outs']) + self.assertEqual(ret, 0) + + def test_not_dvc_file(self): + ret = main(['pipeline', 'show', self.file1]) + self.assertNotEqual(ret, 0) + + def test_non_existing(self): + ret = main(['pipeline', 'show', 'non-existing']) + self.assertNotEqual(ret, 0) diff --git a/tests/test_repro.py b/tests/test_repro.py index f5af30043..1e1441ad1 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -146,20 +146,25 @@ class TestReproDry(TestReproChangedData): class TestReproChangedDeepData(TestReproChangedData): - def test(self): - file2 = 'file2' - file2_stage = file2 + '.dvc' - self.dvc.run(fname=file2_stage, - outs=[file2], - deps=[self.file1, self.CODE], - cmd='python {} {} {}'.format(self.CODE, self.file1, file2)) + def setUp(self): + super(TestReproChangedDeepData, self).setUp() + self.file2 = 'file2' + self.file2_stage = self.file2 + '.dvc' + self.dvc.run(fname=self.file2_stage, + outs=[self.file2], + deps=[self.file1, self.CODE], + cmd='python {} {} {}'.format(self.CODE, + self.file1, + self.file2)) + + def test(self): self.swap_foo_with_bar() - stages = self.dvc.reproduce(file2_stage) + stages = self.dvc.reproduce(self.file2_stage) self.assertTrue(filecmp.cmp(self.file1, self.BAR, shallow=False)) - self.assertTrue(filecmp.cmp(file2, self.BAR, shallow=False)) + self.assertTrue(filecmp.cmp(self.file2, self.BAR, shallow=False)) self.assertEqual(len(stages), 3)