(self)
| 1058 | self.assertNotIsInstance(RevRevBlocked(), Reversible) |
| 1059 | |
| 1060 | def test_Collection(self): |
| 1061 | # Check some non-collections |
| 1062 | non_collections = [None, 42, 3.14, 1j, lambda x: 2*x] |
| 1063 | for x in non_collections: |
| 1064 | self.assertNotIsInstance(x, Collection) |
| 1065 | self.assertNotIsSubclass(type(x), Collection) |
| 1066 | # Check some non-collection iterables |
| 1067 | non_col_iterables = [_test_gen(), iter(b''), iter(bytearray()), |
| 1068 | (x for x in [])] |
| 1069 | for x in non_col_iterables: |
| 1070 | self.assertNotIsInstance(x, Collection) |
| 1071 | self.assertNotIsSubclass(type(x), Collection) |
| 1072 | # Check some collections |
| 1073 | samples = [set(), frozenset(), dict(), bytes(), str(), tuple(), |
| 1074 | list(), dict().keys(), dict().items(), dict().values()] |
| 1075 | for x in samples: |
| 1076 | self.assertIsInstance(x, Collection) |
| 1077 | self.assertIsSubclass(type(x), Collection) |
| 1078 | # Check also Mapping, MutableMapping, etc. |
| 1079 | self.assertIsSubclass(Sequence, Collection) |
| 1080 | self.assertIsSubclass(Mapping, Collection) |
| 1081 | self.assertIsSubclass(MutableMapping, Collection) |
| 1082 | self.assertIsSubclass(Set, Collection) |
| 1083 | self.assertIsSubclass(MutableSet, Collection) |
| 1084 | self.assertIsSubclass(Sequence, Collection) |
| 1085 | # Check direct subclassing |
| 1086 | class Col(Collection): |
| 1087 | def __iter__(self): |
| 1088 | return iter(list()) |
| 1089 | def __len__(self): |
| 1090 | return 0 |
| 1091 | def __contains__(self, item): |
| 1092 | return False |
| 1093 | class DerCol(Col): pass |
| 1094 | self.assertEqual(list(iter(Col())), []) |
| 1095 | self.assertNotIsSubclass(list, Col) |
| 1096 | self.assertNotIsSubclass(set, Col) |
| 1097 | self.assertNotIsSubclass(float, Col) |
| 1098 | self.assertEqual(list(iter(DerCol())), []) |
| 1099 | self.assertNotIsSubclass(list, DerCol) |
| 1100 | self.assertNotIsSubclass(set, DerCol) |
| 1101 | self.assertNotIsSubclass(float, DerCol) |
| 1102 | self.validate_abstract_methods(Collection, '__len__', '__iter__', |
| 1103 | '__contains__') |
| 1104 | # Check sized container non-iterable (which is not Collection) etc. |
| 1105 | class ColNoIter: |
| 1106 | def __len__(self): return 0 |
| 1107 | def __contains__(self, item): return False |
| 1108 | class ColNoSize: |
| 1109 | def __iter__(self): return iter([]) |
| 1110 | def __contains__(self, item): return False |
| 1111 | class ColNoCont: |
| 1112 | def __iter__(self): return iter([]) |
| 1113 | def __len__(self): return 0 |
| 1114 | self.assertNotIsSubclass(ColNoIter, Collection) |
| 1115 | self.assertNotIsInstance(ColNoIter(), Collection) |
| 1116 | self.assertNotIsSubclass(ColNoSize, Collection) |
| 1117 | self.assertNotIsInstance(ColNoSize(), Collection) |
nothing calls this directly
no test coverage detected