MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_inspect_classify_class_attrs

Method test_inspect_classify_class_attrs

Lib/test/test_enum.py:5091–5154  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5089 self.fail("result does not equal expected, see print above")
5090
5091 def test_inspect_classify_class_attrs(self):
5092 # indirectly test __objclass__
5093 from inspect import Attribute
5094 values = [
5095 Attribute(name='__class__', kind='data',
5096 defining_class=object, object=EnumType),
5097 Attribute(name='__contains__', kind='method',
5098 defining_class=EnumType, object=self.Color.__contains__),
5099 Attribute(name='__doc__', kind='data',
5100 defining_class=self.Color, object='...'),
5101 Attribute(name='__getitem__', kind='method',
5102 defining_class=EnumType, object=self.Color.__getitem__),
5103 Attribute(name='__iter__', kind='method',
5104 defining_class=EnumType, object=self.Color.__iter__),
5105 Attribute(name='__init_subclass__', kind='class method',
5106 defining_class=object, object=getattr(self.Color, '__init_subclass__')),
5107 Attribute(name='__len__', kind='method',
5108 defining_class=EnumType, object=self.Color.__len__),
5109 Attribute(name='__members__', kind='property',
5110 defining_class=EnumType, object=EnumType.__members__),
5111 Attribute(name='__module__', kind='data',
5112 defining_class=self.Color, object=__name__),
5113 Attribute(name='__name__', kind='data',
5114 defining_class=self.Color, object='Color'),
5115 Attribute(name='__qualname__', kind='data',
5116 defining_class=self.Color, object='TestStdLib.Color'),
5117 Attribute(name='YELLOW', kind='data',
5118 defining_class=self.Color, object=self.Color.YELLOW),
5119 Attribute(name='MAGENTA', kind='data',
5120 defining_class=self.Color, object=self.Color.MAGENTA),
5121 Attribute(name='CYAN', kind='data',
5122 defining_class=self.Color, object=self.Color.CYAN),
5123 Attribute(name='name', kind='data',
5124 defining_class=Enum, object=Enum.__dict__['name']),
5125 Attribute(name='value', kind='data',
5126 defining_class=Enum, object=Enum.__dict__['value']),
5127 ]
5128 for v in values:
5129 try:
5130 v.name
5131 except AttributeError:
5132 print(v)
5133 values.sort(key=lambda item: item.name)
5134 result = list(inspect.classify_class_attrs(self.Color))
5135 result.sort(key=lambda item: item.name)
5136 self.assertEqual(
5137 len(values), len(result),
5138 "%s != %s" % ([a.name for a in values], [a.name for a in result])
5139 )
5140 failed = False
5141 for v, r in zip(values, result):
5142 if r.name in ('__init_subclass__', '__doc__'):
5143 # not sure how to make the __init_subclass_ Attributes match
5144 # so as long as there is one, call it good
5145 # __doc__ is too big to check exactly, so treat the same as __init_subclass__
5146 for name in ('name','kind','defining_class'):
5147 if getattr(v, name) != getattr(r, name):
5148 print('\n%s\n%s\n%s\n%s\n' % ('=' * 75, r, v, '=' * 75), sep='')

Callers

nothing calls this directly

Calls 8

AttributeClass · 0.85
getattrFunction · 0.85
listClass · 0.85
lenFunction · 0.85
printFunction · 0.50
sortMethod · 0.45
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected