Skip to content

Commit 1fd0561

Browse files
committed
[test] Test update_checkout --dump-hashes output
1 parent ccdce9f commit 1fd0561

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

utils/update_checkout/tests/scheme_mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __str__(self):
7878
def call_quietly(*args, **kwargs):
7979
kwargs['stderr'] = subprocess.STDOUT
8080
try:
81-
subprocess.check_output(*args, **kwargs)
81+
return subprocess.check_output(*args, **kwargs)
8282
except subprocess.CalledProcessError as e:
8383
raise CallQuietlyException(command=e.cmd, returncode=e.returncode,
8484
output=e.stdout) from e
@@ -180,7 +180,7 @@ def tearDown(self):
180180

181181
def call(self, *args, **kwargs):
182182
kwargs['cwd'] = self.source_root
183-
call_quietly(*args, **kwargs)
183+
return call_quietly(*args, **kwargs)
184184

185185
def get_all_repos(self):
186186
return list(self.config["repos"].keys())

utils/update_checkout/tests/test_dump.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#
1111
# ===----------------------------------------------------------------------===#
1212

13+
import json
14+
1315
from . import scheme_mock
1416

1517

@@ -25,9 +27,16 @@ def test_dump_hashes_json(self):
2527
'--source-root', self.source_root,
2628
'--clone'])
2729

28-
# Then dump the hashes. Just make sure we don't crash. We should test
29-
# the output as well. But we should never crash.
30-
self.call([self.update_checkout_path,
31-
'--config', self.config_path,
32-
'--source-root', self.source_root,
33-
'--dump-hashes'])
30+
# Then dump the hashes.
31+
output = self.call([self.update_checkout_path,
32+
'--config', self.config_path,
33+
'--source-root', self.source_root,
34+
'--dump-hashes'])
35+
# The output should be valid JSON
36+
result = json.loads(output)
37+
38+
# And it should have some basic properties we expect from this JSON
39+
self.assertIn("https-clone-pattern", result)
40+
self.assertEqual(result["repos"], scheme_mock.MOCK_CONFIG["repos"])
41+
self.assertEqual(result["ssh-clone-pattern"], "DO_NOT_USE")
42+
self.assertSetEqual(set(result["branch-schemes"].keys()), {"repro"})

0 commit comments

Comments
 (0)