Skip to content

Commit

Permalink
test: add test for stage file format
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
efiop committed Mar 20, 2018
1 parent 6b285e6 commit 7d5f616
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/test_stage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from dvc.output import Output
from dvc.stage import Stage, StageFileFormatError

from tests.basic_env import TestDvc


class TestSchema(TestDvc):
def _validate_fail(self, d):
with self.assertRaises(StageFileFormatError):
Stage.validate(d)


class TestSchemaCmd(TestSchema):
def test_cmd_object(self):
d = {Stage.PARAM_CMD: {}}
self._validate_fail(d)

def test_cmd_none(self):
d = {Stage.PARAM_CMD: None}
Stage.validate(d)

def test_no_cmd(self):
d = {}
Stage.validate(d)

def test_cmd_str(self):
d = {Stage.PARAM_CMD: 'cmd'}
Stage.validate(d)


class TestSchemaDepsOuts(TestSchema):
def test_object(self):
d = {Stage.PARAM_DEPS: {}}
self._validate_fail(d)

d = {Stage.PARAM_OUTS: {}}
self._validate_fail(d)

def test_none(self):
d = {Stage.PARAM_DEPS: None}
Stage.validate(d)

d = {Stage.PARAM_OUTS: None}
Stage.validate(d)

def test_empty_list(self):
d = {Stage.PARAM_DEPS: []}
Stage.validate(d)

d = {Stage.PARAM_OUTS: []}
Stage.validate(d)

def test_list(self):
l = [{Output.PARAM_PATH: 'foo', Output.PARAM_MD5: '123'},
{Output.PARAM_PATH: 'bar', Output.PARAM_MD5: None},
{Output.PARAM_PATH: 'baz'}]
d = {Stage.PARAM_DEPS: l}
Stage.validate(d)

l[0][Output.PARAM_CACHE] = True
l[1][Output.PARAM_CACHE] = False
d = {Stage.PARAM_OUTS: l}
Stage.validate(d)

0 comments on commit 7d5f616

Please sign in to comment.