diff --git a/testing/utilities/cwd.py b/testing/utilities/cwd.py deleted file mode 100644 index 8a9c5d1..0000000 --- a/testing/utilities/cwd.py +++ /dev/null @@ -1,14 +0,0 @@ -from __future__ import annotations - -import contextlib -import os - - -@contextlib.contextmanager -def cwd(path): - original_cwd = os.getcwd() - os.chdir(path) - try: - yield - finally: - os.chdir(original_cwd) diff --git a/tests/conftest.py b/tests/conftest.py index c9544bf..6b78904 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,7 +15,6 @@ from git_code_debt.util import yaml from git_code_debt.util.subprocess import cmd_output from testing.utilities.auto_namedtuple import auto_namedtuple -from testing.utilities.cwd import cwd @pytest.fixture @@ -70,7 +69,7 @@ def sandbox(tempdir_factory): @pytest.fixture def cloneable(tempdir_factory): repo_path = tempdir_factory.get() - with cwd(repo_path): + with contextlib.chdir(repo_path): subprocess.check_call(('git', 'init', '.')) subprocess.check_call(('git', 'commit', '-m', 'foo', '--allow-empty')) @@ -98,7 +97,7 @@ def make_commit(filename, contents): )) append_commit() - with cwd(cloneable): + with contextlib.chdir(cloneable): # Append a commit for the inital commit append_commit() make_commit('bar.py', '') diff --git a/tests/generate_test.py b/tests/generate_test.py index 63a4004..092cf41 100644 --- a/tests/generate_test.py +++ b/tests/generate_test.py @@ -1,6 +1,7 @@ from __future__ import annotations import collections +import contextlib import os.path import re import sqlite3 @@ -19,7 +20,6 @@ from git_code_debt.metrics.lines import LinesOfCodeParser from git_code_debt.repo_parser import RepoParser from git_code_debt.util.subprocess import cmd_output -from testing.utilities.cwd import cwd def test_increment_metrics_first_time(): @@ -99,7 +99,7 @@ def test_generate_new_data_created(sandbox, cloneable_with_commits): main(('-C', cfg)) before_data_count = get_metric_data_count(sandbox) # Add some commits - with cwd(cloneable_with_commits.path): + with contextlib.chdir(cloneable_with_commits.path): with open('new_file.py', 'w') as f: f.write('# test\n') cmd_output('git', 'add', 'new_file.py') @@ -111,7 +111,7 @@ def test_generate_new_data_created(sandbox, cloneable_with_commits): def test_regression_for_issue_10(sandbox, cloneable): # Create a commit, then create another commit at a previous time - with cwd(cloneable): + with contextlib.chdir(cloneable): cmd_output( 'git', 'commit', '--allow-empty', '-m', 'c1', env=dict( @@ -135,7 +135,7 @@ def test_regression_for_issue_10(sandbox, cloneable): def test_moves_handled_properly(sandbox, cloneable): - with cwd(cloneable): + with contextlib.chdir(cloneable): with open('f', 'w') as f: f.write('foo\nbar\nbaz\n') cmd_output('git', 'add', 'f') @@ -148,7 +148,7 @@ def test_moves_handled_properly(sandbox, cloneable): def test_internal_zero_populated(sandbox, cloneable): - with cwd(cloneable): + with contextlib.chdir(cloneable): with open('f.py', 'w') as f: f.write('# hello world\n') cmd_output('git', 'add', 'f.py')