Skip to content

Commit 92e9882

Browse files
akaiholajreback
authored andcommitted
Two tests didn't properly assert an exception was raised. Fixed. (#21409)
1 parent ffffa5c commit 92e9882

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

pandas/tests/indexes/datetimes/test_indexing.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ def test_get_indexer(self):
583583
def test_reasonable_keyerror(self):
584584
# GH#1062
585585
index = DatetimeIndex(['1/3/2000'])
586-
try:
586+
with pytest.raises(KeyError) as excinfo:
587587
index.get_loc('1/1/2000')
588-
except KeyError as e:
589-
assert '2000' in str(e)
588+
assert '2000' in str(excinfo.value)

pandas/tests/io/parser/c_parser_only.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@
2323

2424
class CParserTests(object):
2525

26-
def test_buffer_overflow(self):
26+
@pytest.mark.parametrize(
27+
'malf',
28+
['1\r1\r1\r 1\r 1\r',
29+
'1\r1\r1\r 1\r 1\r11\r',
30+
'1\r1\r1\r 1\r 1\r11\r1\r'],
31+
ids=['words pointer', 'stream pointer', 'lines pointer'])
32+
def test_buffer_overflow(self, malf):
2733
# see gh-9205: test certain malformed input files that cause
2834
# buffer overflows in tokenizer.c
29-
30-
malfw = "1\r1\r1\r 1\r 1\r" # buffer overflow in words pointer
31-
malfs = "1\r1\r1\r 1\r 1\r11\r" # buffer overflow in stream pointer
32-
malfl = "1\r1\r1\r 1\r 1\r11\r1\r" # buffer overflow in lines pointer
33-
3435
cperr = 'Buffer overflow caught - possible malformed input file.'
35-
36-
for malf in (malfw, malfs, malfl):
37-
try:
38-
self.read_table(StringIO(malf))
39-
except Exception as err:
40-
assert cperr in str(err)
36+
with pytest.raises(pd.errors.ParserError) as excinfo:
37+
self.read_table(StringIO(malf))
38+
assert cperr in str(excinfo.value)
4139

4240
def test_buffer_rd_bytes(self):
4341
# see gh-12098: src->buffer in the C parser can be freed twice leading

0 commit comments

Comments
 (0)