[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_vocabulary.py:1.5

Casey Duncan casey@zope.com
Fri, 30 May 2003 17:46:48 -0400


Update of /cvs-repository/Zope3/src/zope/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv13986/tests

Modified Files:
	test_vocabulary.py 
Log Message:
Remove fromDict constructor of SimpleVocabulary in favor of fromItems
SimpleVocabs now respect order of values/items used in construction
Added docstrings
Added test for order


=== Zope3/src/zope/schema/tests/test_vocabulary.py 1.4 => 1.5 ===
--- Zope3/src/zope/schema/tests/test_vocabulary.py:1.4	Fri May 30 02:10:58 2003
+++ Zope3/src/zope/schema/tests/test_vocabulary.py	Fri May 30 17:46:47 2003
@@ -133,8 +133,8 @@
     
     def setUp(self):
         self.list_vocab = vocabulary.SimpleVocabulary([1, 2, 3])
-        self.dict_vocab = vocabulary.SimpleVocabulary.fromDict(
-            {'one': 1, 'two': 2, 'three': 3, 'fore!': 4})
+        self.items_vocab = vocabulary.SimpleVocabulary.fromItems(
+            [('one', 1), ('two', 2), ('three', 3), ('fore!', 4)])
     
     def test_simple_term(self):
         t = vocabulary.SimpleTerm(1)
@@ -145,14 +145,25 @@
         verifyObject(interfaces.ITokenizedTerm, t)
         self.assertEqual(t.value, 1)
         self.assertEqual(t.token, "One")
+        
+    def test_order(self):
+        value = 1
+        for t in self.list_vocab:
+            self.assertEqual(t.value, value)
+            value += 1
+            
+        value = 1
+        for t in self.items_vocab:
+            self.assertEqual(t.value, value)
+            value += 1
     
     def test_implementation(self):
         self.failUnless(verifyObject(interfaces.IVocabulary, self.list_vocab))
         self.failUnless(
             verifyObject(interfaces.IVocabularyTokenized, self.list_vocab))
-        self.failUnless(verifyObject(interfaces.IVocabulary, self.dict_vocab))
+        self.failUnless(verifyObject(interfaces.IVocabulary, self.items_vocab))
         self.failUnless(
-            verifyObject(interfaces.IVocabularyTokenized, self.dict_vocab))
+            verifyObject(interfaces.IVocabularyTokenized, self.items_vocab))
             
     def test_addt_interfaces(self):
         class IStupid(Interface):
@@ -162,10 +173,10 @@
     
     def test_len(self):
         self.assertEqual(len(self.list_vocab), 3)
-        self.assertEqual(len(self.dict_vocab), 4)
+        self.assertEqual(len(self.items_vocab), 4)
     
     def test_contains(self):
-        for v in (self.list_vocab, self.dict_vocab):
+        for v in (self.list_vocab, self.items_vocab):
             self.assert_(1 in v and 2 in v and 3 in v)
             self.assert_(5 not in v)
             
@@ -173,7 +184,7 @@
         self.assert_(self.list_vocab.getQuery() is None)
         
     def test_iter_and_get_term(self):
-        for v in (self.list_vocab, self.dict_vocab):
+        for v in (self.list_vocab, self.items_vocab):
             for term in v:
                 self.assert_(v.getTerm(term.value) is term)
                 self.assert_(v.getTermByToken(term.token) is term)
@@ -182,8 +193,8 @@
         self.assertRaises(
             AssertionError, vocabulary.SimpleVocabulary, [2, '2'])
         self.assertRaises(
-            AssertionError, vocabulary.SimpleVocabulary.fromDict, 
-            {1:'one', '1':'another one'})
+            AssertionError, vocabulary.SimpleVocabulary.fromItems, 
+            [(1, 'one'), ('1', 'another one')])
         
 
 def test_suite():