Skip to content

Commit

Permalink
Fixes to the test and skipping on 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoborini committed Jul 21, 2015
1 parent 70ed820 commit fae5a5f
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 deletions traits/util/tests/test_trait_documenter.py
@@ -1,57 +1,52 @@
""" 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.tokens = [
(1, 'Property', (12, 21), (12, 29),
' depth_interval = Property(Tuple(Float, Float),\n'),
(51, '(', (12, 29), (12, 30),
' depth_interval = Property(Tuple(Float, Float),\n'),
(1, 'Tuple', (12, 30), (12, 35),
' depth_interval = Property(Tuple(Float, Float),\n'),
(51, '(', (12, 35), (12, 36),
' depth_interval = Property(Tuple(Float, Float),\n'),
(1, 'Float', (12, 36), (12, 41),
' depth_interval = Property(Tuple(Float, Float),\n'),
(51, ',', (12, 41), (12, 42),
' depth_interval = Property(Tuple(Float, Float),\n'),
(1, 'Float', (12, 43), (12, 48),
' depth_interval = Property(Tuple(Float, Float),\n'),
(51, ')', (12, 48), (12, 49),
' depth_interval = Property(Tuple(Float, Float),\n'),
(51, ',', (12, 49), (12, 50),
' depth_interval = Property(Tuple(Float, Float),\n'),
(54, '\n', (12, 50), (12, 51),
' depth_interval = Property(Tuple(Float, Float),\n'),
(1, 'depends_on', (13, 30), (13, 40),
' depends_on="_depth_interval")\n'),
(51, '=', (13, 40), (13, 41),
' depends_on="_depth_interval")\n'),
(3, '"_depth_interval"', (13, 41), (13, 58),
' depends_on="_depth_interval")\n'),
(51, ')', (13, 58), (13, 59),
' depends_on="_depth_interval")\n'),
(4, '\n', (13, 59), (13, 60),
' depends_on="_depth_interval")\n')]
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):
try:
import sphinx
except ImportError:
self.skipTest("Sphinx not available. Cannot import documenter")

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)
string = tokenize.untokenize(definition_tokens)

self.assertEqual(self.source.rstrip(), string)

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

0 comments on commit fae5a5f

Please sign in to comment.