From 61e3e20df03f2d8db70af00070411f0e30853777 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 13 Mar 2024 17:32:24 -0400 Subject: [PATCH] Refactor test --- tests/test_impls.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_impls.py b/tests/test_impls.py index c7abb95..9f30641 100644 --- a/tests/test_impls.py +++ b/tests/test_impls.py @@ -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: @@ -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)