Skip to content

Commit 19f3534

Browse files
committed
MAINT: rm dead code, reformat
1 parent 85e829b commit 19f3534

File tree

3 files changed

+8
-105
lines changed

3 files changed

+8
-105
lines changed

scpdt/plugin.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
from scpdt.frontend import find_doctests
1818

1919

20-
# XXX: unused global?
21-
copied_files = []
22-
23-
2420
def pytest_configure(config):
2521
"""
2622
Perform initial configuration for the pytest plugin.
@@ -34,20 +30,6 @@ def pytest_configure(config):
3430
pydoctest.DoctestTextfile = DTTextfile
3531

3632

37-
def pytest_unconfigure(config):
38-
"""
39-
Called before exiting the test process.
40-
"""
41-
42-
# Delete all locally copied files in the current working directory
43-
if copied_files:
44-
try:
45-
for filepath in copied_files:
46-
os.remove(filepath)
47-
except FileNotFoundError:
48-
pass
49-
50-
5133
def pytest_ignore_collect(collection_path, config):
5234
"""
5335
Determine whether to ignore the specified collection path.
@@ -106,32 +88,6 @@ def pytest_collection_modifyitems(config, items):
10688

10789
# Replace the original list of test items with the unique ones
10890
items[:] = unique_items
109-
110-
111-
# XXX: unused?
112-
def copy_local_files(local_resources, destination_dir):
113-
"""
114-
Copy necessary local files for doctests to the current working directory.
115-
116-
This function copies files specified in the `local_resources` attribute of a DTConfig instance
117-
to the specified `destination_dir`.
118-
119-
Args:
120-
local_resources (dict): A dictionary of resources to be copied.
121-
destination_dir (str): The destination directory where files will be copied.
122-
123-
Returns:
124-
list: A list of paths to the copied files.
125-
"""
126-
for value in local_resources.values():
127-
for filepath in value:
128-
basename = os.path.basename(filepath)
129-
dest_path = os.path.join(destination_dir, basename)
130-
131-
if not os.path.exists(dest_path):
132-
shutil.copy(filepath, destination_dir)
133-
copied_files.append(dest_path)
134-
return copied_files
13591

13692

13793
class DTModule(DoctestModule):
@@ -166,10 +122,6 @@ def collect(self):
166122
else:
167123
raise
168124

169-
# Copy local files specified by the `local_resources` attribute to the current working directory
170-
# if self.config.dt_config.local_resources:
171-
# copy_local_files(self.config.dt_config.local_resources, os.getcwd())
172-
173125
optionflags = dt_config.optionflags
174126

175127
# Plug in the custom runner: `PytestDTRunner`
@@ -210,10 +162,6 @@ def collect(self):
210162

211163
optionflags = pydoctest.get_optionflags(self)
212164

213-
# Copy local files specified by the `local_resources` attribute to the current working directory
214-
if self.config.dt_config.local_resources:
215-
copy_local_files(self.config.dt_config.local_resources, os.getcwd())
216-
217165
# Plug in the custom runner: `PytestDTRunner`
218166
runner = _get_runner(self.config,
219167
verbose=False,

scpdt/tests/local_file_cases.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from scpdt.conftest import dt_config
22

3-
43
# Specify local files required by doctests
5-
dt_config.local_resources = {'scpdt.tests.local_file_cases.local_files':
6-
['local_file.txt'],
7-
'scpdt.tests.local_file_cases.sio':
8-
['octave_a.mat']
9-
}
4+
dt_config.local_resources = {
5+
'scpdt.tests.local_file_cases.local_files': ['local_file.txt'],
6+
'scpdt.tests.local_file_cases.sio': ['octave_a.mat']
7+
}
8+
109

1110
__all__ = ['local_files', 'sio']
1211

12+
1313
def local_files():
1414
"""
1515
A doctest that tries to read a local file
Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
11
import pytest
2-
import os
32
from pathlib import PosixPath, Path
43

54
from . import module_cases, failure_cases, failure_cases_2, stopwords_cases, local_file_cases
6-
from scpdt.plugin import copy_local_files
75
from scpdt.conftest import dt_config
86

9-
pytest_plugins = ['pytester']
10-
11-
'''
12-
@pytest.fixture(autouse=True)
13-
def copy_files():
14-
"""
15-
Copy necessary local files for doctests to the temporary directory used by pytester.
16-
The files to be copied are defined by the `local_resources` attribute of a DTConfig instance.
17-
When testing is done, all copied files are deleted.
18-
"""
19-
try:
20-
dirname = os.path.dirname(Path(__file__))
21-
22-
# Update the file path of each filename
23-
for value in dt_config.local_resources.values():
24-
for i, path in enumerate(value):
25-
value[i] = os.path.join(dirname, os.path.basename(path))
7+
# XXX: this is a bit hacky and repetetive. Can rework?
268

27-
# Copy the files
28-
copied_files = copy_local_files(dt_config.local_resources, os.getcwd())
299

30-
yield copied_files
10+
pytest_plugins = ['pytester']
3111

32-
finally:
33-
# Perform clean-up
34-
for filepath in copied_files:
35-
try:
36-
os.remove(filepath)
37-
except FileNotFoundError:
38-
pass
39-
'''
4012

4113
def test_module_cases(pytester):
4214
"""Test that pytest uses the DTChecker for doctests."""
@@ -63,27 +35,10 @@ def test_stopword_cases(pytester):
6335
assert result.ret == pytest.ExitCode.OK
6436

6537

66-
#@pytest.mark.xfail
6738
def test_local_file_cases(pytester):
6839
"""Test that local files are found for use in doctests.
69-
70-
XXX: this one fails because nobody told pytest how to find those local files.
71-
cf test_testmod.py::TestLocalFiles
7240
"""
7341
path_str = local_file_cases.__file__
7442
python_file = PosixPath(path_str)
75-
76-
# pytester.makeconftest(
77-
# """
78-
# import pytest
79-
# from scpdt.conftest import dt_config
80-
#
81-
# dt_config.local_resources = {'scpdt.tests.local_file_cases.local_files':
82-
# ['local_file.txt']}
83-
# """
84-
# )
85-
86-
# breakpoint()
87-
8843
result = pytester.inline_run(python_file, "--doctest-modules")
8944
assert result.ret == pytest.ExitCode.OK

0 commit comments

Comments
 (0)