Skip to content

Commit

Permalink
Add a new target 'doctest' to run doctests only and simplify Makefile (
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Mar 23, 2023
1 parent 8501f5d commit 3eabb99
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
PROJECT=pygmt
TESTDIR=tmp-test-dir-with-unique-name
PYTEST_COV_ARGS=--cov=$(PROJECT) --cov-config=../pyproject.toml \
--cov-report=term-missing --cov-report=xml --cov-report=html \
--pyargs ${PYTEST_EXTRA}
--cov-report=term-missing --cov-report=xml --cov-report=html
FORMAT_FILES=$(PROJECT) doc/conf.py examples
LINT_FILES=$(PROJECT) doc/conf.py

Expand All @@ -13,7 +12,8 @@ help:
@echo " install install in editable mode"
@echo " package build source and wheel distributions"
@echo " test run the test suite (including some doctests) and report coverage"
@echo " fulltest run the test suite (including all doctests) and report coverage"
@echo " fulltest run the test suite (including all doctests)"
@echo " doctest run the doctests only"
@echo " test_no_images run the test suite (including all doctests) but skip image comparisons"
@echo " format run black, blackdoc, docformatter and isort to automatically format the code"
@echo " check run code style and quality checks (black, blackdoc, docformatter, flakeheaven and isort)"
Expand All @@ -28,41 +28,35 @@ install:
package:
python -m build

test:
# Run a tmp folder to make sure the tests are run on the installed version
_runtest:
# Run in a tmp folder to make sure the tests are run on the installed version
mkdir -p $(TESTDIR)
@echo ""
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
@echo ""
cd $(TESTDIR); PYGMT_USE_EXTERNAL_DISPLAY="false" pytest $(PYTEST_COV_ARGS) --doctest-plus $(PROJECT)
cp $(TESTDIR)/coverage.xml .
cp -r $(TESTDIR)/htmlcov .
rm -r $(TESTDIR)

fulltest:
# Run a tmp folder to make sure the tests are run on the installed version
mkdir -p $(TESTDIR)
cd $(TESTDIR); PYGMT_USE_EXTERNAL_DISPLAY="false" pytest $(PYTEST_ARGS) --pyargs $(PROJECT)
@echo ""
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
@echo ""
cd $(TESTDIR); PYGMT_USE_EXTERNAL_DISPLAY="false" pytest $(PYTEST_COV_ARGS) $(PROJECT)
cp $(TESTDIR)/coverage.xml .
cp -r $(TESTDIR)/htmlcov .
if [ -e $(TESTDIR)/coverage.xml ]; then cp $(TESTDIR)/coverage.xml .; fi
if [ -e $(TESTDIR)/htmlcov ]; then cp -r $(TESTDIR)/htmlcov .; fi
rm -r $(TESTDIR)

test_no_images:
# Run a tmp folder to make sure the tests are run on the installed version
mkdir -p $(TESTDIR)
@echo ""
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
@echo ""
# run pytest without the --mpl option to disable image comparisons
# use -o to override the addopts in pyproject.toml file
cd $(TESTDIR); \
PYGMT_USE_EXTERNAL_DISPLAY="false" \
pytest -o addopts="--verbose --durations=0 --durations-min=0.2 --doctest-modules" \
$(PYTEST_COV_ARGS) $(PROJECT)
rm -r $(TESTDIR)
# run regular tests (unit tests + some doctests)
test: PYTEST_ARGS=--doctest-plus $(PYTEST_COV_ARGS) ${PYTEST_EXTRA}
test: _runtest

# run full tests (unit tests + all doctests)
fulltest: PYTEST_ARGS=${PYTEST_EXTRA}
fulltest: _runtest

# run doctests only
doctest: PYTEST_ARGS=--ignore=../pygmt/tests ${PYTEST_EXTRA}
doctest: _runtest

# run tests without image comparisons
# run pytest without the --mpl option to disable image comparisons
# use '-o addopts' to override 'addopts' settings in pyproject.toml file
test_no_images: PYTEST_ARGS=-o addopts="--verbose --durations=0 --durations-min=0.2 --doctest-modules"
test_no_images: _runtest

format:
isort .
Expand Down

0 comments on commit 3eabb99

Please sign in to comment.