From 82a36c2538db9af3d8f6d3cb33a815d7a351d876 Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 20:59:28 +0100 Subject: [PATCH 1/2] TST: GH30999 add match=msg to 2 pytest.raises in pandas/tests/io/json/test_normalize.py --- pandas/tests/io/json/test_normalize.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index 46f6367a7227f..3a79707a76c00 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -174,8 +174,16 @@ def test_empty_array(self): [ ([{"a": 0}, {"a": 1}], None, does_not_raise()), ({"a": [{"a": 0}, {"a": 1}]}, "a", does_not_raise()), - ('{"a": [{"a": 0}, {"a": 1}]}', None, pytest.raises(NotImplementedError)), - (None, None, pytest.raises(NotImplementedError)), + ( + '{"a": [{"a": 0}, {"a": 1}]}', + None, + pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN), + ), + ( + None, + None, + pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN), + ), ], ) def test_accepted_input(self, data, record_path, error): From 9ddbb25809e2f2bb6b52be50cf5d27c4d0891bc5 Mon Sep 17 00:00:00 2001 From: moink Date: Fri, 1 Jan 2021 10:05:01 +0100 Subject: [PATCH 2/2] TST: GH30999 change pytest parametrization of test_accepted_input to remove linting error --- pandas/tests/io/json/test_normalize.py | 27 ++++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index 3a79707a76c00..b232c827f5ece 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -1,4 +1,3 @@ -from contextlib import nullcontext as does_not_raise import json import numpy as np @@ -170,27 +169,21 @@ def test_empty_array(self): tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( - "data, record_path, error", + "data, record_path, exception_type", [ - ([{"a": 0}, {"a": 1}], None, does_not_raise()), - ({"a": [{"a": 0}, {"a": 1}]}, "a", does_not_raise()), - ( - '{"a": [{"a": 0}, {"a": 1}]}', - None, - pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN), - ), - ( - None, - None, - pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN), - ), + ([{"a": 0}, {"a": 1}], None, None), + ({"a": [{"a": 0}, {"a": 1}]}, "a", None), + ('{"a": [{"a": 0}, {"a": 1}]}', None, NotImplementedError), + (None, None, NotImplementedError), ], ) - def test_accepted_input(self, data, record_path, error): - with error: + def test_accepted_input(self, data, record_path, exception_type): + if exception_type is not None: + with pytest.raises(exception_type, match=tm.EMPTY_STRING_PATTERN): + json_normalize(data, record_path=record_path) + else: result = json_normalize(data, record_path=record_path) expected = DataFrame([0, 1], columns=["a"]) - tm.assert_frame_equal(result, expected) def test_simple_normalize_with_separator(self, deep_nested):