Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Mar 13, 2024
1 parent f73725c commit 61e3e20
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/test_impls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
)
@patch("rapids_build_backend.impls._get_git_commit", Mock(return_value="abc123"))
def test_edit_git_commit(commit_file_type, initial_contents, expected_contents):
def check_initial_contents(filename):
if initial_contents is not None:
with open(filename) as f:
assert f.read() == initial_contents
else:
assert not os.path.exists(filename)

with tempfile.TemporaryDirectory() as d:
commit_file = os.path.join(d, "commit-file")
if initial_contents is not None:
Expand All @@ -44,15 +51,8 @@ def test_edit_git_commit(commit_file_type, initial_contents, expected_contents):
with _edit_git_commit(config):
with open(commit_file) as f:
assert f.read() == expected_contents
bkp_file = os.path.join(d, ".commit-file.rapids-build-backend.bak")
if initial_contents is not None:
with open(bkp_file) as f:
assert f.read() == initial_contents
else:
assert not os.path.exists(bkp_file)
check_initial_contents(
os.path.join(d, ".commit-file.rapids-build-backend.bak")
)

if initial_contents is not None:
with open(commit_file) as f:
assert f.read() == initial_contents
else:
assert not os.path.exists(commit_file)
check_initial_contents(commit_file)

0 comments on commit 61e3e20

Please sign in to comment.