test_validate.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import pytest
  2. from pandas.core.frame import DataFrame
  3. @pytest.fixture
  4. def dataframe():
  5. return DataFrame({"a": [1, 2], "b": [3, 4]})
  6. class TestDataFrameValidate:
  7. """Tests for error handling related to data types of method arguments."""
  8. @pytest.mark.parametrize(
  9. "func",
  10. [
  11. "query",
  12. "eval",
  13. "set_index",
  14. "reset_index",
  15. "dropna",
  16. "drop_duplicates",
  17. "sort_values",
  18. ],
  19. )
  20. @pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0])
  21. def test_validate_bool_args(self, dataframe, func, inplace):
  22. msg = 'For argument "inplace" expected type bool'
  23. kwargs = {"inplace": inplace}
  24. if func == "query":
  25. kwargs["expr"] = "a > b"
  26. elif func == "eval":
  27. kwargs["expr"] = "a + b"
  28. elif func == "set_index":
  29. kwargs["keys"] = ["a"]
  30. elif func == "sort_values":
  31. kwargs["by"] = ["a"]
  32. with pytest.raises(ValueError, match=msg):
  33. getattr(dataframe, func)(**kwargs)