[Checkins] SVN: megrok.five/trunk/src/megrok/five/tests/ Unit test
for megrok.five.Container.
Philipp von Weitershausen
philikon at philikon.de
Thu Feb 15 10:05:47 EST 2007
Log message for revision 72598:
Unit test for megrok.five.Container.
Changed:
A megrok.five/trunk/src/megrok/five/tests/
A megrok.five/trunk/src/megrok/five/tests/__init__.py
A megrok.five/trunk/src/megrok/five/tests/test_container.py
-=-
Added: megrok.five/trunk/src/megrok/five/tests/__init__.py
===================================================================
--- megrok.five/trunk/src/megrok/five/tests/__init__.py 2007-02-15 13:38:22 UTC (rev 72597)
+++ megrok.five/trunk/src/megrok/five/tests/__init__.py 2007-02-15 15:05:46 UTC (rev 72598)
@@ -0,0 +1 @@
+# make this directory a package
Property changes on: megrok.five/trunk/src/megrok/five/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: megrok.five/trunk/src/megrok/five/tests/test_container.py
===================================================================
--- megrok.five/trunk/src/megrok/five/tests/test_container.py 2007-02-15 13:38:22 UTC (rev 72597)
+++ megrok.five/trunk/src/megrok/five/tests/test_container.py 2007-02-15 15:05:46 UTC (rev 72598)
@@ -0,0 +1,58 @@
+import unittest
+from zope.testing.doctest import DocTestSuite
+
+def test_container():
+ """
+ Let's make a container and add a few items. As you can see, we
+ can use the regular IContainer API (Python's mapping API):
+
+ >>> from megrok.five import Container, Model
+ >>> folder = Container()
+ >>> folder['garfield'] = Model('garfield')
+ >>> folder['john'] = Model('john')
+ >>> folder['odie'] = Model('odie')
+
+ The rest of the mapping API is also supported:
+
+ >>> sorted(folder) # test __iter__
+ ['garfield', 'john', 'odie']
+
+ >>> sorted(folder.keys())
+ ['garfield', 'john', 'odie']
+
+ >>> sorted(model.getId() for model in folder.values())
+ ['garfield', 'john', 'odie']
+
+ >>> sorted((name, model.getId()) for name, model in folder.items()) # doctest: +NORMALIZE_WHITESPACE
+ [('garfield', 'garfield'),
+ ('john', 'john'),
+ ('odie', 'odie')]
+
+ >>> 'garfield' in folder # test __contains__
+ True
+
+ >>> len(folder) # test __len__
+ 3
+
+ >>> folder.get('garfield') == folder['garfield']
+ True
+ >>> folder.get('not-there') is None
+ True
+ >>> folder.get('not-there', 'then take me')
+ 'then take me'
+
+ >>> del folder['odie'] # test __delitem__
+ >>> len(folder)
+ 2
+ >>> sorted(folder)
+ ['garfield', 'john']
+
+ """
+
+def test_suite():
+ return unittest.TestSuite([
+ DocTestSuite(),
+ ])
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: megrok.five/trunk/src/megrok/five/tests/test_container.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list