better testing (+ fixes) of sort_attributes
This commit is contained in:
@@ -2,6 +2,12 @@ import unittest
|
||||
from wsme import types
|
||||
|
||||
|
||||
def gen_class():
|
||||
d = {}
|
||||
exec('''class tmp(object): pass''', d)
|
||||
return d['tmp']
|
||||
|
||||
|
||||
class TestTypes(unittest.TestCase):
|
||||
def test_flat_type(self):
|
||||
class Flat(object):
|
||||
@@ -46,6 +52,21 @@ class TestTypes(unittest.TestCase):
|
||||
assert ForcedOrder._wsme_attributes[1][0] == 'a1'
|
||||
assert ForcedOrder._wsme_attributes[2][0] == 'a3'
|
||||
|
||||
c = gen_class()
|
||||
print c
|
||||
types.register_type(c)
|
||||
del c._wsme_attributes
|
||||
|
||||
c.a2 = int
|
||||
c.a1 = int
|
||||
c.a3 = int
|
||||
|
||||
types.register_type(c)
|
||||
|
||||
assert c._wsme_attributes[0][0] == 'a1'
|
||||
assert c._wsme_attributes[1][0] == 'a2'
|
||||
assert c._wsme_attributes[2][0] == 'a3'
|
||||
|
||||
def test_wsproperty(self):
|
||||
class WithWSProp(object):
|
||||
def __init__(self):
|
||||
|
||||
@@ -50,7 +50,11 @@ def sort_attributes(class_, attributes):
|
||||
|
||||
#. Sort by alphabetically"""
|
||||
|
||||
if not len(attributes):
|
||||
return
|
||||
|
||||
attrs = dict(attributes)
|
||||
|
||||
if hasattr(class_, '_wsme_attr_order'):
|
||||
names_order = class_._wsme_attr_order
|
||||
else:
|
||||
@@ -65,7 +69,7 @@ def sort_attributes(class_, attributes):
|
||||
if aname in names and aname not in names_order:
|
||||
names_order.append(aname)
|
||||
assert len(names_order) == len(names)
|
||||
except IOError, e:
|
||||
except (TypeError, IOError):
|
||||
names_order = list(names)
|
||||
names_order.sort()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user