Skip to content

Commit 2ededa7

Browse files
j-bowhayMarcoGorellirgommers
authored
DEV: add check for misnamed tests (scipy#17655)
Closes scipygh-17652 Regarding the command line output of `dev.py lint`, note that the commands are emitted all at once, which is a minor limitation of using `run_doit_task` rather than having it in a Task class with methods, like the setup/build/install commands. Still better than not emitting the commands that are being run at all. [skip azure] [skip cirrus] [skip circle] Co-authored-by: Marco Gorelli <marcogorelli@protonmail.com> Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>
1 parent b5b7a3f commit 2ededa7

File tree

10 files changed

+219
-27
lines changed

10 files changed

+219
-27
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ stages:
158158
# in Checkout stage)
159159
python tools/lint_diff.py --branch origin/$(System.PullRequest.TargetBranch)
160160
tools/unicode-check.py
161+
tools/check_test_name.py
161162
displayName: 'Run Lint Checks'
162163
failOnStderr: true
163164
- job: Linux_Python_38_32bit_full

dev.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,22 +861,34 @@ def run(cls, **kwargs):
861861
###################
862862
# linters
863863

864+
def emit_cmdstr(cmd):
865+
"""Print the command that's being run to stdout"""
866+
console = Console(theme=console_theme)
867+
# The [cmd] square brackets controls the font styling, typically in italics
868+
# to differentiate it from other stdout content
869+
console.print(f"{EMOJI.cmd} [cmd] {cmd}")
870+
871+
864872
@task_params([{'name': 'output_file', 'long': 'output-file', 'default': None,
865873
'help': 'Redirect report to a file'}])
866874
def task_flake8(output_file):
867875
"""Run flake8 over the code base and benchmarks."""
868876
opts = ''
869877
if output_file:
870878
opts += f'--output-file={output_file}'
879+
880+
cmd = f"flake8 {opts} scipy benchmarks/benchmarks"
881+
emit_cmdstr(f"{cmd}")
871882
return {
872-
'actions': [f"flake8 {opts} scipy benchmarks/benchmarks"],
883+
'actions': [cmd],
873884
'doc': 'Lint scipy and benchmarks directory',
874885
}
875886

876887

877888
def task_pep8diff():
878889
# Lint just the diff since branching off of main using a
879890
# stricter configuration.
891+
emit_cmdstr(os.path.join('tools', 'lint_diff.py'))
880892
return {
881893
'basename': 'pep8-diff',
882894
'actions': [str(Dirs().root / 'tools' / 'lint_diff.py')],
@@ -885,6 +897,7 @@ def task_pep8diff():
885897

886898

887899
def task_unicode_check():
900+
emit_cmdstr(os.path.join('tools', 'unicode-check.py'))
888901
return {
889902
'basename': 'unicode-check',
890903
'actions': [str(Dirs().root / 'tools' / 'unicode-check.py')],
@@ -893,16 +906,30 @@ def task_unicode_check():
893906
}
894907

895908

909+
def task_check_test_name():
910+
emit_cmdstr(os.path.join('tools', 'check_test_name.py'))
911+
return {
912+
"basename": "check-testname",
913+
"actions": [str(Dirs().root / "tools" / "check_test_name.py")],
914+
"doc": "Check tests are correctly named so that pytest runs them."
915+
}
916+
917+
896918
@cli.cls_cmd('lint')
897919
class Lint():
898920
""":dash: Run flake8, check PEP 8 compliance on branch diff and check for
899-
disallowed Unicode characters."""
921+
disallowed Unicode characters and possibly-invalid test names."""
900922
output_file = Option(
901923
['--output-file'], default=None, help='Redirect report to a file')
902924

903925
def run(output_file):
904926
opts = {'output_file': output_file}
905-
run_doit_task({'flake8': opts, 'pep8-diff': {}, 'unicode-check': {}})
927+
run_doit_task({
928+
'flake8': opts,
929+
'pep8-diff': {},
930+
'unicode-check': {},
931+
'check-testname': {},
932+
})
906933

907934

908935
@cli.cls_cmd('mypy')
@@ -938,6 +965,7 @@ def run(cls, **kwargs):
938965
os.environ['MYPY_FORCE_COLOR'] = '1'
939966
# Change to the site directory to make sure mypy doesn't pick
940967
# up any type stubs in the source tree.
968+
emit_cmdstr(f"mypy.api.run --config-file {config} {check_path}")
941969
report, errors, status = mypy.api.run([
942970
"--config-file",
943971
str(config),

scipy/optimize/tests/test__numdiff.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ def jac_zero_jacobian(self, x):
215215
[-x[1] * np.sin(x[0] * x[1]), -x[0] * np.sin(x[0] * x[1])]
216216
])
217217

218-
def fun_non_numpy(self, x):
219-
return math.exp(x)
220-
221218
def jac_non_numpy(self, x):
222219
# x can be a scalar or an array [val].
223220
# Cast to true scalar before handing over to math.exp

scipy/optimize/tests/test__spectral.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def x0_2(n):
149149
x0.fill(1/n**2)
150150
return x0
151151

152-
def F_4(x, n):
152+
153+
def F_4(x, n): # skip name check
153154
assert_equal(n % 3, 0)
154155
g = np.zeros([n])
155156
# Note: the first line is typoed in some of the references;
@@ -159,7 +160,8 @@ def F_4(x, n):
159160
g[2::3] = 1.25 * x[2::3] - 0.25*x[2::3]**3
160161
return g
161162

162-
def x0_4(n):
163+
164+
def x0_4(n): # skip name check
163165
assert_equal(n % 3, 0)
164166
x0 = np.array([-1, 1/2, -1] * (n//3))
165167
return x0

scipy/optimize/tests/test_linesearch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,33 @@ def assert_fp_equal(x, y, err_msg="", nulp=50):
5353

5454
class TestLineSearch:
5555
# -- scalar functions; must have dphi(0.) < 0
56-
def _scalar_func_1(self, s):
56+
def _scalar_func_1(self, s): # skip name check
5757
self.fcount += 1
5858
p = -s - s**3 + s**4
5959
dp = -1 - 3*s**2 + 4*s**3
6060
return p, dp
6161

62-
def _scalar_func_2(self, s):
62+
def _scalar_func_2(self, s): # skip name check
6363
self.fcount += 1
6464
p = np.exp(-4*s) + s**2
6565
dp = -4*np.exp(-4*s) + 2*s
6666
return p, dp
6767

68-
def _scalar_func_3(self, s):
68+
def _scalar_func_3(self, s): # skip name check
6969
self.fcount += 1
7070
p = -np.sin(10*s)
7171
dp = -10*np.cos(10*s)
7272
return p, dp
7373

7474
# -- n-d functions
7575

76-
def _line_func_1(self, x):
76+
def _line_func_1(self, x): # skip name check
7777
self.fcount += 1
7878
f = np.dot(x, x)
7979
df = 2*x
8080
return f, df
8181

82-
def _line_func_2(self, x):
82+
def _line_func_2(self, x): # skip name check
8383
self.fcount += 1
8484
f = np.dot(x, np.dot(self.A, x)) + 1
8585
df = np.dot(self.A + self.A.T, x)

scipy/sparse/tests/test_sparsetools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,41 +220,41 @@ def get_matrix():
220220
finally:
221221
gc.collect()
222222

223-
def _check_bsr_matvecs(self, m):
223+
def _check_bsr_matvecs(self, m): # skip name check
224224
m = m()
225225
n = self.n
226226

227227
# _matvecs
228228
r = m.dot(np.ones((n, 2), dtype=np.int8))
229229
assert_equal(r[0, 0], int_to_int8(n))
230230

231-
def _check_bsr_matvec(self, m):
231+
def _check_bsr_matvec(self, m): # skip name check
232232
m = m()
233233
n = self.n
234234

235235
# _matvec
236236
r = m.dot(np.ones((n,), dtype=np.int8))
237237
assert_equal(r[0], int_to_int8(n))
238238

239-
def _check_bsr_diagonal(self, m):
239+
def _check_bsr_diagonal(self, m): # skip name check
240240
m = m()
241241
n = self.n
242242

243243
# _diagonal
244244
r = m.diagonal()
245245
assert_equal(r, np.ones(n))
246246

247-
def _check_bsr_sort_indices(self, m):
247+
def _check_bsr_sort_indices(self, m): # skip name check
248248
# _sort_indices
249249
m = m()
250250
m.sort_indices()
251251

252-
def _check_bsr_transpose(self, m):
252+
def _check_bsr_transpose(self, m): # skip name check
253253
# _transpose
254254
m = m()
255255
m.transpose()
256256

257-
def _check_bsr_matmat(self, m):
257+
def _check_bsr_matmat(self, m): # skip name check
258258
m = m()
259259
n = self.n
260260

scipy/special/tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def test_pro_ang1_cv(self):
835835
assert_array_almost_equal(cephes.pro_ang1_cv(1,1,1,1,0),
836836
array((1.0,0.0)))
837837

838-
def _check_pro_cv(self):
838+
def test_pro_cv(self):
839839
assert_equal(cephes.pro_cv(1,1,0),2.0)
840840

841841
def test_pro_rad1(self):

scipy/special/tests/test_data.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
jn, jv, jvp, yn, yv, yvp, iv, ivp, kn, kv, kvp,
1111
gamma, gammaln, gammainc, gammaincc, gammaincinv, gammainccinv, digamma,
1212
beta, betainc, betaincinv, poch,
13-
ellipe, ellipeinc, ellipk, ellipkm1, ellipkinc, ellipj,
13+
ellipe, ellipeinc, ellipk, ellipkm1, ellipkinc,
1414
elliprc, elliprd, elliprf, elliprg, elliprj,
1515
erf, erfc, erfinv, erfcinv, exp1, expi, expn,
1616
bdtrik, btdtr, btdtri, btdtria, btdtrib, chndtr, gdtr, gdtrc, gdtrix, gdtrib,
@@ -64,10 +64,6 @@ def ellipeinc_(f, k):
6464
return ellipeinc(f, k*k)
6565

6666

67-
def ellipj_(k):
68-
return ellipj(k*k)
69-
70-
7167
def zeta_(x):
7268
return zeta(x, 1.)
7369

0 commit comments

Comments
 (0)