From add68252ec6afe5859c8af179811c380858dffec Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Sun, 10 Jun 2018 15:21:15 +0300 Subject: [PATCH 1/5] Two tests didn't properly assert an exception was raised. Fixed. --- pandas/tests/indexes/datetimes/test_indexing.py | 5 ++--- pandas/tests/io/parser/c_parser_only.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_indexing.py b/pandas/tests/indexes/datetimes/test_indexing.py index dd192db4b0eb3..8cffa035721b0 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -583,7 +583,6 @@ def test_get_indexer(self): def test_reasonable_keyerror(self): # GH#1062 index = DatetimeIndex(['1/3/2000']) - try: + with pytest.raises(KeyError) as excinfo: index.get_loc('1/1/2000') - except KeyError as e: - assert '2000' in str(e) + assert '2000' in str(excinfo.value) diff --git a/pandas/tests/io/parser/c_parser_only.py b/pandas/tests/io/parser/c_parser_only.py index e0422249289b7..d88c224cbe33e 100644 --- a/pandas/tests/io/parser/c_parser_only.py +++ b/pandas/tests/io/parser/c_parser_only.py @@ -34,10 +34,9 @@ def test_buffer_overflow(self): cperr = 'Buffer overflow caught - possible malformed input file.' for malf in (malfw, malfs, malfl): - try: + with pytest.raises(pd.errors.ParserError) as excinfo: self.read_table(StringIO(malf)) - except Exception as err: - assert cperr in str(err) + assert cperr in str(excinfo.value) def test_buffer_rd_bytes(self): # see gh-12098: src->buffer in the C parser can be freed twice leading From ded6a05f222b4f5d5d95e771053ade06e2e35477 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Sun, 10 Jun 2018 15:27:30 +0300 Subject: [PATCH 2/5] whatsnew entry for fixed exception assertions --- doc/source/whatsnew/v0.24.0.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index de985d4db5fa3..fecf1b0fb156f 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -191,6 +191,5 @@ Other ^^^^^ - :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`) -- -- +- fixed two test cases which asserted an exception message but failed to make sure that an exception was actually raised - From 3d7e536f9e48527957b309dc01d24055a86c2b7e Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Sun, 10 Jun 2018 17:47:18 +0300 Subject: [PATCH 3/5] Revert "whatsnew entry for fixed exception assertions" This reverts commit ded6a05f222b4f5d5d95e771053ade06e2e35477. Whatsnew entries are not required for test changes. --- doc/source/whatsnew/v0.24.0.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index fecf1b0fb156f..de985d4db5fa3 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -191,5 +191,6 @@ Other ^^^^^ - :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`) -- fixed two test cases which asserted an exception message but failed to make sure that an exception was actually raised +- +- - From f47437ed2f24cc1394ea8707b5aa752ad5416fd9 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Sun, 10 Jun 2018 17:53:06 +0300 Subject: [PATCH 4/5] Parametrized the C parser buffer overflow test (#21409) --- pandas/tests/io/parser/c_parser_only.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pandas/tests/io/parser/c_parser_only.py b/pandas/tests/io/parser/c_parser_only.py index d88c224cbe33e..0b386c319417a 100644 --- a/pandas/tests/io/parser/c_parser_only.py +++ b/pandas/tests/io/parser/c_parser_only.py @@ -23,20 +23,18 @@ class CParserTests(object): - def test_buffer_overflow(self): + @pytest.mark.parametrize( + '_description, malf', + [('buffer overflow in words pointer', '1\r1\r1\r 1\r 1\r'), + ('buffer overflow in stream pointer', '1\r1\r1\r 1\r 1\r11\r'), + ('buffer overflow in lines pointer', '1\r1\r1\r 1\r 1\r11\r1\r')]) + def test_buffer_overflow(self, _description, malf): # see gh-9205: test certain malformed input files that cause # buffer overflows in tokenizer.c - - malfw = "1\r1\r1\r 1\r 1\r" # buffer overflow in words pointer - malfs = "1\r1\r1\r 1\r 1\r11\r" # buffer overflow in stream pointer - malfl = "1\r1\r1\r 1\r 1\r11\r1\r" # buffer overflow in lines pointer - cperr = 'Buffer overflow caught - possible malformed input file.' - - for malf in (malfw, malfs, malfl): - with pytest.raises(pd.errors.ParserError) as excinfo: - self.read_table(StringIO(malf)) - assert cperr in str(excinfo.value) + with pytest.raises(pd.errors.ParserError) as excinfo: + self.read_table(StringIO(malf)) + assert cperr in str(excinfo.value) def test_buffer_rd_bytes(self): # see gh-12098: src->buffer in the C parser can be freed twice leading From ef25e390e990d78a9a83b68f99c75dbc083b6891 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Tue, 12 Jun 2018 07:35:32 -0400 Subject: [PATCH 5/5] use ids --- pandas/tests/io/parser/c_parser_only.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/io/parser/c_parser_only.py b/pandas/tests/io/parser/c_parser_only.py index 0b386c319417a..9dc7b070f889d 100644 --- a/pandas/tests/io/parser/c_parser_only.py +++ b/pandas/tests/io/parser/c_parser_only.py @@ -24,11 +24,12 @@ class CParserTests(object): @pytest.mark.parametrize( - '_description, malf', - [('buffer overflow in words pointer', '1\r1\r1\r 1\r 1\r'), - ('buffer overflow in stream pointer', '1\r1\r1\r 1\r 1\r11\r'), - ('buffer overflow in lines pointer', '1\r1\r1\r 1\r 1\r11\r1\r')]) - def test_buffer_overflow(self, _description, malf): + 'malf', + ['1\r1\r1\r 1\r 1\r', + '1\r1\r1\r 1\r 1\r11\r', + '1\r1\r1\r 1\r 1\r11\r1\r'], + ids=['words pointer', 'stream pointer', 'lines pointer']) + def test_buffer_overflow(self, malf): # see gh-9205: test certain malformed input files that cause # buffer overflows in tokenizer.c cperr = 'Buffer overflow caught - possible malformed input file.'