Skip to content

Commit

Permalink
Workaround lack of sphinx in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoborini committed Jul 20, 2015
1 parent b1a8b4a commit 4a7aac2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions traits/util/tests/test_trait_documenter.py
@@ -1,10 +1,30 @@
""" Tests for the trait documenter. """

import contextlib
import sys
import tokenize
import types
from mock import Mock

from traits.util.trait_documenter import _get_definition_tokens
from traits.testing.unittest_tools import unittest

@contextlib.contextmanager
def sphinx_mock_import():
try:
from sphinx.ext.autodoc import ClassLevelDocumenter
except ImportError:
sphinx = types.ModuleType("sphinx")
sphinx.ext = types.ModuleType("sphinx.ext")
sphinx.ext.autodoc = types.ModuleType("sphinx.ext.autodoc")
sys.modules["sphinx"] = sphinx
sys.modules["sphinx.ext"] = sphinx.ext
sys.modules["sphinx.ext.autodoc"] = sphinx.ext.autodoc
sphinx.ext.autodoc.__dict__["ClassLevelDocumenter"] = Mock()

yield

del sys.modules["sphinx.ext.autodoc"]


class TestTraitDocumenter(unittest.TestCase):
""" Tests for the trait documenter. """
Expand Down Expand Up @@ -43,10 +63,13 @@ def setUp(self):
' depends_on="_depth_interval")\n')]

def test_get_definition_tokens(self):
definition_tokens = _get_definition_tokens(self.tokens)
with sphinx_mock_import():
from traits.util.trait_documenter import _get_definition_tokens

definition_tokens = _get_definition_tokens(self.tokens)

# Check if they are correctly untokenized. This should not raise.
tokenize.untokenize(definition_tokens)
# Check if they are correctly untokenized. This should not raise.
tokenize.untokenize(definition_tokens)

if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit 4a7aac2

Please sign in to comment.