|
1 |
| -from contextlib import nullcontext as does_not_raise |
2 | 1 | import json
|
3 | 2 |
|
4 | 3 | import numpy as np
|
@@ -170,19 +169,21 @@ def test_empty_array(self):
|
170 | 169 | tm.assert_frame_equal(result, expected)
|
171 | 170 |
|
172 | 171 | @pytest.mark.parametrize(
|
173 |
| - "data, record_path, error", |
| 172 | + "data, record_path, exception_type", |
174 | 173 | [
|
175 |
| - ([{"a": 0}, {"a": 1}], None, does_not_raise()), |
176 |
| - ({"a": [{"a": 0}, {"a": 1}]}, "a", does_not_raise()), |
177 |
| - ('{"a": [{"a": 0}, {"a": 1}]}', None, pytest.raises(NotImplementedError)), |
178 |
| - (None, None, pytest.raises(NotImplementedError)), |
| 174 | + ([{"a": 0}, {"a": 1}], None, None), |
| 175 | + ({"a": [{"a": 0}, {"a": 1}]}, "a", None), |
| 176 | + ('{"a": [{"a": 0}, {"a": 1}]}', None, NotImplementedError), |
| 177 | + (None, None, NotImplementedError), |
179 | 178 | ],
|
180 | 179 | )
|
181 |
| - def test_accepted_input(self, data, record_path, error): |
182 |
| - with error: |
| 180 | + def test_accepted_input(self, data, record_path, exception_type): |
| 181 | + if exception_type is not None: |
| 182 | + with pytest.raises(exception_type, match=tm.EMPTY_STRING_PATTERN): |
| 183 | + json_normalize(data, record_path=record_path) |
| 184 | + else: |
183 | 185 | result = json_normalize(data, record_path=record_path)
|
184 | 186 | expected = DataFrame([0, 1], columns=["a"])
|
185 |
| - |
186 | 187 | tm.assert_frame_equal(result, expected)
|
187 | 188 |
|
188 | 189 | def test_simple_normalize_with_separator(self, deep_nested):
|
|
0 commit comments