Update datetypename() to work with DictType and ArrayType instances.
--HG-- extra : source : cef0a57e57255c4437922d3c2b0a81c84ad29b07
This commit is contained in:
parent
322dca63c5
commit
6af9b92878
@ -3,6 +3,7 @@ import sphinx
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import wsme.types
|
import wsme.types
|
||||||
|
from wsme import sphinxext
|
||||||
|
|
||||||
docpath = os.path.join(
|
docpath = os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
@ -24,3 +25,21 @@ class TestSphinxExt(unittest.TestCase):
|
|||||||
'-d', '.test_sphinxext/doctree',
|
'-d', '.test_sphinxext/doctree',
|
||||||
docpath,
|
docpath,
|
||||||
'.test_sphinxext/html']) == 0
|
'.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)')
|
||||||
|
@ -27,6 +27,11 @@ field_re = re.compile(r':(?P<field>\w+)(\s+(?P<name>\w+))?:')
|
|||||||
def datatypename(datatype):
|
def datatypename(datatype):
|
||||||
if isinstance(datatype, wsme.types.UserType):
|
if isinstance(datatype, wsme.types.UserType):
|
||||||
return datatype.name
|
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__
|
return datatype.__name__
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user