Debian Codegraph @

python/mozversioncontrol/test/test_context_manager.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import mozunit
6
7 from mozversioncontrol import get_repository_object
8
9
10 def test_context_manager(repo):
11 cmd = {
12 "git": ["show", "--no-patch"],
13 "hg": ["tip"],
14 "jj": ["show", "@-"],
15 "src": ["echo", "src"],
16 }[repo.vcs]
17
18 vcs = get_repository_object(repo.dir)
19 output_subprocess = vcs._run(*cmd)
20 if repo.vcs == "hg":
21 assert vcs._client.server is None
22 if repo.vcs != "src":
23 assert "Initial commit" in output_subprocess
24
25 with vcs:
26 if repo.vcs == "hg":
27 assert vcs._client.server is not None
28 output_client = vcs._run(*cmd)
29
30 if repo.vcs == "hg":
31 assert vcs._client.server is None
32 assert output_subprocess == output_client
33
34
35 if __name__ == "__main__":
36 mozunit.main()