fix metrics tests on windows

This commit is contained in:
Ivan Shcheklein
2019-02-09 19:57:41 -08:00
parent 36c4a3a5af
commit 5563f13273
2 changed files with 22 additions and 10 deletions
+18 -2
View File
@@ -378,10 +378,26 @@ class TestCachedMetrics(TestDvc):
self.dvc.scm.checkout(branch)
self.dvc.checkout(force=True)
content = json.dumps({"metrics": branch})
print(
'print(json.dumps({{"metrics": "{branch}"}})\n'.format(
branch=branch
)
)
with open("code.py", "w+") as fobj:
fobj.write("import sys\n")
fobj.write("import os\n")
fobj.write("import json\n")
fobj.write(
'print(json.dumps({{"metrics": "{branch}"}}))\n'.format(
branch=branch
)
)
stage = self.dvc.run(
deps=["code.py"],
metrics=["metrics.json"],
cmd="echo '{content}' > metrics.json".format(content=content),
cmd="python code.py metrics.json > metrics.json",
)
self.assertIsNotNone(stage)
self.assertEqual(stage.relpath, "metrics.json.dvc")
+4 -8
View File
@@ -532,18 +532,14 @@ class TestCmdRunOverwrite(TestDvc):
class TestCmdRunCliMetrics(TestDvc):
def test_cached(self):
ret = main(
["run", "-m", "metrics.txt", "echo -n 'test' > metrics.txt"]
)
ret = main(["run", "-m", "metrics.txt", "echo 'test' > metrics.txt"])
self.assertEqual(ret, 0)
self.assertEqual(open("metrics.txt", "r").read(), "test")
self.assertEqual(open("metrics.txt", "r").read().rstrip(), "test")
def test_not_cached(self):
ret = main(
["run", "-M", "metrics.txt", "echo -n 'test' > metrics.txt"]
)
ret = main(["run", "-M", "metrics.txt", "echo 'test' > metrics.txt"])
self.assertEqual(ret, 0)
self.assertEqual(open("metrics.txt", "r").read(), "test")
self.assertEqual(open("metrics.txt", "r").read().rstrip(), "test")
class TestRunDeterministicBase(TestDvc):