Debian Codegraph @

python/mozversioncontrol/test/test_try_commit.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 import pytest
7
8 from mozversioncontrol import get_repository_object
9 from mozversioncontrol.errors import MissingVCSExtension
10
11
12 def test_try_commit(repo):
13 commit_message = "try commit message"
14 vcs = get_repository_object(repo.dir)
15 initial_head_ref = vcs.head_ref
16
17 # Create a non-empty commit.
18 try:
19 with vcs.try_commit(commit_message, {"try_task_config.json": "{}"}) as head:
20 if vcs.name != "src":
21 assert vcs.get_changed_files(rev=head) == ["try_task_config.json"]
22 except MissingVCSExtension:
23 pytest.xfail("Requires the Mercurial evolve extension.")
24
25 assert (
26 vcs.head_ref == initial_head_ref
27 ), "We should have reverted to previous head after try_commit"
28
29 # Create an empty commit.
30 with vcs.try_commit(commit_message) as head:
31 assert vcs.get_changed_files(rev=head) == []
32
33 assert (
34 vcs.head_ref == initial_head_ref
35 ), "We should have reverted to previous head after try_commit"
36
37
38 if __name__ == "__main__":
39 mozunit.main()