1. leapfrogdevelopment
  2. rstr

Commits

Brendan McCollam  committed 54701d1

Adding tests

  • Participants
  • Parent commits 2937b0f
  • Branches default

Comments (0)

Files changed (3)

File rstr/__init__.py

View file
  • Ignore whitespace
-from rstr_base import default_instance
+from rstr_base import Rstr
+from rstr_base import default_instance as _default_instance
 
-for alpha in default_instance._alphabets.keys():
-    globals()[alpha] = getattr(default_instance, alpha)
+rstr = _default_instance.rstr
+xeger = _default_instance.xeger
+
+#This allows convenience methods from rstr to be accessed at the package level.
+#Without requiring the user to instantiate an Rstr() object.
+for alpha in _default_instance._alphabets.keys():
+    globals()[alpha] = getattr(_default_instance, alpha)

File rstr/tests/__init__.py

View file
  • Ignore whitespace
 import unittest
 import test_rstr
 import test_xeger
+import test_package_level_access
 
 def suite():
     loader = unittest.TestLoader()
     suite = loader.loadTestsFromModule(test_rstr)
     suite.addTests(loader.loadTestsFromModule(test_xeger))
+    suite.addTests(loader.loadTestsFromModule(test_package_level_access))
     return suite

File rstr/tests/test_package_level_access.py

View file
  • Ignore whitespace
+import unittest
+import re
+
+import rstr
+
+class TestPackageLevelFunctions(unittest.TestCase):
+
+    def test_rstr(self):
+        assert re.match(r'^[ABC]+$', rstr.rstr('ABC'))
+
+    def test_xeger(self):
+        assert re.match(r'^foo[\d]{10}bar$', rstr.xeger('^foo[\d]{10}bar$'))
+
+    def test_convenience_function(self):
+        assert re.match(r'^[a-zA-Z]+$', rstr.letters())