# pyresample.test.utils module

Utilities for testing.

This mostly takes from astropy’s method for checking collected_warnings during tests.

class pyresample.test.utils.CustomScheduler(max_computes=1)

  Bases: `object`

  Scheduler raising an exception if data are computed too many times.

  Set starting and maximum compute counts.

  __init__(max_computes=1)

    Set starting and maximum compute counts.

pyresample.test.utils.assert_future_geometry(area_def, expect_future_geometry)

  Check that the provided geometry is an instance of a pyresample 2.0 geometry class.

pyresample.test.utils.assert_maximum_dask_computes(max_computes=1)

  Context manager to make sure dask computations are not executed more than `max_computes` times.

pyresample.test.utils.assert_warnings_contain(collected_warnings, message, count=1)

  Check that collected warnings with catch_warnings contain certain messages.

  Parameters:

    - collected_warnings (`list`) – List of warnings collected using `warnings.catch_warnings(record=True)`.

    - message (`str`) – Lowercase string to check is in one or more of the warning messages.

    - count (`int`) – Number of warnings that should contain the provided message string.

  Examples

  Use during test code with:

      with warnings.catch_warnings(record=True) as w:
          # test code
      assert_warnings_contain(w, "invalid data", 1)

class pyresample.test.utils.catch_warnings(*classes)

  Bases: `catch_warnings`

  A high-powered version of warnings.catch_warnings to use for testing.

  Makes sure that there is no dependence on the order in which the tests are run.

  This completely blitzes any memory of any warnings that have appeared before so that all warnings will be caught and displayed.

  `*args` is a set of warning classes to collect. If no arguments are provided, all warnings are collected.

  Use as follows:

      with catch_warnings(MyCustomWarning) as w:
          do.something.bad()
      assert len(w) > 0

  Initialize the classes of warnings to catch.

  __init__(*classes)

    Initialize the classes of warnings to catch.

pyresample.test.utils.create_test_latitude(start, stop, shape, twist_factor=0.0, dtype=<class 'numpy.float32'>)

  Get basic sample of latitude data.

pyresample.test.utils.create_test_longitude(start, stop, shape, twist_factor=0.0, dtype=<class 'numpy.float32'>)

  Get basic sample of longitude data.

pyresample.test.utils.friendly_crs_equal(expected, actual, keys=None, use_obj=True, use_wkt=True)

  Test if two projection definitions are equal.

  The main purpose of this function is to help manage differences between pyproj versions. Depending on the version installed and used pyresample may provide a different proj_dict or other similar CRS definition.

  Parameters:

    - expected (dict, str, pyproj.crs.CRS) – Expected CRS definition as a PROJ dictionary or string or CRS object.

    - actual (dict, str, pyproj.crs.CRS) – Actual CRS definition

    - keys (list) – Specific PROJ parameters to look for. Only takes effect if use_obj is False.

    - use_obj (bool) – Use pyproj’s CRS object to test equivalence. Default is True.

    - use_wkt (bool) – Increase likely hood of making CRS objects equal by converting WellKnownText before converting to the final CRS object. Requires use_obj. Defaults to True.

pyresample.test.utils.treat_deprecations_as_exceptions()

  Turn all DeprecationWarnings into exceptions.

  Deprecation warnings indicate deprecated uses of Python itself or Numpy. This completely resets the warning filters and any “already seen” warning state.