test_util.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import pytest
  3. from pandas import (
  4. array,
  5. compat,
  6. )
  7. import pandas._testing as tm
  8. def test_numpy_err_state_is_default():
  9. expected = {"over": "warn", "divide": "warn", "invalid": "warn", "under": "ignore"}
  10. import numpy as np
  11. # The error state should be unchanged after that import.
  12. assert np.geterr() == expected
  13. def test_convert_rows_list_to_csv_str():
  14. rows_list = ["aaa", "bbb", "ccc"]
  15. ret = tm.convert_rows_list_to_csv_str(rows_list)
  16. if compat.is_platform_windows():
  17. expected = "aaa\r\nbbb\r\nccc\r\n"
  18. else:
  19. expected = "aaa\nbbb\nccc\n"
  20. assert ret == expected
  21. @pytest.mark.parametrize("strict_data_files", [True, False])
  22. def test_datapath_missing(datapath):
  23. with pytest.raises(ValueError, match="Could not find file"):
  24. datapath("not_a_file")
  25. def test_datapath(datapath):
  26. args = ("io", "data", "csv", "iris.csv")
  27. result = datapath(*args)
  28. expected = os.path.join(os.path.dirname(os.path.dirname(__file__)), *args)
  29. assert result == expected
  30. def test_external_error_raised():
  31. with tm.external_error_raised(TypeError):
  32. raise TypeError("Should not check this error message, so it will pass")
  33. def test_is_sorted():
  34. arr = array([1, 2, 3], dtype="Int64")
  35. tm.assert_is_sorted(arr)
  36. arr = array([4, 2, 3], dtype="Int64")
  37. with pytest.raises(AssertionError, match="ExtensionArray are different"):
  38. tm.assert_is_sorted(arr)