Skip to content

Commit

Permalink
fix metrics tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Feb 10, 2019
1 parent 36c4a3a commit 5563f13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 18 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,26 @@ def _do_run(self, branch):
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")
Expand Down
12 changes: 4 additions & 8 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,18 +532,14 @@ def test(self):

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):
Expand Down

0 comments on commit 5563f13

Please sign in to comment.