Skip to content

Commit 633669f

Browse files
committed
relink tests: Delete unused fixtures.
1 parent 05e25b5 commit 633669f

6 files changed

Lines changed: 85 additions & 315 deletions

File tree

tests/relink/test_args.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020
import relink # noqa: E402
2121

2222

23-
@pytest.fixture(scope="function", autouse=True)
24-
def configure_logging():
25-
"""Configure logging to output to stdout for all tests."""
26-
# Configure logging before each test
27-
logging.basicConfig(
28-
level=logging.INFO,
29-
format="%(message)s",
30-
stream=sys.stdout,
31-
force=True, # Force reconfiguration
32-
)
33-
yield
34-
# Clean up logging handlers after each test
35-
logging.getLogger().handlers.clear()
36-
37-
3823
@pytest.fixture(scope="function", name="mock_default_dirs")
3924
def fixture_mock_default_dirs():
4025
"""Mock the default directories to use temporary directories."""
@@ -50,19 +35,6 @@ def fixture_mock_default_dirs():
5035
shutil.rmtree(target_dir, ignore_errors=True)
5136

5237

53-
@pytest.fixture(scope="function", name="temp_dirs")
54-
def fixture_temp_dirs():
55-
"""Create temporary source and target directories for testing."""
56-
source_dir = tempfile.mkdtemp(prefix="test_source_")
57-
target_dir = tempfile.mkdtemp(prefix="test_target_")
58-
59-
yield source_dir, target_dir
60-
61-
# Cleanup
62-
shutil.rmtree(source_dir, ignore_errors=True)
63-
shutil.rmtree(target_dir, ignore_errors=True)
64-
65-
6638
class TestParseArguments:
6739
"""Test suite for parse_arguments function."""
6840

tests/relink/test_cmdline.py

Lines changed: 85 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -4,152 +4,93 @@
44

55
import os
66
import sys
7-
import tempfile
8-
import shutil
9-
import logging
107
import subprocess
11-
from unittest.mock import patch
128

139
import pytest
1410

15-
# Add parent directory to path to import relink module
16-
sys.path.insert(
17-
0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18-
)
19-
# pylint: disable=wrong-import-position
20-
import relink # noqa: E402
21-
22-
23-
@pytest.fixture(scope="function", autouse=True)
24-
def configure_logging():
25-
"""Configure logging to output to stdout for all tests."""
26-
# Configure logging before each test
27-
logging.basicConfig(
28-
level=logging.INFO,
29-
format="%(message)s",
30-
stream=sys.stdout,
31-
force=True, # Force reconfiguration
11+
12+
@pytest.fixture(name="mock_dirs")
13+
def fixture_mock_dirs(tmp_path):
14+
"""Create temporary directories and files for command-line testing."""
15+
source_dir = tmp_path / "source"
16+
target_dir = tmp_path / "target"
17+
source_dir.mkdir()
18+
target_dir.mkdir()
19+
20+
# Create a test file
21+
source_file = source_dir / "test_file.txt"
22+
target_file = target_dir / "test_file.txt"
23+
source_file.write_text("source content")
24+
target_file.write_text("target content")
25+
26+
return source_dir, target_dir, source_file, target_file
27+
28+
29+
def test_command_line_execution_dry_run(mock_dirs):
30+
"""Test executing relink.py from command line with --dry-run flag."""
31+
source_dir, target_dir, source_file, _ = mock_dirs
32+
33+
# Get the path to relink.py
34+
relink_script = os.path.join(
35+
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
36+
"relink.py",
37+
)
38+
39+
# Build the command
40+
command = [
41+
sys.executable,
42+
relink_script,
43+
"--source-root",
44+
str(source_dir),
45+
"--target-root",
46+
str(target_dir),
47+
"--dry-run",
48+
]
49+
50+
# Execute the command
51+
result = subprocess.run(command, capture_output=True, text=True, check=False)
52+
53+
# Verify the command executed successfully
54+
assert result.returncode == 0, f"Command failed with stderr: {result.stderr}"
55+
56+
# Verify dry-run messages in output
57+
assert "DRY RUN MODE" in result.stdout
58+
assert "[DRY RUN] Would create symbolic link:" in result.stdout
59+
60+
# Verify no actual changes were made
61+
assert source_file.is_file()
62+
assert not source_file.is_symlink()
63+
64+
65+
def test_command_line_execution_actual_run(mock_dirs):
66+
"""Test executing relink.py from command line without dry-run."""
67+
source_dir, target_dir, source_file, target_file = mock_dirs
68+
69+
# Get the path to relink.py
70+
relink_script = os.path.join(
71+
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
72+
"relink.py",
3273
)
33-
yield
34-
# Clean up logging handlers after each test
35-
logging.getLogger().handlers.clear()
36-
37-
38-
@pytest.fixture(scope="function", name="mock_default_dirs")
39-
def fixture_mock_default_dirs():
40-
"""Mock the default directories to use temporary directories."""
41-
source_dir = tempfile.mkdtemp(prefix="test_default_source_")
42-
target_dir = tempfile.mkdtemp(prefix="test_default_target_")
43-
44-
with patch.object(relink, "DEFAULT_SOURCE_ROOT", source_dir):
45-
with patch.object(relink, "DEFAULT_TARGET_ROOT", target_dir):
46-
yield source_dir, target_dir
47-
48-
# Cleanup
49-
shutil.rmtree(source_dir, ignore_errors=True)
50-
shutil.rmtree(target_dir, ignore_errors=True)
51-
52-
53-
@pytest.fixture(scope="function", name="temp_dirs")
54-
def fixture_temp_dirs():
55-
"""Create temporary source and target directories for testing."""
56-
source_dir = tempfile.mkdtemp(prefix="test_source_")
57-
target_dir = tempfile.mkdtemp(prefix="test_target_")
58-
59-
yield source_dir, target_dir
60-
61-
# Cleanup
62-
shutil.rmtree(source_dir, ignore_errors=True)
63-
shutil.rmtree(target_dir, ignore_errors=True)
64-
65-
66-
class TestCommandLineExecution:
67-
"""Test suite for command-line execution of relink.py."""
68-
69-
@pytest.fixture
70-
def mock_dirs(self, tmp_path):
71-
"""Create temporary directories and files for command-line testing."""
72-
source_dir = tmp_path / "source"
73-
target_dir = tmp_path / "target"
74-
source_dir.mkdir()
75-
target_dir.mkdir()
76-
77-
# Create a test file
78-
source_file = source_dir / "test_file.txt"
79-
target_file = target_dir / "test_file.txt"
80-
source_file.write_text("source content")
81-
target_file.write_text("target content")
82-
83-
return source_dir, target_dir, source_file, target_file
84-
85-
def test_command_line_execution_dry_run(self, mock_dirs):
86-
"""Test executing relink.py from command line with --dry-run flag."""
87-
source_dir, target_dir, source_file, _ = mock_dirs
88-
89-
# Get the path to relink.py
90-
relink_script = os.path.join(
91-
os.path.dirname(
92-
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
93-
),
94-
"relink.py",
95-
)
96-
97-
# Build the command
98-
command = [
99-
sys.executable,
100-
relink_script,
101-
"--source-root",
102-
str(source_dir),
103-
"--target-root",
104-
str(target_dir),
105-
"--dry-run",
106-
]
107-
108-
# Execute the command
109-
result = subprocess.run(command, capture_output=True, text=True, check=False)
110-
111-
# Verify the command executed successfully
112-
assert result.returncode == 0, f"Command failed with stderr: {result.stderr}"
113-
114-
# Verify dry-run messages in output
115-
assert "DRY RUN MODE" in result.stdout
116-
assert "[DRY RUN] Would create symbolic link:" in result.stdout
117-
118-
# Verify no actual changes were made
119-
assert source_file.is_file()
120-
assert not source_file.is_symlink()
121-
122-
def test_command_line_execution_actual_run(self, mock_dirs):
123-
"""Test executing relink.py from command line without dry-run."""
124-
source_dir, target_dir, source_file, target_file = mock_dirs
125-
126-
# Get the path to relink.py
127-
relink_script = os.path.join(
128-
os.path.dirname(
129-
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
130-
),
131-
"relink.py",
132-
)
133-
134-
# Build the command
135-
command = [
136-
sys.executable,
137-
relink_script,
138-
"--source-root",
139-
str(source_dir),
140-
"--target-root",
141-
str(target_dir),
142-
]
143-
144-
# Execute the command
145-
result = subprocess.run(command, capture_output=True, text=True, check=False)
146-
147-
# Verify the command executed successfully
148-
assert result.returncode == 0, f"Command failed with stderr: {result.stderr}"
149-
150-
# Verify the file was converted to a symlink
151-
assert source_file.is_symlink()
152-
assert os.readlink(str(source_file)) == str(target_file)
153-
154-
# Verify success messages in output
155-
assert "Created symbolic link:" in result.stdout
74+
75+
# Build the command
76+
command = [
77+
sys.executable,
78+
relink_script,
79+
"--source-root",
80+
str(source_dir),
81+
"--target-root",
82+
str(target_dir),
83+
]
84+
85+
# Execute the command
86+
result = subprocess.run(command, capture_output=True, text=True, check=False)
87+
88+
# Verify the command executed successfully
89+
assert result.returncode == 0, f"Command failed with stderr: {result.stderr}"
90+
91+
# Verify the file was converted to a symlink
92+
assert source_file.is_symlink()
93+
assert os.readlink(str(source_file)) == str(target_file)
94+
95+
# Verify success messages in output
96+
assert "Created symbolic link:" in result.stdout

tests/relink/test_dryrun.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import tempfile
88
import shutil
99
import logging
10-
from unittest.mock import patch
1110

1211
import pytest
1312

@@ -19,36 +18,6 @@
1918
import relink # noqa: E402
2019

2120

22-
@pytest.fixture(scope="function", autouse=True)
23-
def configure_logging():
24-
"""Configure logging to output to stdout for all tests."""
25-
# Configure logging before each test
26-
logging.basicConfig(
27-
level=logging.INFO,
28-
format="%(message)s",
29-
stream=sys.stdout,
30-
force=True, # Force reconfiguration
31-
)
32-
yield
33-
# Clean up logging handlers after each test
34-
logging.getLogger().handlers.clear()
35-
36-
37-
@pytest.fixture(scope="function", name="mock_default_dirs")
38-
def fixture_mock_default_dirs():
39-
"""Mock the default directories to use temporary directories."""
40-
source_dir = tempfile.mkdtemp(prefix="test_default_source_")
41-
target_dir = tempfile.mkdtemp(prefix="test_default_target_")
42-
43-
with patch.object(relink, "DEFAULT_SOURCE_ROOT", source_dir):
44-
with patch.object(relink, "DEFAULT_TARGET_ROOT", target_dir):
45-
yield source_dir, target_dir
46-
47-
# Cleanup
48-
shutil.rmtree(source_dir, ignore_errors=True)
49-
shutil.rmtree(target_dir, ignore_errors=True)
50-
51-
5221
@pytest.fixture(scope="function", name="temp_dirs")
5322
def fixture_temp_dirs():
5423
"""Create temporary source and target directories for testing."""

tests/relink/test_find_and_replace_owned_files.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,6 @@
2020
import relink # noqa: E402
2121

2222

23-
@pytest.fixture(scope="function", autouse=True)
24-
def configure_logging():
25-
"""Configure logging to output to stdout for all tests."""
26-
# Configure logging before each test
27-
logging.basicConfig(
28-
level=logging.INFO,
29-
format="%(message)s",
30-
stream=sys.stdout,
31-
force=True, # Force reconfiguration
32-
)
33-
yield
34-
# Clean up logging handlers after each test
35-
logging.getLogger().handlers.clear()
36-
37-
38-
@pytest.fixture(scope="function", name="mock_default_dirs")
39-
def fixture_mock_default_dirs():
40-
"""Mock the default directories to use temporary directories."""
41-
source_dir = tempfile.mkdtemp(prefix="test_default_source_")
42-
target_dir = tempfile.mkdtemp(prefix="test_default_target_")
43-
44-
with patch.object(relink, "DEFAULT_SOURCE_ROOT", source_dir):
45-
with patch.object(relink, "DEFAULT_TARGET_ROOT", target_dir):
46-
yield source_dir, target_dir
47-
48-
# Cleanup
49-
shutil.rmtree(source_dir, ignore_errors=True)
50-
shutil.rmtree(target_dir, ignore_errors=True)
51-
52-
5323
@pytest.fixture(scope="function", name="temp_dirs")
5424
def fixture_temp_dirs():
5525
"""Create temporary source and target directories for testing."""

0 commit comments

Comments
 (0)