Example #1
0
 def test_get(self):
     collection = BaseNamedCollection(ITEMS, NAMES)
     name = NAMES.keys()[0]
     uid = NAMES[name]
     assert collection.get(name) is not None
     assert collection.get(name) == collection[name]
     assert collection.get(name) is ITEMS.get(uid)
Example #2
0
 def test_contains(self):
     collection = BaseNamedCollection(ITEMS, NAMES)
     name = NAMES.keys()[0]
     uid = NAMES[name]  # noqa
     assert name in collection
     for namekey in NAMES.keys():
         assert namekey in collection
Example #3
0
 def test_iterkeys(self):
     """Test __iter__() and iterkeys()"""
     collection = BaseNamedCollection(ITEMS, NAMES)
     for name in collection.iterkeys():
         assert name in NAMES.keys()
         assert collection.get(name) in collection.itervalues()
         assert (name, collection.get(name)) in collection.iteritems()
Example #4
0
 def test_keys(self):
     collection = BaseNamedCollection(ITEMS, NAMES)
     for name in collection.keys():
         assert name in NAMES.keys()
         assert collection.get(name) in collection.values()
         ## symmetry in relationship to UID:
         assert collection.name_for(collection.uid_for(name)) is name
Example #5
0
 def test_setops(self):
     collection1 = BaseNamedCollection(ITEMS, NAMES)
     namemap = NAMES.copy()
     uid = str(uuid.uuid3(NS_PKG, 'item3'))
     namemap['item3'] = uid
     collection2 = BaseNamedCollection(ITEMS2, namemap)
     self.assertIsInstance(
         collection2.difference(collection1),
         BaseNamedCollection,
         )
     self.assertEqual(
         set((collection1 & collection2).keys()),
         set(collection1.keys())
         )
     self.assertEqual(
         set((collection2 | collection1).keys()),
         set(collection2.keys())
         )
     # sufficient test:
     self.assertEqual(
         set(collection2.keys()),
         set(namemap.keys())
         )
Example #6
0
 def test_construction(self):
     self.assertRaises(TypeError, BaseNamedCollection, ITEMS)
     # succeeds w/ names:
     collection = BaseNamedCollection(ITEMS, NAMES)  # noqa
     self.assertRaises(ValueError, BaseNamedCollection, ITEMS, None)
Example #7
0
 def test_interfaces(self):
     collection = BaseNamedCollection(ITEMS, NAMES)
     assert IItemCollection.providedBy(collection)
     assert ICollectionSetOperations.providedBy(collection)
     assert INamedItemCollection.providedBy(collection)
     assert not IUIDItemCollection.providedBy(collection)