conftest.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import os
  2. import pytest
  3. from pandas import read_csv, read_table
  4. class BaseParser(object):
  5. engine = None
  6. low_memory = True
  7. float_precision_choices = []
  8. def update_kwargs(self, kwargs):
  9. kwargs = kwargs.copy()
  10. kwargs.update(dict(engine=self.engine,
  11. low_memory=self.low_memory))
  12. return kwargs
  13. def read_csv(self, *args, **kwargs):
  14. kwargs = self.update_kwargs(kwargs)
  15. return read_csv(*args, **kwargs)
  16. def read_table(self, *args, **kwargs):
  17. kwargs = self.update_kwargs(kwargs)
  18. return read_table(*args, **kwargs)
  19. class CParser(BaseParser):
  20. engine = "c"
  21. float_precision_choices = [None, "high", "round_trip"]
  22. class CParserHighMemory(CParser):
  23. low_memory = False
  24. class CParserLowMemory(CParser):
  25. low_memory = True
  26. class PythonParser(BaseParser):
  27. engine = "python"
  28. float_precision_choices = [None]
  29. @pytest.fixture
  30. def csv_dir_path(datapath):
  31. return datapath("io", "parser", "data")
  32. @pytest.fixture
  33. def csv1(csv_dir_path):
  34. return os.path.join(csv_dir_path, "test1.csv")
  35. _cParserHighMemory = CParserHighMemory()
  36. _cParserLowMemory = CParserLowMemory()
  37. _pythonParser = PythonParser()
  38. _py_parsers_only = [_pythonParser]
  39. _c_parsers_only = [_cParserHighMemory, _cParserLowMemory]
  40. _all_parsers = _c_parsers_only + _py_parsers_only
  41. _py_parser_ids = ["python"]
  42. _c_parser_ids = ["c_high", "c_low"]
  43. _all_parser_ids = _c_parser_ids + _py_parser_ids
  44. @pytest.fixture(params=_all_parsers,
  45. ids=_all_parser_ids)
  46. def all_parsers(request):
  47. return request.param
  48. @pytest.fixture(params=_c_parsers_only,
  49. ids=_c_parser_ids)
  50. def c_parser_only(request):
  51. return request.param
  52. @pytest.fixture(params=_py_parsers_only,
  53. ids=_py_parser_ids)
  54. def python_parser_only(request):
  55. return request.param