17
17
failure_cases ,
18
18
failure_cases_2 ,
19
19
local_file_cases )
20
- from ..frontend import testmod , find_doctests , run_docstring_examples
20
+ from ..frontend import testmod as _testmod , find_doctests , run_docstring_examples
21
21
from ..util import warnings_errors
22
22
from ..impl import DTConfig
23
23
24
24
_VERBOSE = 2
25
25
26
26
27
27
def test_module ():
28
- res , _ = testmod (module , verbose = _VERBOSE )
29
- if res .failed != 0 or res .attempted == 0 :
30
- raise RuntimeError ("Test_module(DTFinder) failed)" )
31
- return res
28
+ res , _ = _testmod (module , verbose = _VERBOSE )
29
+ assert res .failed == 0
30
+ assert res .attempted != 0
32
31
33
32
34
33
def test_module_vanilla_dtfinder ():
35
34
config = DTConfig ()
36
35
config .stopwords = []
37
- res , _ = testmod (module , verbose = _VERBOSE , config = config )
38
- if res .failed != 0 or res .attempted == 0 :
39
- raise RuntimeError ("Test_module(vanilla DocTestFinder) failed)" )
40
- return res
36
+ res , _ = _testmod (module , verbose = _VERBOSE , config = config )
37
+ assert res .failed == 0
38
+ assert res .attempted != 0
41
39
42
40
43
41
def test_stopwords ():
44
- res , _ = testmod (stopwords , verbose = _VERBOSE )
45
- if res .failed != 0 or res .attempted == 0 :
46
- raise RuntimeError ("Test_stopwords failed." )
47
- return res
42
+ res , _ = _testmod (stopwords , verbose = _VERBOSE )
43
+ assert res .failed == 0
44
+ assert res .attempted != 0
48
45
49
46
50
47
def test_public_obj_discovery ():
51
- res , _ = testmod (module , verbose = _VERBOSE , strategy = 'api' )
52
- if res .failed != 0 or res .attempted == 0 :
53
- raise RuntimeError ("Test_public_obj failed." )
54
- return res
48
+ res , _ = _testmod (module , verbose = _VERBOSE , strategy = 'api' )
49
+ assert res .failed == 0
50
+ assert res .attempted != 0
55
51
56
52
57
53
def test_run_docstring_examples ():
58
54
f = finder_cases .Klass
59
55
res1 = run_docstring_examples (f )
60
- res2 = testmod (finder_cases , strategy = [finder_cases .Klass ])
56
+ res2 = _testmod (finder_cases , strategy = [finder_cases .Klass ])
61
57
assert res1 == res2
62
58
63
59
64
60
def test_global_state ():
65
61
# Make sure doctesting does not alter the global state, as much as reasonable
66
62
objs = [module .manip_printoptions ]
67
63
opts = np .get_printoptions ()
68
- testmod (module )
64
+ _testmod (module )
69
65
new_opts = np .get_printoptions ()
70
66
assert new_opts == opts
71
67
72
68
73
69
def test_module_debugrunner ():
74
70
with pytest .raises ((doctest .UnexpectedException , doctest .DocTestFailure )):
75
- res = testmod (failure_cases , raise_on_error = True )
71
+ res = _testmod (failure_cases , raise_on_error = True )
76
72
77
73
78
74
def test_verbosity_1 ():
79
75
# smoke test that verbose=1 works
80
76
stream = io .StringIO ()
81
77
with redirect_stderr (stream ):
82
- testmod (failure_cases , verbose = 1 , report = False )
78
+ _testmod (failure_cases , verbose = 1 , report = False )
83
79
84
80
85
81
def test_user_context ():
86
82
# use a user context to turn warnings to errors : test that it raises
87
83
config = DTConfig ()
88
84
config .user_context_mgr = warnings_errors
89
85
with pytest .raises (doctest .UnexpectedException ):
90
- testmod (failure_cases_2 ,
86
+ _testmod (failure_cases_2 ,
91
87
raise_on_error = True , strategy = [failure_cases_2 .func_depr ],
92
88
config = config )
93
89
@@ -99,23 +95,25 @@ def test_local_files(self):
99
95
config = DTConfig ()
100
96
config .local_resources = {'scpdt.tests.local_file_cases.local_files' :
101
97
['local_file.txt' ]}
102
- res , _ = testmod (local_file_cases , config = config ,
98
+ res , _ = _testmod (local_file_cases , config = config ,
103
99
strategy = [local_file_cases .local_files ],
104
100
verbose = _VERBOSE )
105
- if res .failed != 0 or res .attempted == 0 :
106
- raise RuntimeError ("Test_module::test_local_files" )
101
+
102
+ assert res .failed == 0
103
+ assert res .attempted != 0
107
104
108
105
@pytest .mark .skipif (not HAVE_SCIPY , reason = 'need scipy' )
109
106
def test_sio_octave (self ):
110
107
# scipy/tutorial/io.rst : octave_a.mat file
111
108
config = DTConfig ()
112
109
config .local_resources = {'scpdt.tests.local_file_cases.sio' :
113
110
['octave_a.mat' ]}
114
- res , _ = testmod (local_file_cases , config = config ,
115
- strategy = [local_file_cases .sio ],
116
- verbose = _VERBOSE )
117
- if res .failed != 0 or res .attempted == 0 :
118
- raise RuntimeError ("Test_module::sio" )
111
+ res , _ = _testmod (local_file_cases , config = config ,
112
+ strategy = [local_file_cases .sio ],
113
+ verbose = _VERBOSE )
114
+
115
+ assert res .failed == 0
116
+ assert res .attempted != 0
119
117
120
118
121
119
class TestNameErrorAfterException :
@@ -125,8 +123,8 @@ def test_name_error_after_exception(self):
125
123
# This first came in in https://github.com/scipy/scipy/pull/13116
126
124
stream = io .StringIO ()
127
125
with redirect_stderr (stream ):
128
- testmod (failure_cases_2 ,
129
- strategy = [failure_cases_2 .func_name_error ])
126
+ _testmod (failure_cases_2 ,
127
+ strategy = [failure_cases_2 .func_name_error ])
130
128
131
129
stream .seek (0 )
132
130
output = stream .read ()
@@ -139,8 +137,8 @@ def test_name_error_after_exception_off(self):
139
137
config = DTConfig (nameerror_after_exception = True )
140
138
stream = io .StringIO ()
141
139
with redirect_stderr (stream ):
142
- testmod (failure_cases_2 ,
143
- strategy = [failure_cases_2 .func_name_error ], config = config )
140
+ _testmod (failure_cases_2 ,
141
+ strategy = [failure_cases_2 .func_name_error ], config = config )
144
142
145
143
stream .seek (0 )
146
144
output = stream .read ()
0 commit comments