From 0e9de200bc1ee9e74ed4f99a1d4141551e8e70f9 Mon Sep 17 00:00:00 2001 From: Jon Crall <erotemic@gmail.com> Date: Wed, 2 Oct 2019 01:37:49 -0400 Subject: [PATCH] Enable doctests in CI with xdoctest (#1479) * Enable doctests in CI with xdoctest * use xdoctest in travis file * Fix doctest warnings * dont test eggs directory * Ensure xdoctest is installed before running CI --- .travis.yml | 4 ++-- mmdet/models/bbox_heads/convfc_bbox_head.py | 2 +- mmdet/models/bbox_heads/double_bbox_head.py | 2 +- mmdet/models/losses/utils.py | 1 + mmdet/models/mask_heads/fused_semantic_head.py | 2 +- pytest.ini | 7 +++++++ setup.py | 2 +- tests/requirements.txt | 3 ++- 8 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 pytest.ini diff --git a/.travis.yml b/.travis.yml index 30595047..5d53d790 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ script: - yapf -r -d --style .style.yapf mmdet/ tools/ tests/ - python setup.py check -m -s - python setup.py build_ext --inplace - - coverage run --source mmdet -m py.test tests -v --doctest-modules + - coverage run --source mmdet -m py.test -v --xdoctest-modules tests mmdet after_success: - - coverage report \ No newline at end of file + - coverage report diff --git a/mmdet/models/bbox_heads/convfc_bbox_head.py b/mmdet/models/bbox_heads/convfc_bbox_head.py index f6659b32..777c4559 100644 --- a/mmdet/models/bbox_heads/convfc_bbox_head.py +++ b/mmdet/models/bbox_heads/convfc_bbox_head.py @@ -7,7 +7,7 @@ from .bbox_head import BBoxHead @HEADS.register_module class ConvFCBBoxHead(BBoxHead): - """More general bbox head, with shared conv and fc layers and two optional + r"""More general bbox head, with shared conv and fc layers and two optional separated branches. /-> cls convs -> cls fcs -> cls diff --git a/mmdet/models/bbox_heads/double_bbox_head.py b/mmdet/models/bbox_heads/double_bbox_head.py index a2934a0b..c8a0e269 100644 --- a/mmdet/models/bbox_heads/double_bbox_head.py +++ b/mmdet/models/bbox_heads/double_bbox_head.py @@ -71,7 +71,7 @@ class BasicResBlock(nn.Module): @HEADS.register_module class DoubleConvFCBBoxHead(BBoxHead): - """Bbox head used in Double-Head R-CNN + r"""Bbox head used in Double-Head R-CNN /-> cls /-> shared convs -> diff --git a/mmdet/models/losses/utils.py b/mmdet/models/losses/utils.py index 5c16e062..3361c6ca 100644 --- a/mmdet/models/losses/utils.py +++ b/mmdet/models/losses/utils.py @@ -64,6 +64,7 @@ def weighted_loss(loss_func): :Example: + >>> import torch >>> @weighted_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() diff --git a/mmdet/models/mask_heads/fused_semantic_head.py b/mmdet/models/mask_heads/fused_semantic_head.py index ee6910f4..80dab051 100644 --- a/mmdet/models/mask_heads/fused_semantic_head.py +++ b/mmdet/models/mask_heads/fused_semantic_head.py @@ -9,7 +9,7 @@ from ..utils import ConvModule @HEADS.register_module class FusedSemanticHead(nn.Module): - """Multi-level fused semantic segmentation head. + r"""Multi-level fused semantic segmentation head. in_1 -> 1x1 conv --- | diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..9796e871 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +addopts = --xdoctest --xdoctest-style=auto +norecursedirs = .git ignore build __pycache__ data docker docs .eggs + +filterwarnings= default + ignore:.*No cfgstr given in Cacher constructor or call.*:Warning + ignore:.*Define the __nice__ method for.*:Warning diff --git a/setup.py b/setup.py index 3c8f55c7..c75f5218 100644 --- a/setup.py +++ b/setup.py @@ -152,7 +152,7 @@ if __name__ == '__main__': ], license='Apache License 2.0', setup_requires=['pytest-runner', 'cython', 'numpy'], - tests_require=['pytest'], + tests_require=['pytest', 'xdoctest'], install_requires=get_requirements(), ext_modules=[ make_cython_ext( diff --git a/tests/requirements.txt b/tests/requirements.txt index 4eced799..a1f3efbb 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -2,4 +2,5 @@ isort flake8 yapf pytest-cov -codecov \ No newline at end of file +codecov +xdoctest >= 0.10.0 -- GitLab