test_util.py 1.5 KB

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