-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: Check more error messages in tests
- Loading branch information
Showing
8 changed files
with
167 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
from pandas.core.frame import DataFrame | ||
|
||
import pytest | ||
import pandas.util.testing as tm | ||
|
||
|
||
class TestDataFrameValidate(object): | ||
"""Tests for error handling related to data types of method arguments.""" | ||
df = DataFrame({'a': [1, 2], 'b': [3, 4]}) | ||
|
||
def test_validate_bool_args(self): | ||
# Tests for error handling related to boolean arguments. | ||
invalid_values = [1, "True", [1, 2, 3], 5.0] | ||
|
||
for value in invalid_values: | ||
with pytest.raises(ValueError): | ||
self.df.query('a > b', inplace=value) | ||
|
||
with pytest.raises(ValueError): | ||
self.df.eval('a + b', inplace=value) | ||
@pytest.fixture | ||
def dataframe(): | ||
return DataFrame({'a': [1, 2], 'b': [3, 4]}) | ||
|
||
with pytest.raises(ValueError): | ||
self.df.set_index(keys=['a'], inplace=value) | ||
|
||
with pytest.raises(ValueError): | ||
self.df.reset_index(inplace=value) | ||
|
||
with pytest.raises(ValueError): | ||
self.df.dropna(inplace=value) | ||
|
||
with pytest.raises(ValueError): | ||
self.df.drop_duplicates(inplace=value) | ||
class TestDataFrameValidate(object): | ||
"""Tests for error handling related to data types of method arguments.""" | ||
|
||
with pytest.raises(ValueError): | ||
self.df.sort_values(by=['a'], inplace=value) | ||
@pytest.mark.parametrize("func", ["query", "eval", "set_index", | ||
"reset_index", "dropna", | ||
"drop_duplicates", "sort_values"]) | ||
@pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0]) | ||
def test_validate_bool_args(self, dataframe, func, inplace): | ||
msg = "For argument \"inplace\" expected type bool" | ||
kwargs = dict(inplace=inplace) | ||
|
||
if func == "query": | ||
kwargs["expr"] = "a > b" | ||
elif func == "eval": | ||
kwargs["expr"] = "a + b" | ||
elif func == "set_index": | ||
kwargs["keys"] = ["a"] | ||
elif func == "sort_values": | ||
kwargs["by"] = ["a"] | ||
|
||
with tm.assert_raises_regex(ValueError, msg): | ||
getattr(dataframe, func)(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import pytest | ||
|
||
from pandas.compat import StringIO | ||
from pandas import read_sas | ||
|
||
import pandas.util.testing as tm | ||
|
||
|
||
class TestSas(object): | ||
|
||
def test_sas_buffer_format(self): | ||
|
||
# GH14947 | ||
# see gh-14947 | ||
b = StringIO("") | ||
with pytest.raises(ValueError): | ||
|
||
msg = ("If this is a buffer object rather than a string " | ||
"name, you must specify a format string") | ||
with tm.assert_raises_regex(ValueError, msg): | ||
read_sas(b) |
Oops, something went wrong.