# pylint: disable=missing-docstring## The main API for PyGMT.## All of PyGMT is operated on a "modern mode session" (new to GMT6). When you# import the pygmt library, a new session will be started automatically. The# session will be closed when the current Python process terminates. Thus, the# Python API does not expose the `gmt begin` and `gmt end` commands.importatexitas_atexitfrom._versionimportget_versionsas_get_versions# Import modules to make the high-level GMT Python APIfrom.session_managementimportbeginas_begin,endas_endfrom.figureimportFigurefrom.griddingimportsurfacefrom.samplingimportgrdtrackfrom.mathopsimportmakecptfrom.modulesimportconfig,info,grdinfo,whichfrom.importdatasets# Get the version number through versioneer__version__=_get_versions()["version"]__commit__=_get_versions()["full-revisionid"]# Start our global modern mode session_begin()# Tell Python to run _end when shutting down_atexit.register(_end)
[docs]defprint_clib_info():""" Print information about the GMT shared library that we can find. Includes the GMT version, default values for parameters, the path to the ``libgmt`` shared library, and GMT directories. """from.clibimportSessionlines=["Loaded libgmt:"]withSession()asses:forkeyinsorted(ses.info):lines.append(" {}: {}".format(key,ses.info[key]))print("\n".join(lines))
[docs]deftest(doctest=True,verbose=True,coverage=False,figures=True):""" Run the test suite. Uses `pytest <http://pytest.org/>`__ to discover and run the tests. If you haven't already, you can install it with `conda <http://conda.pydata.org/>`__ or `pip <https://pip.pypa.io/en/stable/>`__. Parameters ---------- doctest : bool If ``True``, will run the doctests as well (code examples that start with a ``>>>`` in the docs). verbose : bool If ``True``, will print extra information during the test run. coverage : bool If ``True``, will run test coverage analysis on the code as well. Requires ``pytest-cov``. figures : bool If ``True``, will test generated figures against saved baseline figures. Requires ``pytest-mpl`` and ``matplotlib``. Raises ------ AssertionError If pytest returns a non-zero error code indicating that some tests have failed. """importpytestprint_clib_info()package=__name__args=[]ifverbose:args.append("-vv")ifcoverage:args.append("--cov={}".format(package))args.append("--cov-report=term-missing")ifdoctest:args.append("--doctest-modules")iffigures:args.append("--mpl")args.append("--pyargs")args.append(package)status=pytest.main(args)assertstatus==0,"Some tests have failed."