|
1 |
| -import pytest |
2 | 1 | from pandas.core.series import Series
|
3 | 2 |
|
| 3 | +import pytest |
| 4 | +import pandas.util.testing as tm |
| 5 | + |
4 | 6 |
|
5 | 7 | class TestSeriesValidate(object):
|
6 | 8 | """Tests for error handling related to data types of method arguments."""
|
7 |
| - s = Series([1, 2, 3, 4, 5]) |
8 |
| - |
9 |
| - def test_validate_bool_args(self): |
10 |
| - # Tests for error handling related to boolean arguments. |
11 |
| - invalid_values = [1, "True", [1, 2, 3], 5.0] |
12 |
| - |
13 |
| - for value in invalid_values: |
14 |
| - with pytest.raises(ValueError): |
15 |
| - self.s.reset_index(inplace=value) |
16 |
| - |
17 |
| - with pytest.raises(ValueError): |
18 |
| - self.s._set_name(name='hello', inplace=value) |
19 | 9 |
|
20 |
| - with pytest.raises(ValueError): |
21 |
| - self.s.sort_values(inplace=value) |
| 10 | + @classmethod |
| 11 | + def setup_class(cls): |
| 12 | + cls.s = Series([1, 2, 3, 4, 5]) |
22 | 13 |
|
23 |
| - with pytest.raises(ValueError): |
24 |
| - self.s.sort_index(inplace=value) |
| 14 | + @pytest.mark.parametrize("func", ["reset_index", "_set_name", |
| 15 | + "sort_values", "sort_index", |
| 16 | + "rename", "dropna"]) |
| 17 | + @pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0]) |
| 18 | + def test_validate_bool_args(self, func, inplace): |
| 19 | + msg = "For argument \"inplace\" expected type bool" |
| 20 | + kwargs = dict(inplace=inplace) |
25 | 21 |
|
26 |
| - with pytest.raises(ValueError): |
27 |
| - self.s.rename(inplace=value) |
| 22 | + if func == "_set_name": |
| 23 | + kwargs["name"] = "hello" |
28 | 24 |
|
29 |
| - with pytest.raises(ValueError): |
30 |
| - self.s.dropna(inplace=value) |
| 25 | + with tm.assert_raises_regex(ValueError, msg): |
| 26 | + getattr(self.s, func)(**kwargs) |
0 commit comments