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

Fred L. Drake, Jr. fred@zope.com
Wed, 4 Jun 2003 14:09:08 -0400


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

Modified Files:
	test_vocabulary.py 
Log Message:
Refactored the SimpleVocabulary constructors to allow creating instances from
a sequence of terms.  Better support for specializing the vocabulary by
moving term creation to a new class method.


=== Zope3/src/zope/schema/tests/test_vocabulary.py 1.8 => 1.9 ===
--- Zope3/src/zope/schema/tests/test_vocabulary.py:1.8	Wed Jun  4 11:10:37 2003
+++ Zope3/src/zope/schema/tests/test_vocabulary.py	Wed Jun  4 14:09:07 2003
@@ -130,7 +130,7 @@
 
 class SimpleVocabularyTests(unittest.TestCase):
 
-    list_vocab = vocabulary.SimpleVocabulary([1, 2, 3])
+    list_vocab = vocabulary.SimpleVocabulary.fromValues([1, 2, 3])
     items_vocab = vocabulary.SimpleVocabulary.fromItems(
         [('one', 1), ('two', 2), ('three', 3), ('fore!', 4)])
 
@@ -166,7 +166,7 @@
     def test_addt_interfaces(self):
         class IStupid(Interface):
             pass
-        v = vocabulary.SimpleVocabulary([1, 2, 3], IStupid)
+        v = vocabulary.SimpleVocabulary.fromValues([1, 2, 3], IStupid)
         self.failUnless(IStupid.isImplementedBy(v))
 
     def test_len(self):
@@ -189,10 +189,27 @@
 
     def test_nonunique_tokens(self):
         self.assertRaises(
-            AssertionError, vocabulary.SimpleVocabulary, [2, '2'])
+            AssertionError, vocabulary.SimpleVocabulary.fromValues,
+            [2, '2'])
         self.assertRaises(
             AssertionError, vocabulary.SimpleVocabulary.fromItems, 
             [(1, 'one'), ('1', 'another one')])
+
+    def test_overriding_createTerm(self):
+        class MyTerm:
+            def __init__(self, value):
+                self.value = value
+                self.token = repr(value)
+                self.nextvalue = value + 1
+
+        class MyVocabulary(vocabulary.SimpleVocabulary):
+            def createTerm(cls, value):
+                return MyTerm(value)
+            createTerm = classmethod(createTerm)
+
+        vocab = MyVocabulary.fromValues([1, 2, 3])
+        for term in vocab:
+            self.assertEqual(term.value + 1, term.nextvalue)
 
 
 def test_suite():