diff --git a/tests/test_sphinxext.py b/tests/test_sphinxext.py index a86e11f..62d0ee1 100644 --- a/tests/test_sphinxext.py +++ b/tests/test_sphinxext.py @@ -3,6 +3,7 @@ import sphinx import os.path import wsme.types +from wsme import sphinxext docpath = os.path.join( os.path.dirname(__file__), @@ -24,3 +25,21 @@ class TestSphinxExt(unittest.TestCase): '-d', '.test_sphinxext/doctree', docpath, '.test_sphinxext/html']) == 0 + + +class TestDataTypeName(unittest.TestCase): + def test_user_type(self): + self.assertEqual(sphinxext.datatypename(ASampleType), + 'ASampleType') + + def test_dict_type(self): + d = wsme.types.DictType(str, str) + self.assertEqual(sphinxext.datatypename(d), 'dict(str: str)') + d = wsme.types.DictType(str, ASampleType) + self.assertEqual(sphinxext.datatypename(d), 'dict(str: ASampleType)') + + def test_array_type(self): + d = wsme.types.ArrayType(str) + self.assertEqual(sphinxext.datatypename(d), 'list(str)') + d = wsme.types.ArrayType(ASampleType) + self.assertEqual(sphinxext.datatypename(d), 'list(ASampleType)') diff --git a/wsme/sphinxext.py b/wsme/sphinxext.py index 5a97fb4..3f845d3 100644 --- a/wsme/sphinxext.py +++ b/wsme/sphinxext.py @@ -27,6 +27,11 @@ field_re = re.compile(r':(?P\w+)(\s+(?P\w+))?:') def datatypename(datatype): if isinstance(datatype, wsme.types.UserType): return datatype.name + if isinstance(datatype, wsme.types.DictType): + return 'dict(%s: %s)' % (datatypename(datatype.key_type), + datatypename(datatype.value_type)) + if isinstance(datatype, wsme.types.ArrayType): + return 'list(%s)' % datatypename(datatype.item_type) return datatype.__name__