Skip to content

Commit 95b41d1

Browse files
jd-aubsipocz
authored andcommitted
Update exception tests to use match
1 parent 2c6ffb7 commit 95b41d1

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

astroquery/casda/tests/test_casda.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ def test_login_no_default_user():
136136
assert casda._authenticated is False
137137
assert casda.USERNAME == ''
138138

139-
with pytest.raises(LoginError) as excinfo:
139+
with pytest.raises(LoginError, match=r"If you do not pass a username to login\(\),") as excinfo:
140140
Casda.login()
141141

142-
assert "If you do not pass a username to login()," in str(excinfo.value)
143-
144142
assert casda._authenticated is False
145143
assert casda.USERNAME == ''
146144
assert hasattr(casda, '_auth') is False
@@ -286,11 +284,9 @@ def test_filter_out_unreleased():
286284
def test_stage_data_unauthorised(patch_get):
287285
table = Table()
288286

289-
with pytest.raises(ValueError) as excinfo:
287+
with pytest.raises(ValueError, match=r"Credentials must be supplied") as excinfo:
290288
Casda.stage_data(table)
291289

292-
assert "Credentials must be supplied" in str(excinfo.value)
293-
294290

295291
def test_stage_data_empty(patch_get):
296292
table = Table()
@@ -323,11 +319,9 @@ def test_stage_data_no_link(patch_get):
323319
fake_login(casda, USERNAME, PASSWORD)
324320
casda.POLL_INTERVAL = 1
325321

326-
with pytest.raises(ValueError) as excinfo:
322+
with pytest.raises(ValueError, match=r"You do not have access to any of the requested data files\.") as excinfo:
327323
casda.stage_data(table)
328324

329-
assert "You do not have access to any of the requested data files." in str(excinfo.value)
330-
331325

332326
def test_stage_data(patch_get):
333327
prefix = 'https://somewhere/casda/datalink/links?'
@@ -370,9 +364,9 @@ def test_cutout_no_args(patch_get):
370364
casda = Casda()
371365
fake_login(casda, USERNAME, PASSWORD)
372366
casda.POLL_INTERVAL = 1
373-
with pytest.raises(ValueError) as excinfo:
367+
with pytest.raises(ValueError,
368+
match=r"Please provide cutout parameters such as coordinates, band or channel\.") as excinfo:
374369
casda.cutout(table)
375-
assert "Please provide cutout parameters such as coordinates, band or channel." in str(excinfo.value)
376370

377371

378372
def test_cutout_unauthorised(patch_get):
@@ -384,9 +378,8 @@ def test_cutout_unauthorised(patch_get):
384378
radius = 30*u.arcmin
385379
centre = SkyCoord(ra, dec)
386380

387-
with pytest.raises(ValueError) as excinfo:
381+
with pytest.raises(ValueError, match=r"Credentials must be supplied to download CASDA image data") as excinfo:
388382
Casda.cutout(table, coordinates=centre, radius=radius, verbose=True)
389-
assert "Credentials must be supplied to download CASDA image data" in str(excinfo.value)
390383

391384

392385
def test_cutout_no_table(patch_get):

0 commit comments

Comments
 (0)