Skip to content

Commit ee21cf8

Browse files
Add pytest lint
1 parent a7ff4c3 commit ee21cf8

File tree

9 files changed

+50
-57
lines changed

9 files changed

+50
-57
lines changed

gwcs/tests/conftest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,22 @@ def sellmeier_zemax():
9292
return examples.sellmeier_zemax()
9393

9494

95-
@pytest.fixture(scope="function")
95+
@pytest.fixture
9696
def gwcs_3d_galactic_spectral():
9797
return examples.gwcs_3d_galactic_spectral()
9898

9999

100-
@pytest.fixture(scope="function")
100+
@pytest.fixture
101101
def gwcs_1d_spectral():
102102
return examples.gwcs_1d_spectral()
103103

104104

105-
@pytest.fixture(scope="function")
105+
@pytest.fixture
106106
def gwcs_spec_cel_time_4d():
107107
return examples.gwcs_spec_cel_time_4d()
108108

109109

110110
@pytest.fixture(
111-
scope="function",
112111
params=[
113112
(2, 1, 0),
114113
(2, 0, 1),
@@ -123,7 +122,6 @@ def gwcs_cube_with_separable_spectral(request):
123122

124123

125124
@pytest.fixture(
126-
scope="function",
127125
params=[
128126
(2, 0, 1),
129127
(2, 1, 0),
@@ -140,7 +138,7 @@ def gwcs_cube_with_separable_time(request):
140138
return examples.gwcs_cube_with_separable_time(axes_order)
141139

142140

143-
@pytest.fixture(scope="function")
141+
@pytest.fixture
144142
def gwcs_7d_complex_mapping():
145143
return examples.gwcs_7d_complex_mapping()
146144

gwcs/tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_pixel_to_world_values_units_2d(gwcs_2d_shift_scale_quantity, x, y):
163163
[assert_allclose(n, p) for n, p in zip(new_api_pixel, api_pixel, strict=False)]
164164

165165

166-
@pytest.mark.parametrize(("x"), (x, xarr))
166+
@pytest.mark.parametrize(("x"), [x, xarr])
167167
def test_pixel_to_world_values_units_1d(gwcs_1d_freq_quantity, x):
168168
wcsobj = gwcs_1d_freq_quantity
169169

@@ -456,7 +456,7 @@ def test_pixel_to_world_quantity(gwcs_2d_shift_scale, gwcs_2d_shift_scale_quanti
456456
assert_allclose(result1.data.lat, result2.data.lat)
457457

458458
# test for pixel units
459-
with pytest.raises(ValueError):
459+
with pytest.raises(ValueError): # noqa: PT011
460460
gwcs_2d_shift_scale.pixel_to_world(x * u.Jy, y * u.Jy)
461461

462462

@@ -483,7 +483,7 @@ def test_array_index_to_world_quantity(
483483
assert_allclose(result0.data.lat, result1.data.lat)
484484

485485
# test for pixel units
486-
with pytest.raises(ValueError):
486+
with pytest.raises(ValueError): # noqa: PT011
487487
gwcs_2d_shift_scale.array_index_to_world(x * u.Jy, y * u.Jy)
488488

489489

gwcs/tests/test_coordinate_systems.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,17 @@ def test_axes_type():
205205

206206

207207
def test_length_attributes():
208-
with pytest.raises(ValueError):
208+
with pytest.raises(ValueError): # noqa: PT011
209209
cf.CoordinateFrame(
210210
naxes=2, unit=(u.deg), axes_type=("SPATIAL", "SPATIAL"), axes_order=(0, 1)
211211
)
212212

213-
with pytest.raises(ValueError):
213+
with pytest.raises(ValueError): # noqa: PT011
214214
cf.CoordinateFrame(
215215
naxes=2, unit=(u.deg, u.deg), axes_type=("SPATIAL",), axes_order=(0, 1)
216216
)
217217

218-
with pytest.raises(ValueError):
218+
with pytest.raises(ValueError): # noqa: PT011
219219
cf.CoordinateFrame(
220220
naxes=2,
221221
unit=(u.deg, u.deg),
@@ -285,10 +285,10 @@ def test_coordinate_to_quantity_celestial(inp):
285285
assert_quantity_allclose(lon, 10 * u.deg)
286286
assert_quantity_allclose(lat, 20 * u.deg)
287287

288-
with pytest.raises(ValueError):
288+
with pytest.raises(ValueError): # noqa: PT011
289289
coordinate_to_quantity(10 * u.deg, 2 * u.deg, 3 * u.deg, frame=cel)
290290

291-
with pytest.raises(ValueError):
291+
with pytest.raises(ValueError): # noqa: PT011
292292
coordinate_to_quantity((1, 2), frame=cel)
293293

294294

@@ -407,14 +407,14 @@ def test_coordinate_to_quantity_frame_2d():
407407

408408
def test_coordinate_to_quantity_error():
409409
frame = cf.Frame2D(unit=(u.one, u.arcsec))
410-
with pytest.raises(ValueError):
410+
with pytest.raises(ValueError): # noqa: PT011
411411
coordinate_to_quantity(1, frame=frame)
412412

413-
with pytest.raises(ValueError):
413+
with pytest.raises(ValueError): # noqa: PT011
414414
coordinate_to_quantity((1, 1), 2, frame=frame)
415415

416416
frame = cf.TemporalFrame(reference_frame=Time([], format="isot"), unit=u.s)
417-
with pytest.raises(ValueError):
417+
with pytest.raises(ValueError): # noqa: PT011
418418
coordinate_to_quantity(1, frame=frame)
419419

420420

@@ -450,7 +450,7 @@ def test_axis_physical_types():
450450
fr2d = cf.Frame2D(name="d", axis_physical_types=("pos.x", "pos.y"))
451451
assert fr2d.axis_physical_types == ("custom:pos.x", "custom:pos.y")
452452

453-
with pytest.raises(ValueError):
453+
with pytest.raises(ValueError): # noqa: PT011
454454
cf.CelestialFrame(
455455
reference_frame=coord.ICRS(), axis_physical_types=("pos.eq.ra",)
456456
)
@@ -481,7 +481,7 @@ def test_axis_physical_types():
481481
naxes=1,
482482
)
483483
assert frame.axis_physical_types == ("custom:length",)
484-
with pytest.raises(ValueError):
484+
with pytest.raises(ValueError): # noqa: PT011
485485
cf.CoordinateFrame(
486486
name="custom_frame",
487487
axes_type=("SPATIAL",),
@@ -492,7 +492,7 @@ def test_axis_physical_types():
492492

493493

494494
def test_base_frame():
495-
with pytest.raises(ValueError):
495+
with pytest.raises(ValueError): # noqa: PT011
496496
cf.CoordinateFrame(
497497
name="custom_frame",
498498
axes_type=("SPATIAL",),
@@ -542,9 +542,10 @@ def test_ucd1_to_ctype(caplog):
542542
ctype_to_ucd=ctype_to_ucd, allowed_ucd_duplicates=cf._ALLOWED_UCD_DUPLICATES
543543
)
544544

545-
assert caplog.record_tuples[-1][1] == logging.WARNING and caplog.record_tuples[-1][
546-
2
547-
].startswith("Found unsupported duplicate physical type")
545+
assert caplog.record_tuples[-1][1] == logging.WARNING
546+
assert caplog.record_tuples[-1][2].startswith(
547+
"Found unsupported duplicate physical type"
548+
)
548549

549550
for k, v in cf._ALLOWED_UCD_DUPLICATES.items():
550551
assert inv_map.get(k, "") == v

gwcs/tests/test_geometry.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_spherical_cartesian_inverse():
2828

2929

3030
@pytest.mark.parametrize(
31-
"testval, unit, wrap_at",
31+
("testval", "unit", "wrap_at"),
3232
product(
3333
[
3434
(45.0, -90.0, (0.0, 0.0, -1.0)),
@@ -71,7 +71,7 @@ def test_spherical_to_cartesian(testval, unit, wrap_at):
7171

7272

7373
@pytest.mark.parametrize(
74-
"lon, lat, unit, wrap_at",
74+
("lon", "lat", "unit", "wrap_at"),
7575
list(
7676
product(
7777
[0, 45, 90, 135, 180, 225, 270, 315, 360],
@@ -104,7 +104,7 @@ def test_cart2spher_at_pole(cart_to_spher):
104104

105105

106106
@pytest.mark.parametrize(
107-
"lonlat, unit, wrap_at",
107+
("lonlat", "unit", "wrap_at"),
108108
list(
109109
product(
110110
[
@@ -146,7 +146,7 @@ def test_spher2cart_roundrip_arr(lonlat, unit, wrap_at):
146146
assert u.allclose(c2s(*s2c(lon, lat)), (olon, olat), atol=atol)
147147

148148

149-
@pytest.mark.parametrize("unit1, unit2", [(u.deg, 1), (1, u.deg)])
149+
@pytest.mark.parametrize(("unit1", "unit2"), [(u.deg, 1), (1, u.deg)])
150150
def test_spherical_to_cartesian_mixed_Q(spher_to_cart, unit1, unit2):
151151
with pytest.raises(TypeError) as arg_err:
152152
spher_to_cart(135.0 * unit1, 45.0 * unit2)
@@ -157,7 +157,7 @@ def test_spherical_to_cartesian_mixed_Q(spher_to_cart, unit1, unit2):
157157

158158

159159
@pytest.mark.parametrize(
160-
"x, y, z",
160+
("x", "y", "z"),
161161
sorted(
162162
list(
163163
set(
@@ -180,21 +180,17 @@ def test_cartesian_to_spherical_mixed_Q(cart_to_spher, x, y, z):
180180
@pytest.mark.parametrize("wrap_at", ["1", 180.0, True, 180j, [180], -180, 0])
181181
def test_c2s2c_wrong_wrap_type(spher_to_cart, cart_to_spher, wrap_at):
182182
err_msg = "'wrap_lon_at' must be an integer number: 180 or 360"
183-
with pytest.raises(ValueError) as arg_err:
183+
with pytest.raises(ValueError, match=err_msg):
184184
geometry.SphericalToCartesian(wrap_lon_at=wrap_at)
185-
assert arg_err.value.args[0] == err_msg
186185

187-
with pytest.raises(ValueError) as arg_err:
186+
with pytest.raises(ValueError, match=err_msg):
188187
spher_to_cart.wrap_lon_at = wrap_at
189-
assert arg_err.value.args[0] == err_msg
190188

191-
with pytest.raises(ValueError) as arg_err:
189+
with pytest.raises(ValueError, match=err_msg):
192190
geometry.CartesianToSpherical(wrap_lon_at=wrap_at)
193-
assert arg_err.value.args[0] == err_msg
194191

195-
with pytest.raises(ValueError) as arg_err:
192+
with pytest.raises(ValueError, match=err_msg):
196193
cart_to_spher.wrap_lon_at = wrap_at
197-
assert arg_err.value.args[0] == err_msg
198194

199195

200196
def test_cartesian_spherical_asdf(tmpdir):

gwcs/tests/test_region.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_RegionsSelector():
200200
mapper = selector.LabelMapperArray(labels)
201201
sel = {1: models.Shift(1) & models.Scale(1), 2: models.Shift(2) & models.Scale(2)}
202202

203-
with pytest.raises(ValueError):
203+
with pytest.raises(ValueError): # noqa: PT011
204204
# 0 can't be a key in ``selector``
205205
selector.RegionsSelector(
206206
inputs=("x", "y"),
@@ -259,7 +259,7 @@ def test_overalpping_ranges():
259259
for key in keys:
260260
rmapper[tuple(key)] = models.Const1D(4)
261261

262-
with pytest.raises(ValueError):
262+
with pytest.raises(ValueError): # noqa: PT011
263263
selector.LabelMapperRange(("x", "y"), rmapper, inputs_mapping=((0,)))
264264

265265

gwcs/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020

2121
def test_wrong_projcode():
22+
ctype = {"CTYPE": ["RA---TAM", "DEC--TAM"]}
2223
with pytest.raises(UnsupportedProjectionError):
23-
ctype = {"CTYPE": ["RA---TAM", "DEC--TAM"]}
2424
gwutils.get_projcode(ctype)
2525

2626

gwcs/tests/test_wcs.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_bounding_box():
280280
pipeline = [("detector", trans3), ("sky", None)]
281281
w = wcs.WCS(pipeline)
282282
bb = ((-1, 10), (6, 15))
283-
with pytest.raises(ValueError):
283+
with pytest.raises(ValueError): # noqa: PT011
284284
w.bounding_box = bb
285285
trans2 = models.Shift(10) & models.Scale(2)
286286
pipeline = [("detector", trans2), ("sky", None)]
@@ -292,7 +292,7 @@ def test_bounding_box():
292292
w = wcs.WCS(pipeline)
293293
w.bounding_box = (1, 5)
294294
assert w.bounding_box == w.forward_transform.bounding_box
295-
with pytest.raises(ValueError):
295+
with pytest.raises(ValueError): # noqa: PT011
296296
w.bounding_box = ((1, 5), (2, 6))
297297

298298

@@ -333,7 +333,7 @@ def test_compound_bounding_box():
333333
w(13, 13, 4)
334334

335335
# Test attaching a invalid bounding box (not ignoring input 'x')
336-
with pytest.raises(ValueError):
336+
with pytest.raises(ValueError): # noqa: PT011
337337
w.attach_compound_bounding_box(cbb, [("x", False)])
338338

339339
# Test that bounding_box with quantities can be assigned and evaluates
@@ -375,7 +375,7 @@ def test_grid_from_bounding_box_step():
375375
assert_allclose(x, x1)
376376
assert_allclose(y, y1)
377377

378-
with pytest.raises(ValueError):
378+
with pytest.raises(ValueError): # noqa: PT011
379379
grid_from_bounding_box(bb, step=(1, 2, 1))
380380

381381

@@ -778,9 +778,9 @@ def test_to_fits_sip():
778778
assert_allclose(gwcsvalx, fitsvalx, atol=4e-11, rtol=0)
779779
assert_allclose(gwcsvaly, fitsvaly, atol=4e-11, rtol=0)
780780

781-
with pytest.raises(ValueError):
782-
miriwcs.bounding_box = None
783-
mirisip = miriwcs.to_fits_sip(bounding_box=None, max_inv_pix_error=0.1)
781+
miriwcs.bounding_box = None
782+
with pytest.raises(ValueError): # noqa: PT011
783+
_ = miriwcs.to_fits_sip(bounding_box=None, max_inv_pix_error=0.1)
784784

785785

786786
@pytest.mark.parametrize(
@@ -918,8 +918,8 @@ def test_to_fits_tab_no_bb(gwcs_3d_galactic_spectral):
918918
w.bounding_box = None
919919

920920
# FITS WCS -TAB:
921-
with pytest.raises(ValueError):
922-
hdr, bt = w.to_fits_tab()
921+
with pytest.raises(ValueError): # noqa: PT011
922+
_, _ = w.to_fits_tab()
923923

924924

925925
def test_to_fits_tab_cube(gwcs_3d_galactic_spectral):
@@ -1346,7 +1346,6 @@ def test_iter_inv():
13461346
quiet=False,
13471347
with_bounding_box=False,
13481348
)
1349-
assert np.allclose((x, y), (xp, yp))
13501349

13511350
xp, yp = e.value.best_solution.T
13521351
assert np.allclose((x[1:], y[1:]), (xp[1:], yp[1:]))

gwcs/wcs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ def _order_clockwise(v):
16851685
if center:
16861686
vertices = utils._toindex(vertices)
16871687

1688-
result = np.asarray(self.__call__(*vertices, **{"with_bounding_box": False}))
1688+
result = np.asarray(self.__call__(*vertices, with_bounding_box=False))
16891689

16901690
axis_type = axis_type.lower()
16911691
if axis_type == "spatial" and all_spatial:
@@ -3389,8 +3389,8 @@ def _reform_poly_coefficients(fit_poly_x, fit_poly_y):
33893389
invcdmat = npla.inv(np.array(cdmat))
33903390
degree = fit_poly_x.degree
33913391
# Now loop through all remaining coefficients
3392-
for i in range(0, degree + 1):
3393-
for j in range(0, degree + 1):
3392+
for i in range(degree + 1):
3393+
for j in range(degree + 1):
33943394
if (i + j > 1) and (i + j < degree + 1):
33953395
old_x = getattr(fit_poly_x, f"c{i}_{j}").value
33963396
old_y = getattr(fit_poly_y, f"c{i}_{j}").value
@@ -3407,8 +3407,8 @@ def _store_2D_coefficients(hdr, poly_model, coeff_prefix, keeplinear=False):
34073407
"""
34083408
mindeg = int(not keeplinear)
34093409
degree = poly_model.degree
3410-
for i in range(0, degree + 1):
3411-
for j in range(0, degree + 1):
3410+
for i in range(degree + 1):
3411+
for j in range(degree + 1):
34123412
if (i + j) > mindeg and (i + j < degree + 1):
34133413
hdr[f"{coeff_prefix}_{i}_{j}"] = getattr(poly_model, f"c{i}_{j}").value
34143414

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ select = [
131131
# "FA", # flake8-future-annotations (correct usage future annotations)
132132
# "ISC", # flake8-implicit-str-concat (prevent implicit string concat)
133133
# "ICN", # flake8-import-conventions (enforce import conventions)
134-
#"G", # flake8-logging-format (best practices for logging)
135134
# "INP", # flake8-no-pep420 (prevent use of PEP420, i.e. implicit name spaces)
136-
#"PIE", # flake8-pie (misc suggested improvement linting)
135+
"PIE", # flake8-pie (misc suggested improvement linting)
137136
# "T20", # flake8-print (prevent print statements in code)
138-
#"PT", # flake8-pytest-style (best practices for pytest)
137+
"PT", # flake8-pytest-style (best practices for pytest)
139138
#"Q", # flake8-quotes (best practices for quotes)
140139
# "RSE", # flake8-raise (best practices for raising exceptions)
141140
#"RET", # flake8-return (best practices for return statements)

0 commit comments

Comments
 (0)