There will be a webinar on pyGIMLi hosted by SEG on March 19, 2024 at 4 pm CET. Register for free here.

pygimli.testing#

Testing utilities

In Python you can call pygimli.test() to run all docstring examples.

Writing tests for pyGIMLi#

Please check: https://docs.pytest.org/en/latest/

Overview#

Functions

devTests()

Determine pygimli testing mode.

join(a, *p)

Join two or more pathname components, inserting '/' as needed.

realpath(filename, *[, strict])

Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path.

setDevTests(mode)

Set pygimli testing mode.

test([target, show, onlydoctests, coverage, ...])

Run docstring examples and additional tests.

Functions#

pygimli.testing.devTests()[source]#

Determine pygimli testing mode.

Returns True if pygimli is in testing mode.

pygimli.testing.join(a, *p)[source]#

Join two or more pathname components, inserting ‘/’ as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.

pygimli.testing.realpath(filename, *, strict=False)[source]#

Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path.

pygimli.testing.setDevTests(mode)[source]#

Set pygimli testing mode.

Testing mode ensures a constant seed for the random generator if you use pg.randn().

pygimli.testing.test(target=None, show=False, onlydoctests=False, coverage=False, htmlreport=False, abort=False, verbose=True, devTests=False)[source]#

Run docstring examples and additional tests.

>>> import pygimli as pg
>>> # Run the whole test suite.
>>> pg.test() 
>>> # Test a single function by a string.
>>> pg.test("utils.boxprint", verbose=False) 
>>> # The target argument can also be the function directly
>>> from pygimli.utils import boxprint
>>> pg.test(boxprint, verbose=False) 
>>> # Use some logical expressions
>>> pg.test("draw and not drawMesh") 
Parameters:
  • target (function or string or pattern (-k flag in pytest), optional) – Function or method to test. By default everything is tested.

  • show (boolean, optional) – Show viewer windows during test run. They will be closed automatically.

  • onlydoctests (boolean, optional) – Run test files in testing as well.

  • coverage (boolean, optional) – Create a coverage report. Requires the pytest-cov plugin.

  • htmlreport (str, optional) – Filename for HTML report such as www.pygimli.org/build_tests.html. Requires pytest-html plugin.

  • abort (boolean, optional) – Return correct exit code, e.g. abort documentation build when a test fails.

  • devTests (boolean[False]) – Don’t skip special tests marked for development, only with the @pg.skipOnDefaultTest decorator. Can be overwritten by env DEVTESTS.