[Dev] repository unit tests review

Andi Vajda vajda at osafoundation.org
Sun Jan 4 17:27:08 PST 2004


Disclaimer: Ted asked me to review the repository unit tests he wrote and to
            post my comments to the dev list.

Andi..

Besides adding some spaces after the ',' characters which didn't have any
and re-indenting some wrapping lines, most changes have to do with the fact
that I made _reopenRepository() also re-instantiate self.rep, ensuring that
the previously loaded items are now bogus.

I also changed a bunch of '==' tests to 'is' tests since that's what we're
looking for.

Index: RepositoryTestCase.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/RepositoryTestCase.py,v
retrieving revision 1.1
diff -w -u -r1.1 RepositoryTestCase.py
--- RepositoryTestCase.py	22 Dec 2003 18:33:46 -0000	1.1
+++ RepositoryTestCase.py	4 Jan 2004 23:26:38 -0000
@@ -30,6 +30,7 @@
     def _reopenRepository(self):
         self.rep.commit()
         self.rep.close()
+        self.rep = XMLRepository(os.path.join(self.testdir, '__repository__'))
         self.rep.open()

     # Repository specific assertions


It is a better test to re-instantiate the repository after closing it. That
way you'll never endup using old item references from the previous session
and are really validating that what you saved is also what you expect to
reload. That causes several problems I fixed in TestItems.py below.


Index: TestItems.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestItems.py,v
retrieving revision 1.4
diff -w -u -r1.4 TestItems.py
--- TestItems.py	31 Dec 2003 02:09:40 -0000	1.4
+++ TestItems.py	4 Jan 2004 23:28:57 -0000
@@ -19,14 +19,14 @@
     def testItemParentChild(self):
         """Test basic attribute functionality, focusing on parent-child relationships"""
         # Test find()

You probably intended to create a regular item of kind Item not of kind Kind.

-        kind = self.rep.find('//Schema/Core/Kind')
+        kind = self.rep.find('//Schema/Core/Item')
         self.assert_(kind is not None)

         # Test getItemDisplayName
-        self.assertEquals(kind.getItemDisplayName(), 'Kind')
+        self.assertEquals(kind.getItemDisplayName(), 'Item')

         # Test getItemPath()
-        self.assertEquals(str(kind.getItemPath()),'//Schema/Core/Kind')
+        self.assertEquals(str(kind.getItemPath()), '//Schema/Core/Item')

         # Test simple item construction
         item = Item('test', self.rep, kind)
@@ -41,7 +41,8 @@
         self.assert_(item.isDirty())
         self.failIf(item.isDeleted())
         self.failIf(item.isStale())

The object returned by Item.getRepository() is the repository's view. Yes,
the API is a little confusing here, it should be called getRepositoryView().

-#TODO repo equality        self.assertEquals(self.rep, item.getRepository())
+        self.assertEquals(self.rep.view, item.getRepository())
+

 #TODO test toXML
         xml = item.toXML()
         self.assert_(xml is not None)
@@ -67,7 +68,9 @@
         self.assertEquals(child2.getItemDisplayName(),'child2')
         self.assertItemPathEqual(child2,'//test/child2')
         self.assert_(item.hasChildren())
+        self.assert_(item.hasChild('child1'))
         self.assert_(item.hasChild('child2'))
+
         item.placeChild(child2, child1)
         self.assert_(item.hasChild('child2'))
         self.failIf(item.isNew())
@@ -83,16 +86,18 @@
         self.assertEqual(item.getItemChild('child1'), iter.next())
         self.assertEqual(item.getItemChild('child2'), iter.next())

+# TODO  self.failUnlessRaises(StopIteration, iter.next())
+

After each call to self._reopenRepository(), all previous item objects are
no good anymore and need to be reloaded. A bug: closing a repository should
stale all its loaded items.

         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//test')
+        child1 = item['child1']
+        child2 = item['child2']
         self.assertIsRoot(item)
         self.assert_(item.hasChildren())
         self.assert_(item.hasChild('child1'))
         self.assert_(item.hasChild('child2'))

-#TODO        self.failUnlessRaises(StopIteration, iter.next())
-
         # Test item renaming, getItemName
         child3 = Item('busted', item, kind)
         self.assertEqual(child3.getItemName(), 'busted')

Same thing, reload all items used by the test.

@@ -125,6 +130,10 @@
         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//test')
+        child1 = item['child1']
+        child2 = item['child2']
+        child3 = child2['child3']
+
         self.assertEqual(child2,child3.getItemParent())
         self.assertItemPathEqual(child3,'//test/child2/child3')
         self.assertIsRoot(child3.getRoot())

Same thing, reload all items used by the test.

@@ -138,12 +147,15 @@
         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//test')
+        child1 = item['child1']
+        child2 = item['child2']
+        child3 = child2['child3']
+
         child3.move(self.rep)
         self.assert_(child3 in self.rep.getRoots())
         self.assertItemPathEqual(child3,'//child3')
         self.assertIsRoot(child3.getRoot())

-
     def testAttributeIteration(self):
         """Test iteration over attributes"""
         kind = self.rep.find('//Schema/Core/Kind')

I replaced calls to issubclass() with calls to isinstance().

@@ -159,10 +171,12 @@
             self.failUnless(kind.hasAttributeValue(i))

         # Test iterating over reference attributes
-        referenceAttributeNames = ['superKinds','attributes','kind','inheritedAttributes','items']
+        referenceAttributeNames = ['superKinds', 'attributes', 'kind',
+                                   'inheritedAttributes', 'items']
         for i in kind.iterAttributes(referencesOnly=True):
             self.failUnless(i[0] in referenceAttributeNames)
-            self.failUnless(issubclass(type(i[1]),RefDict) or type(i[1] == Kind)) #TODO is the Kind check right?
+            self.failUnless(isinstance(i[1], RefDict) or
+                            isinstance(i[1], Kind))

 if __name__ == "__main__":
 #    import hotshot
Index: TestKinds.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestKinds.py,v
retrieving revision 1.1
diff -w -u -r1.1 TestKinds.py
--- TestKinds.py	31 Dec 2003 02:17:50 -0000	1.1
+++ TestKinds.py	4 Jan 2004 23:49:48 -0000
@@ -17,7 +17,7 @@
     """ Test Kinds  """

toXML is not broken for kinds so I removed the comment.

     def testToXML(self):
-        """ toXML on kinds is broken """
+
         kind = self.rep.find('//Schema/Core/Kind')
         xml = kind.toXML()
         self.failIf(xml is None)


Index: TestLiteralAttributes.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestLiteralAttributes.py,v
retrieving revision 1.4
diff -w -u -r1.4 TestLiteralAttributes.py
--- TestLiteralAttributes.py	31 Dec 2003 02:09:40 -0000	1.4
+++ TestLiteralAttributes.py	5 Jan 2004 00:19:44 -0000


I renamed item1 to kind1 and item2 to item1 since that's what they are and
it is less confusing that way.


@@ -22,35 +22,35 @@
         itemKind = self.rep.find('//Schema/Core/Item')
         self.assert_(itemKind is not None)

-        item1 = Item('item1', self.rep, kind)
-        self.assert_(item1 is not None)
+        kind1 = Item('kind1', self.rep, kind)
+        self.assert_(kind1 is not None)

-        item2 = Item('item2', self.rep, itemKind)
-        self.assert_(item2 is not None)
+        item1 = Item('item1', self.rep, itemKind)
+        self.assert_(item1 is not None)

         #Test hasAttributeAspect and getAttributeAspect
-        self.assert_(item1.hasAttributeAspect('attributes','cardinality') and
-                     item1.getAttributeAspect('attributes','cardinality') == 'list')
+        self.assert_(kind1.hasAttributeAspect('attributes','cardinality') and
+                     kind1.getAttributeAspect('attributes','cardinality') == 'list')

-        self.assert_(item1.hasAttributeAspect('superKinds','cardinality') and
-                     item1.getAttributeAspect('superKinds','cardinality') == 'list')
+        self.assert_(kind1.hasAttributeAspect('superKinds','cardinality') and
+                     kind1.getAttributeAspect('superKinds','cardinality') == 'list')

-        self.assert_(item1.hasAttributeAspect('classes','cardinality') and
-                     item1.getAttributeAspect('classes','cardinality') == 'dict')
+        self.assert_(kind1.hasAttributeAspect('classes','cardinality') and
+                     kind1.getAttributeAspect('classes','cardinality') == 'dict')

-        self.assert_(item1.hasAttributeAspect('notFoundAttributes','persist') and
-                     item1.getAttributeAspect('notFoundAttributes','persist') == False)
+        self.assert_(kind1.hasAttributeAspect('notFoundAttributes','persist') and
+                     kind1.getAttributeAspect('notFoundAttributes','persist') == False)

         # up to here displayName is an unset Chandler attribute
-        self.failUnlessRaises(AttributeError, lambda x: item2.displayName, None)
+        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
         # now set the attribute
-        item2.setAttributeValue('displayName','myName')
-        self.assertEquals(item2.displayName,'myName')
+        item1.setAttributeValue('displayName', 'myName')
+        self.assertEquals(item1.displayName, 'myName')
         #test __getattr__ and getAttributeValue() access
-        self.assertEquals(item2.displayName,item2.getAttributeValue('displayName'))
+        self.assertEquals(item1.displayName, item1.getAttributeValue('displayName'))

It seems the lambda body below didn't need the extra argument.

         # now remove attribute value
-        item2.removeAttributeValue('displayName')
-        self.failUnlessRaises(AttributeError, lambda x: item2.displayName, None)
+        item1.removeAttributeValue('displayName')
+        self.failUnlessRaises(AttributeError, lambda: item1.displayName)
         #TODO need a test for list valued literal attribute

         # test dict valued literal attribute
@@ -96,7 +96,7 @@
         # create an attribute with cardinality list and add to the kind
         attrKind = itemKind.getAttribute('kind').kind
         multiAttribute = Attribute('strings', myKind, attrKind)
-        multiAttribute.setAttributeValue('cardinality','list')
+        multiAttribute.cardinality = 'list'
         myKind.addValue('attributes', multiAttribute)

         # create an item of the new kind
@@ -109,6 +109,10 @@
         item.addValue('strings','Goofy')
         verifyItem(item)

I added the four lines below to also test regular python collection syntax.

+        # again set the list attribute
+        item.strings = [ 'Mickey', 'Minnie', 'Donald', 'Goofy' ]
+        verifyItem(item)
+
         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//item')
@@ -119,12 +123,15 @@
         item.removeValue('strings',0)
         self.failIf(item.hasValue('strings','Mickey'))
         self.assertEquals(len(item.strings),3)
-        item.removeValue('strings',2)

I changed a couple of remove calls into del calls to test regular python syntax

+
+        del item.strings[2]
         self.failIf(item.hasValue('strings','Goofy'))
         self.assertEquals(len(item.strings),2)
-        item.removeValue('strings',1)
+
+        del item.strings[1]
         self.failIf(item.hasValue('strings','Donald'))
         self.assertEquals(len(item.strings),1)
+
         item.removeValue('strings',0)
         self.failIf(item.hasValue('strings','Minnie'))
         self.assertEquals(len(item.strings),0)
@@ -177,7 +184,7 @@
         # create an attribute with cardinality dict and add to the kind
         attrKind = itemKind.getAttribute('kind').kind
         multiAttribute = Attribute('strings', myKind, attrKind)
-        multiAttribute.setAttributeValue('cardinality','dict')
+        multiAttribute.cardinality = 'dict'
         myKind.addValue('attributes', multiAttribute)

         # create an item of the new kind
@@ -188,22 +195,30 @@
         item.addValue('strings','Dog','Goofy')
         verifyItem(item)

I added the five lines below to also test regular python collection syntax.

+        # set the strings attribute again
+        item.strings = { 'Mickey': 'Mouse', 'Minnie': 'Mouse',
+                         'Donald': 'Duck', 'Goofy': 'Dog' }
+        verifyItem(item)
+
         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//item')
         verifyItem(item)

         #test removeValue by removing values and checking
-        #that value is removed and length has decrease
+        #that value is removed and length has decreased
         item.removeValue('strings','Mickey')
         self.assert_(item.hasValue('strings','Mouse'))
         self.assertEquals(len(item.strings),3)

I changed a couple of remove calls into del calls to test regular python syntax

-        item.removeValue('strings','Goofy')
+
+        del item.strings['Goofy']
         self.failIf(item.hasValue('strings','Dog'))
         self.assertEquals(len(item.strings),2)
-        item.removeValue('strings','Donald')
+
+        del item.strings['Donald']
         self.failIf(item.hasValue('strings','Duck'))
         self.assertEquals(len(item.strings),1)
+
         item.removeValue('strings','Minnie')
         self.failIf(item.hasValue('strings','Mouse'))
         self.assertEquals(len(item.strings),0)
@@ -211,6 +226,10 @@
         # now write what we've done and read it back
         self._reopenRepository()
         item = self.rep.find('//item')
+        self.failIf('Mickey' in item.strings)
+        self.failIf('Minnie' in item.strings)
+        self.failIf('Goofy' in item.strings)
+        self.failIf('Donald' in item.strings)
         self.failIf(item.hasValue('strings','Dog'))
         self.failIf(item.hasValue('strings','Duck'))
         self.failIf(item.hasValue('strings','Mouse'))

Index: TestPersistentCollections.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestPersistentCollections.py,v
retrieving revision 1.2
diff -w -u -r1.2 TestPersistentCollections.py
--- TestPersistentCollections.py	31 Dec 2003 20:50:02 -0000	1.2
+++ TestPersistentCollections.py	5 Jan 2004 00:34:53 -0000
@@ -10,6 +10,8 @@
 import RepositoryTestCase, os, unittest

 from repository.schema.Attribute import Attribute
+from repository.util.Path import Path
+

 class PersistentCollectionsTest(RepositoryTestCase.RepositoryTestCase):
     """Test Persistent Collection"""
@@ -21,13 +23,13 @@
     def _checkManagerAndEmployeesList(self, m, es):
         """Make sure a list of employees has the same manager"""
         for i in es:

I changed the assertEquals calls into asserts since assertEquals() checks
that two objects are equals using == (value compare) not 'is' (pointer
compare) which is what we actually want.

-            self.assertEquals(i.manager, m)
+            self.assert_(i.manager is m)
             self.assert_(m.hasValue('employees', i))

     def _checkManagerAndEmployeesDict(self, m, es):
         """Make sure a list of employees has the same manager"""
         for k,v in es.items():
-            self.assertEquals(v.manager, m)
+            self.assert_(v.manager is m)
             self.assert_(m.hasValue('employees', v))


I changed a bunch of item.setAttributeValue('foo', 'bar') calls into the
more succint item.foo = 'bar' variant.

@@ -39,13 +41,13 @@

         managerKind = kind.newItem('manager', self.rep)
         employeesAttribute = Attribute('employees',managerKind, attrKind)
-        employeesAttribute.setAttributeValue('cardinality','list')
-        employeesAttribute.setAttributeValue('otherName', 'manager')
+        employeesAttribute.cardinality = 'list'
+        employeesAttribute.otherName = 'manager'
         managerKind.addValue('attributes',
                              employeesAttribute,alias='employees')
         employeeKind = kind.newItem('employee', self.rep)
         managerAttribute = Attribute('manager',employeeKind, attrKind)
-        managerAttribute.setAttributeValue('otherName', 'employees')
+        managerAttribute.otherName = 'employees'
         employeeKind.addValue('attributes',
                               managerAttribute,alias='manager')

@@ -64,7 +66,7 @@
         manager = self.rep.find("//boss")
         emps = []
         for i in empNames:

Changed to test finding by constructing Path directly (more efficient too).

-            emps.append(self.rep.find("//%s" % i))
+            emps.append(self.rep.find(Path('//', i)))
         self._checkManagerAndEmployeesList(manager, emps)


@@ -76,13 +78,13 @@

         managerKind = kind.newItem('manager', self.rep)
         employeesAttribute = Attribute('employees',managerKind, attrKind)
-        employeesAttribute.setAttributeValue('cardinality','dict')
-        employeesAttribute.setAttributeValue('otherName', 'manager')
+        employeesAttribute.cardinality = 'list'
+        employeesAttribute.otherName = 'manager'
         managerKind.addValue('attributes',
                              employeesAttribute,alias='employees')
         employeeKind = kind.newItem('employee', self.rep)
         managerAttribute = Attribute('manager',employeeKind, attrKind)
-        managerAttribute.setAttributeValue('otherName', 'employees')
+        managerAttribute.otherName = 'employees'
         employeeKind.addValue('attributes',
                               managerAttribute,alias='manager')

@@ -101,7 +103,7 @@
         manager = self.rep.find('//boss')
         emps = {}
         for e in empNames:

Changed to test finding by constructing Path directly (more efficient too).

-            emp = self.rep.find('//%s' % e)
+            emp = self.rep.find(Path('//', e))
             emps[str(emp.getUUID())] = emp
         self._checkManagerAndEmployeesDict(manager,emps)


Index: TestReferenceAttributes.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestReferenceAttributes.py,v
retrieving revision 1.6
diff -w -u -r1.6 TestReferenceAttributes.py
--- TestReferenceAttributes.py	31 Dec 2003 02:09:40 -0000	1.6
+++ TestReferenceAttributes.py	5 Jan 2004 01:11:38 -0000
@@ -16,79 +16,87 @@
     """ Test Reference Attributes """

     def testReferenceAttributes(self):
-        """Test bidirectional single valued attrribute"""
+        """Test bidirectional single valued attribute"""
         kind = self.rep.find('//Schema/Core/Kind')
         itemKind = self.rep.find('//Schema/Core/Item')
         self.assert_(itemKind is not None)

I renamed item1 -> kind1 and item2,3 -> item1,2 since that's what they are
and it is less confusing that way.

-        item1 = Item('item1', self.rep, kind)
-        self.assert_(item1 is not None)
+        kind1 = Item('kind1', self.rep, kind)
+        self.assert_(kind1 is not None)

-        item2 = Item('item2', self.rep, itemKind)
-        self.assert_(item2 is not None)
+        item1 = Item('item1', self.rep, itemKind)
+        self.assert_(item1 is not None)

I changed a bunch of assertEquals() to assert_ in order to use 'is' instead
of '=='.

         # check kind
-        self.assertEquals(item1.kind, kind)
-        self.assert_(item1 in kind.items)
+        self.assert_(kind1.kind is kind)
+        self.assert_(kind1 in kind.items)

         # check kind and otherName
-        self.assertEquals(item2.kind, itemKind)
-        self.assert_(item2 in itemKind.items)
+        self.assert_(item1.kind is itemKind)
+        self.assert_(item1 in itemKind.items)
+

I changed a bunch of setAttributeValue calls to use . = instead.

         # set kind Attribute (update bidirectional ref)
-        item2.setAttributeValue('kind', item1)
-        self.assertEquals(item2.kind, item1)
-        # now test that  otherName side of kind now = items of item1
-        self.assert_(item2 in item1.items)
-        # and verify item2 no longer in kind.items (old otherName)
-        self.assert_(item2 not in kind.items)
+        item1.kind = kind1
+        self.assert_(item1.kind is kind1)
+
+        # now test that  otherName side of kind now = items of kind1
+        self.assert_(item1 in kind1.items)
+        # and verify item1 no longer in kind.items (old otherName)
+        self.assert_(item1 not in kind.items)

         # create a third item and switch kind using __setattr__
-        item3 = Item('item3', self.rep, itemKind)
-        self.assert_(item3 is not None)
-        item3.kind = item1
+        item2 = Item('item2', self.rep, itemKind)
+        self.assert_(item2 is not None)
+        item2.kind = kind1
+
         # again, verify kind
-        self.assertEquals(item3.kind, item1)
+        self.assert_(item2.kind is kind1)
+
         # now verify that otherName side of kind is list cardinality
-        self.assertEquals(len(item1.items), 2)
-        self.assert_(item2 in item1.items)
-        self.assert_(item3 in item1.items)
+        self.assertEquals(len(kind1.items), 2)
+        self.assert_(item1 in kind1.items)
+        self.assert_(item2 in kind1.items)

         # now write what we've done and read it back
         self._reopenRepository()
         kind = self.rep.find('//Schema/Core/Kind')
         itemKind = self.rep.find('//Schema/Core/Item')
+        kind1 = self.rep.find('//kind1')
         item1 = self.rep.find('//item1')
         item2 = self.rep.find('//item2')
-        item3 = self.rep.find('//item3')
+
         # check kind
-        self.assertEquals(item1.kind, kind)
-        self.assert_(item1 in kind.items)
+        self.assert_(kind1.kind is kind)
+        self.assert_(kind1 in kind.items)
+
         # set kind Attribute (update bidirectional ref)
-        self.assertEquals(item2.kind, item1)
-        # now test that  otherName side of kind now = items of item1
-        self.assert_(item2 in item1.items)
-        # and verify item2 no longer in kind.items (old otherName)
-        self.assert_(item2 not in kind.items)
+        self.assert_(item1.kind is kind1)
+
+        # now test that otherName side of kind now = items of kind1
+        self.assert_(item1 in kind1.items)
+        # and verify item1 no longer in kind.items (old otherName)
+        self.assert_(item1 not in kind.items)
         # again, verify kind
-        self.assertEquals(item3.kind, item1)
+        self.assert_(item2.kind is kind1)
+
         # now verify that otherName side of kind is list cardinality
-        self.assertEquals(len(item1.items), 2)
-        self.assert_(item2 in item1.items)
-        self.assert_(item3 in item1.items)
+        self.assertEquals(len(kind1.items), 2)
+        self.assert_(item1 in kind1.items)
+        self.assert_(item2 in kind1.items)

         # test removeAttributeValue
-        item3.removeAttributeValue('kind')
-        self.failUnlessRaises(AttributeError, lambda x: item3.kind, None)
-        self.assertEquals(len(item1.items),1)
-        self.failIf(item3 in item1.items)

I removed the unused None argument to lambda.

+        item2.removeAttributeValue('kind')
+        self.failUnlessRaises(AttributeError, lambda: item2.kind)
+        self.assertEquals(len(kind1.items), 1)
+        self.failIf(item2 in kind1.items)

         # now write what we've done and read it back
         self._reopenRepository()
-        item1 = self.rep.find('//item1')
-        item3 = self.rep.find('//item3')
-        self.failUnlessRaises(AttributeError, lambda x: item3.kind, None)
-        self.assertEquals(len(item1.items),1)
-        self.failIf(item3 in item1.items)
+        kind1 = self.rep.find('//kind1')
+        item2 = self.rep.find('//item2')
+        self.failUnlessRaises(AttributeError, lambda: item2.kind)
+        self.assertEquals(len(kind1.items), 1)
+        self.failIf(item2 in kind1.items)

     # support functions for testListReferenceAttributes and testDictReferenceAttributes
     def _findManagerAndEmployees(self):
@@ -114,13 +122,13 @@

         managerKind = kind.newItem('manager', self.rep)
         employeesAttribute = Attribute('employees',managerKind, attrKind)
-        employeesAttribute.setAttributeValue('cardinality','list')
-        employeesAttribute.setAttributeValue('otherName', 'manager')
+        employeesAttribute.cardinality = 'list'
+        employeesAttribute.otherName = 'manager'
         managerKind.addValue('attributes',
                              employeesAttribute,alias='employees')
         employeeKind = kind.newItem('employee', self.rep)
         managerAttribute = Attribute('manager',employeeKind, attrKind)
-        managerAttribute.setAttributeValue('otherName', 'employees')
+        managerAttribute.otherName = 'employees'
         employeeKind.addValue('attributes',
                               managerAttribute,alias='manager')

@@ -130,7 +138,8 @@
         employeesAttribute = managerKind.getAttribute('employees')
         self.assert_(employeesAttribute is not None)
         self.assertEquals(employeesAttribute.cardinality,'list')
-        self.assertEquals(employeesAttribute.getAttributeValue('otherName'),'manager')
+        self.assertEquals(employeesAttribute.getAttributeValue('otherName'),
+                          'manager')
         employeeKind = self.rep.find('//employee')
         managerAttribute = employeeKind.getAttribute('manager')
         self.assert_(managerAttribute is not None)
@@ -180,13 +189,13 @@

I changed the 'dict' cardinality to 'list' as it is the only one supported
by ref collections.

         managerKind = kind.newItem('manager', self.rep)
         employeesAttribute = Attribute('employees',managerKind, attrKind)
-        employeesAttribute.setAttributeValue('cardinality','dict')
-        employeesAttribute.setAttributeValue('otherName', 'manager')
+        employeesAttribute.cardinality = 'list'
+        employeesAttribute.otherName = 'manager'
         managerKind.addValue('attributes',
                              employeesAttribute,alias='employees')
         employeeKind = kind.newItem('employee', self.rep)
         managerAttribute = Attribute('manager',employeeKind, attrKind)
-        managerAttribute.setAttributeValue('otherName', 'employees')
+        managerAttribute.otherName = 'employees'
         employeeKind.addValue('attributes',
                               managerAttribute,alias='manager')

@@ -195,8 +204,9 @@
         managerKind = self.rep.find('//manager')
         employeesAttribute = managerKind.getAttribute('employees')
         self.assert_(employeesAttribute is not None)
-        self.assertEquals(employeesAttribute.cardinality,'dict')
-        self.assertEquals(employeesAttribute.getAttributeValue('otherName'),'manager')
+        self.assertEquals(employeesAttribute.cardinality, 'list')
+        self.assertEquals(employeesAttribute.getAttributeValue('otherName'),
+                          'manager')
         employeeKind = self.rep.find('//employee')
         managerAttribute = employeeKind.getAttribute('manager')
         self.assert_(managerAttribute is not None)
@@ -252,20 +262,20 @@
         issuesAttr = itemKind.getAttribute('issues')
         criticalSubAttr = Attribute('critical', issuesAttr, attrKind)
         criticalSubAttr.superAttribute = issuesAttr
-        self.assert_(criticalSubAttr.superAttribute == issuesAttr)
+        self.assert_(criticalSubAttr.superAttribute is issuesAttr)
         self.assert_(criticalSubAttr in issuesAttr.subAttributes)

         # now do it by assigning to the subAttributes list to ensure that
         # the bidirectional ref is getting updated.
         normalSubAttr = Attribute('normal', issuesAttr, attrKind)
         issuesAttr.subAttributes.append(normalSubAttr)
-        self.assert_(normalSubAttr.superAttribute == issuesAttr)
+        self.assert_(normalSubAttr.superAttribute is issuesAttr)
         self.assert_(normalSubAttr in issuesAttr.subAttributes)

         # now do it by callin addValue on the Attribute item
         minorSubAttr = Attribute('minor', issuesAttr, attrKind)
         issuesAttr.addValue('subAttributes',minorSubAttr)
-        self.assert_(minorSubAttr.superAttribute == issuesAttr)
+        self.assert_(minorSubAttr.superAttribute is issuesAttr)
         self.assert_(minorSubAttr in issuesAttr.subAttributes)

         # now write what we've done and read it back
@@ -281,11 +291,11 @@
         criticalSubAttr = attMap['critical']
         normalSubAttr = attMap['normal']
         minorSubAttr = attMap['minor']

Changed a bunch of '==' tests into 'is' tests.

-        self.assert_(criticalSubAttr.superAttribute == issuesAttr)
+        self.assert_(criticalSubAttr.superAttribute is issuesAttr)
         self.assert_(criticalSubAttr in issuesAttr.subAttributes)
-        self.assert_(normalSubAttr.superAttribute == issuesAttr)
+        self.assert_(normalSubAttr.superAttribute is issuesAttr)
         self.assert_(normalSubAttr in issuesAttr.subAttributes)
-        self.assert_(minorSubAttr.superAttribute == issuesAttr)
+        self.assert_(minorSubAttr.superAttribute is issuesAttr)
         self.assert_(minorSubAttr in issuesAttr.subAttributes)

 if __name__ == "__main__":


Index: TestRepository.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestRepository.py,v
retrieving revision 1.3
diff -w -u -r1.3 TestRepository.py
--- TestRepository.py	22 Dec 2003 18:33:46 -0000	1.3
+++ TestRepository.py	5 Jan 2004 01:20:23 -0000
@@ -30,18 +30,19 @@
         pass

     def testGetRoot(self):
+
         root = self.rep.getRoot('Packs')
         #TODO these should use UUID's
         self.assert_(root.getItemName() == 'Packs')

I added testing finding the root by treating the rep object as a dict.

+        root = self.rep['Packs']
+        self.assert_(root.getItemName() == 'Packs')
+

I changed the test below to NOT rely on the order of roots in the
repository which is random.


     def testGetRoots(self):
         """ Make sure the roots of the repository are correct"""
-        roots = self.rep.getRoots()
-        schema = roots[0]
-        packs = roots[1]
-        #TODO these should use UUID's
-        self.assert_(schema.getItemName() == 'Schema')
-        self.assert_(packs.getItemName() == 'Packs')
+
+        for root in self.rep.getRoots():
+            self.assert_(root.getItemName() in ['Schema', 'Packs'])

     def testWalk(self):
         def callme(self, path, x):
Index: TestRepositoryBasic.py
===================================================================
RCS file: /usr/local/cvsrep/osaf/chandler/Chandler/repository/tests/TestRepositoryBasic.py,v
retrieving revision 1.3
diff -w -u -r1.3 TestRepositoryBasic.py
--- TestRepositoryBasic.py	22 Dec 2003 18:33:46 -0000	1.3
+++ TestRepositoryBasic.py	5 Jan 2004 01:20:32 -0000
@@ -49,7 +49,8 @@
         """
         self.rep.create()
         self.assert_(self.rep.check())
-        schemaPack = os.path.join(self.rootdir, 'repository', 'packs', 'schema.pack')
+        schemaPack = os.path.join(self.rootdir, 'repository',
+                                  'packs', 'schema.pack')
         self.rep.loadPack(schemaPack)
         self.assert_(self.rep.check())




More information about the Dev mailing list