conftest.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """Pytest and scipy-doctest configuration for Shapely."""
  2. import numpy
  3. import pytest
  4. from shapely import geos_version_string
  5. try:
  6. from scipy_doctest.conftest import dt_config
  7. HAVE_SCPDT = True
  8. except ModuleNotFoundError:
  9. HAVE_SCPDT = False
  10. shapely20_todo = pytest.mark.xfail(
  11. strict=True, reason="Not yet implemented for Shapely 2.0"
  12. )
  13. shapely20_wontfix = pytest.mark.xfail(strict=True, reason="Will fail for Shapely 2.0")
  14. def pytest_report_header(config):
  15. """Header for pytest."""
  16. vers = [
  17. f"GEOS version: {geos_version_string}",
  18. f"NumPy version: {numpy.__version__}",
  19. ]
  20. return "\n".join(vers)
  21. if HAVE_SCPDT:
  22. import doctest
  23. import warnings
  24. from contextlib import contextmanager
  25. @contextmanager
  26. def warnings_errors_and_rng(test=None):
  27. """Filter out some warnings."""
  28. depr_msgs = "|".join(
  29. [
  30. # https://github.com/pyproj4/pyproj/issues/1468
  31. "Conversion of an array with ndim",
  32. ]
  33. )
  34. runtime_msgs = "|".join(
  35. [
  36. # https://github.com/libgeos/geos/pull/1226
  37. "invalid value encountered in coverage_union",
  38. ]
  39. )
  40. with warnings.catch_warnings():
  41. if depr_msgs:
  42. warnings.filterwarnings("ignore", depr_msgs, DeprecationWarning)
  43. if runtime_msgs:
  44. warnings.filterwarnings("ignore", runtime_msgs, RuntimeWarning)
  45. yield
  46. # find and check doctests under this context manager
  47. dt_config.user_context_mgr = warnings_errors_and_rng
  48. # relax all NumPy scalar type repr, e.g. `np.int32(0)` matches `0`
  49. dt_config.strict_check = False
  50. dt_config.optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
  51. # ignores are for things fail doctest collection (optionals etc)
  52. dt_config.pytest_extra_ignore = [
  53. "shapely/geos.py",
  54. ]