incubator-heraldry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ket...@apache.org
Subject svn commit: r493346 - /incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py
Date Sat, 06 Jan 2007 05:23:39 GMT
Author: keturn
Date: Fri Jan  5 21:23:38 2007
New Revision: 493346

URL: http://svn.apache.org/viewvc?view=rev&rev=493346
Log:
[python-to-heraldry @ Transform the XRI tests so that they run independently]
(meaning neutral)

Original author: Josh Hoyt <josh@janrain.com>
Date: 2006-12-20 23:30:00+00:00

Modified:
    incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py

Modified: incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py
URL: http://svn.apache.org/viewvc/incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py?view=diff&rev=493346&r1=493345&r2=493346
==============================================================================
--- incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py (original)
+++ incubator/heraldry/libraries/python/openid/trunk/openid/test/test_xri.py Fri Jan  5 21:23:38
2007
@@ -1,4 +1,3 @@
-
 from unittest import TestCase
 from openid.yadis import xri
 
@@ -53,64 +52,49 @@
 
 
 class CanonicalIDTest(TestCase):
-    providerIsAuthoritativeCases = [
-        # provider, canonicalID, isAuthoritative
-        ('=', '=!698.74D1.A1F2.86C7', True),
-        ('@!1234', '@!1234!ABCD', True),
-        ('@!1234!5678', '@!1234!5678!ABCD', True),
-        ('@!1234', '=!1234!ABCD', False),
-        ('@!1234', '@!1234!ABCD!9765', False),
-        ('@!1234!ABCD', '=!1234', False),
-        ('=!BABE', '=!D00D', False),
-        ]
-
-
-    def test_providerIsAuthoritative(self):
-        """Checking whether this provider is authoratitve for
-        the given XRI."""
-        # XXX: Should perhaps be more like the other data-driven tests?
-        for providerID, canonicalID, isAuthoritative in \
-                self.providerIsAuthoritativeCases:
-            self._providerIsAuthoritative(providerID, canonicalID,
-                                          isAuthoritative)
-
-
-    def _providerIsAuthoritative(self, providerID, canonicalID, expected):
-        result = xri.providerIsAuthoritative(providerID, canonicalID)
-        self.failUnlessEqual(expected, result,
-                             "%s providing %s, expected %s" % (providerID,
-                                                               canonicalID,
-                                                               expected))
-
-
+    def mkTest(providerID, canonicalID, isAuthoritative):
+        def test(self):
+            result = xri.providerIsAuthoritative(providerID, canonicalID)
+            format = "%s providing %s, expected %s"
+            message = format % (providerID, canonicalID, isAuthoritative)
+            self.failUnlessEqual(isAuthoritative, result, message)
+
+        return test
+
+    test_equals = mkTest('=', '=!698.74D1.A1F2.86C7', True)
+    test_atOne = mkTest('@!1234', '@!1234!ABCD', True)
+    test_atTwo = mkTest('@!1234!5678', '@!1234!5678!ABCD', True)
+
+    test_atEqualsFails = mkTest('@!1234', '=!1234!ABCD', False)
+    test_tooDeepFails = mkTest('@!1234', '@!1234!ABCD!9765', False)
+    test_atEqualsAndTooDeepFails = mkTest('@!1234!ABCD', '=!1234', False)
+    test_differentBeginningFails = mkTest('=!BABE', '=!D00D', False)
 
 class TestGetRootAuthority(TestCase):
-    xris = [
-        ("@foo", "@"),
-        ("@foo*bar", "@"),
-        ("@*foo*bar", "@"),
-        ("@foo/bar", "@"),
-        ("!!990!991", "!"),
-        ("!1001!02", "!"),
-        ("=foo*bar", "="),
-        ("(example.com)/foo", "(example.com)"),
-        ("(example.com)*bar/foo", "(example.com)"),
-        ("baz.example.com/foo", "baz.example.com"),
-        ("baz.example.com:8080/foo", "baz.example.com:8080"),
-        # Looking at the ABNF in XRI Syntax 2.0, I don't think you can
-        # have example.com*bar.  You can do (example.com)*bar, but that
-        # would mean something else.
-        ##("example.com*bar/(=baz)", "example.com*bar"),
-        ##("baz.example.com!01/foo", "baz.example.com!01"),
-        ]
-
-
-    def test_getRootAuthority(self):
-        for thexri, expected_root in self.xris:
-            self.failUnlessEqual(xri.rootAuthority(thexri),
-                                 xri.XRI(expected_root))
-
-
+    def mkTest(the_xri, expected_root):
+        def test(self):
+            actual_root = xri.rootAuthority(the_xri)
+            self.failUnlessEqual(actual_root, xri.XRI(expected_root))
+        return test
+
+    test_at = mkTest("@foo", "@")
+    test_atStar = mkTest("@foo*bar", "@")
+    test_atStarStar = mkTest("@*foo*bar", "@")
+    test_atWithPath = mkTest("@foo/bar", "@")
+    test_bangBang = mkTest("!!990!991", "!")
+    test_bang = mkTest("!1001!02", "!")
+    test_equalsStar = mkTest("=foo*bar", "=")
+    test_xrefPath = mkTest("(example.com)/foo", "(example.com)")
+    test_xrefStar = mkTest("(example.com)*bar/foo", "(example.com)")
+    test_uriAuth = mkTest("baz.example.com/foo", "baz.example.com")
+    test_uriAuthPort = mkTest("baz.example.com:8080/foo",
+                              "baz.example.com:8080")
+
+    # Looking at the ABNF in XRI Syntax 2.0, I don't think you can
+    # have example.com*bar.  You can do (example.com)*bar, but that
+    # would mean something else.
+    ##("example.com*bar/(=baz)", "example.com*bar"),
+    ##("baz.example.com!01/foo", "baz.example.com!01"),
 
 if __name__ == '__main__':
     import unittest



Mime
View raw message