Skip to content

Commit c5f00f8

Browse files
committed
refactor commit
1 parent c344156 commit c5f00f8

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

tools/src/test/python/test_mercurial.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,7 @@
3333
from opengrok_tools.utils.command import Command
3434

3535

36-
def add_commit_file(file_path, repo_path, comment):
37-
"""
38-
:param file_path: path to the file to be created
39-
:param repo_path: Mercurial repository path
40-
:param comment: content and commit comment
41-
"""
42-
with open(file_path, "w") as fp:
43-
fp.write(comment)
44-
assert os.path.exists(file_path)
45-
46-
cmd = Command(["hg", "add", file_path], work_dir=repo_path)
47-
cmd.execute()
48-
assert cmd.getretcode() == 0
49-
36+
def hg_commit_file(file_path, repo_path, comment):
5037
cmd = Command(
5138
[
5239
"hg",
@@ -63,6 +50,23 @@ def add_commit_file(file_path, repo_path, comment):
6350
assert cmd.getretcode() == 0
6451

6552

53+
def hg_add_commit_file(file_path, repo_path, comment):
54+
"""
55+
:param file_path: path to the file to be created
56+
:param repo_path: Mercurial repository path
57+
:param comment: content and commit comment
58+
"""
59+
with open(file_path, "w", encoding="ascii") as fp:
60+
fp.write(comment)
61+
assert os.path.exists(file_path)
62+
63+
cmd = Command(["hg", "add", file_path], work_dir=repo_path)
64+
cmd.execute()
65+
assert cmd.getretcode() == 0
66+
67+
hg_commit_file(file_path, repo_path, comment)
68+
69+
6670
@pytest.mark.parametrize("create_file_in_parent", [True, False])
6771
@pytest.mark.skipif(shutil.which("hg") is None, reason="need hg")
6872
def test_strip_outgoing(create_file_in_parent):
@@ -82,7 +86,7 @@ def test_strip_outgoing(create_file_in_parent):
8286
#
8387
if create_file_in_parent:
8488
file_path = os.path.join(repo_parent_path, file_name)
85-
add_commit_file(file_path, repo_parent_path, "parent")
89+
hg_add_commit_file(file_path, repo_parent_path, "parent")
8690

8791
# Clone the repository and create couple of new changesets.
8892
repo_clone_path = os.path.join(test_root, "clone")
@@ -93,13 +97,11 @@ def test_strip_outgoing(create_file_in_parent):
9397
assert cmd.getretcode() == 0
9498

9599
file_path = os.path.join(repo_clone_path, file_name)
96-
add_commit_file(file_path, repo_clone_path, "first")
100+
hg_add_commit_file(file_path, repo_clone_path, "first")
97101

98-
with open(file_path, "a") as fp:
102+
with open(file_path, "a", encoding="ascii") as fp:
99103
fp.write("bar")
100-
cmd = Command(["hg", "commit", "-m", "second"], work_dir=repo_clone_path)
101-
cmd.execute()
102-
assert cmd.getretcode() == 0
104+
hg_commit_file(file_path, repo_clone_path, "second")
103105

104106
# Strip the changesets.
105107
repository = MercurialRepository(

0 commit comments

Comments
 (0)