mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
* test: remove never used copy of load_stage_file() * dvc: save comments and custom formatting in stage files * Add a couple of TODOs * test: test repro doesn't clear comments and formatting in .dvc As part of this I started writing pytest-like tests and added commonly used fixtures. * test: simplify and prettify dvc formatting retained test Also test that line comments after md5 fields are retained. * test: fix tests * dvc: fix stage and metrics opens not closed * dvc: always use utf-8 in stage files It used to encode in system default encoding. Not sure if PyYAML was handling this silently or we were just lucky all the way. * test: unit test apply_diff() * test: remove TODOs and ASK * dvc: polish dvc-formatting PR * dvc: move stage load/dump utils to a new stage utils file * dvc: clean up apply_diff() * test: test stage md5 ignores comments * test: remove pytests starting marker
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
from dvc.utils.stage import load_stage_file, dump_stage_file
|
|
|
|
from tests.basic_env import TestDvc
|
|
from dvc.stage import StageCommitError
|
|
|
|
|
|
class TestCommitRecursive(TestDvc):
|
|
def test(self):
|
|
stages = self.dvc.add(self.DATA_DIR, recursive=True, no_commit=True)
|
|
self.assertEqual(len(stages), 2)
|
|
|
|
self.assertNotEqual(self.dvc.status(), {})
|
|
|
|
self.dvc.commit(self.DATA_DIR, recursive=True)
|
|
|
|
self.assertEqual(self.dvc.status(), {})
|
|
|
|
|
|
class TestCommitForce(TestDvc):
|
|
def test(self):
|
|
stages = self.dvc.add(self.FOO, no_commit=True)
|
|
self.assertEqual(len(stages), 1)
|
|
stage = stages[0]
|
|
|
|
with self.dvc.state:
|
|
self.assertTrue(stage.outs[0].changed_cache())
|
|
|
|
with open(self.FOO, "a") as fobj:
|
|
fobj.write(self.FOO_CONTENTS)
|
|
|
|
with self.dvc.state:
|
|
self.assertTrue(stage.outs[0].changed_cache())
|
|
|
|
with self.assertRaises(StageCommitError):
|
|
self.dvc.commit(stage.path)
|
|
|
|
with self.dvc.state:
|
|
self.assertTrue(stage.outs[0].changed_cache())
|
|
|
|
self.dvc.commit(stage.path, force=True)
|
|
|
|
self.assertEqual(self.dvc.status(stage.path), {})
|
|
|
|
|
|
class TestCommitWithDeps(TestDvc):
|
|
def test(self):
|
|
stages = self.dvc.add(self.FOO, no_commit=True)
|
|
self.assertEqual(len(stages), 1)
|
|
foo_stage = stages[0]
|
|
self.assertTrue(foo_stage is not None)
|
|
self.assertEqual(len(foo_stage.outs), 1)
|
|
|
|
fname = "file"
|
|
stage = self.dvc.run(
|
|
cmd="python {} {} {}".format(self.CODE, self.FOO, fname),
|
|
outs=[fname],
|
|
deps=[self.FOO, self.CODE],
|
|
no_commit=True,
|
|
)
|
|
self.assertTrue(stage is not None)
|
|
self.assertEqual(len(stage.outs), 1)
|
|
|
|
with self.dvc.state:
|
|
self.assertTrue(foo_stage.outs[0].changed_cache())
|
|
self.assertTrue(stage.outs[0].changed_cache())
|
|
|
|
self.dvc.commit(stage.path, with_deps=True)
|
|
with self.dvc.state:
|
|
self.assertFalse(foo_stage.outs[0].changed_cache())
|
|
self.assertFalse(stage.outs[0].changed_cache())
|
|
|
|
|
|
class TestCommitChangedMd5(TestDvc):
|
|
def test(self):
|
|
stages = self.dvc.add(self.FOO, no_commit=True)
|
|
self.assertEqual(len(stages), 1)
|
|
stage = stages[0]
|
|
|
|
st = load_stage_file(stage.path)
|
|
st["md5"] = "1111111111"
|
|
dump_stage_file(stage.path, st)
|
|
|
|
with self.assertRaises(StageCommitError):
|
|
self.dvc.commit(stage.path)
|
|
|
|
self.dvc.commit(stage.path, force=True)
|