|
1 | 1 | import hashlib |
| 2 | +import json |
2 | 3 | import os |
3 | 4 | import pytest |
4 | 5 |
|
| 6 | +from dvc.main import main |
| 7 | + |
5 | 8 |
|
6 | 9 | def digest(text): |
7 | 10 | return hashlib.md5(bytes(text, "utf-8")).hexdigest() |
@@ -126,7 +129,7 @@ def test_directories(tmp_dir, scm, dvc): |
126 | 129 | assert dvc.diff(":/init", ":/directory") == { |
127 | 130 | "added": [ |
128 | 131 | { |
129 | | - "filename": os.path.dir("dir", ""), |
| 132 | + "filename": os.path.join("dir", ""), |
130 | 133 | "checksum": "5fb6b29836c388e093ca0715c872fe2a.dir", |
131 | 134 | }, |
132 | 135 | {"filename": os.path.join("dir", "1"), "checksum": digest("1")}, |
@@ -179,13 +182,19 @@ def test_cli(tmp_dir, scm, dvc): |
179 | 182 | pytest.skip("TODO: define output structure") |
180 | 183 |
|
181 | 184 |
|
182 | | -def test_json(tmp_dir, scm, dvc): |
183 | | - # result = { |
184 | | - # "added": {...}, |
185 | | - # "renamed": {...}, |
186 | | - # "modified": {...}, |
187 | | - # "deleted": {...}, |
188 | | - # } |
| 185 | +def test_json(tmp_dir, scm, dvc, capsys): |
| 186 | + assert 0 == main(["diff", "--json"]) |
| 187 | + assert not capsys.readouterr().out |
189 | 188 |
|
190 | | - # main(["diff", "--json"]) |
191 | | - pytest.skip("TODO: define output structure") |
| 189 | + tmp_dir.dvc_gen("file", "text") |
| 190 | + assert 0 == main(["diff", "--json"]) |
| 191 | + assert ( |
| 192 | + json.dumps( |
| 193 | + { |
| 194 | + "added": [{"filename": "file", "checksum": digest("text")}], |
| 195 | + "deleted": [], |
| 196 | + "modified": [], |
| 197 | + } |
| 198 | + ) |
| 199 | + in capsys.readouterr().out |
| 200 | + ) |
0 commit comments