/
test_trait_documenter.py
54 lines (38 loc) · 1.45 KB
/
test_trait_documenter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
""" Tests for the trait documenter. """
import StringIO
import sys
import tokenize
from unittest import skipIf
from traits.testing.unittest_tools import unittest
def _sphinx_present():
try:
import sphinx
except ImportError:
return False
return True
# Skipping for python 3.2 because sphinx does not work on it.
def python_version_is_32():
return "{}.{}".format(
sys.version_info.major,
sys.version_info.minor) == "3.2"
@skipIf(not _sphinx_present() or python_version_is_32(),
"Sphinx not available. Cannot test documenter")
class TestTraitDocumenter(unittest.TestCase):
""" Tests for the trait documenter. """
def setUp(self):
self.source = """
depth_interval = Property(Tuple(Float, Float),
depends_on="_depth_interval")
"""
string_io = StringIO.StringIO(self.source)
tokens = tokenize.generate_tokens(string_io.readline)
self.tokens = tokens
def test_get_definition_tokens(self):
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.
string = tokenize.untokenize(definition_tokens)
self.assertEqual(self.source.rstrip(), string)
if __name__ == '__main__':
unittest.main()
# ## EOF ######################################################################