Philip Jenvey avatar Philip Jenvey committed 8e0aeec

cleanup test_processors, modeling the PEP 399 style

Comments (0)

Files changed (1)

test/engine/test_processors.py

-from test.lib.testing import eq_, assert_raises, assert_raises_message
-from test.lib import testing, fixtures
+from test.lib import fixtures
+from test.lib.testing import assert_raises_message
 
+from sqlalchemy import processors
 try:
-    from sqlalchemy.cprocessors import str_to_datetime as c_str_to_datetime, \
-                                    str_to_date as c_str_to_date, \
-                                    str_to_time as c_str_to_time
-    from sqlalchemy.processors import py_fallback
-    for key, value in py_fallback().items():
-        globals()["py_%s" % key] = value
-except:
-    from sqlalchemy.processors import str_to_datetime as py_str_to_datetime, \
-                                        str_to_date as py_str_to_date, \
-                                        str_to_time as py_str_to_time
+    from sqlalchemy import cprocessors
+except ImportError:
+    cprocessors = None
 
-class DateProcessorTest(fixtures.TestBase):
-    @testing.requires.cextensions
-    def test_c_date_no_string(self):
+class _DateProcessorTest(fixtures.TestBase):
+    def test_date_no_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse date string '2012' - value is not a string",
-            c_str_to_date, 2012
+            self.module.str_to_date, 2012
         )
 
-    def test_py_date_no_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse date string '2012' - value is not a string",
-            py_str_to_date, 2012
-        )
-
-    @testing.requires.cextensions
-    def test_c_datetime_no_string(self):
+    def test_datetime_no_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse datetime string '2012' - value is not a string",
-            c_str_to_datetime, 2012
+            self.module.str_to_datetime, 2012
         )
 
-    def test_py_datetime_no_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse datetime string '2012' - value is not a string",
-            py_str_to_datetime, 2012
-        )
-
-    @testing.requires.cextensions
-    def test_c_time_no_string(self):
+    def test_time_no_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse time string '2012' - value is not a string",
-            c_str_to_time, 2012
+            self.module.str_to_time, 2012
         )
 
-    def test_py_time_no_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse time string '2012' - value is not a string",
-            py_str_to_time, 2012
-        )
-
-    @testing.requires.cextensions
-    def test_c_date_invalid_string(self):
+    def test_date_invalid_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse date string: '5:a'",
-            c_str_to_date, "5:a"
+            self.module.str_to_date, "5:a"
         )
 
-    def test_py_date_invalid_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse date string: '5:a'",
-            py_str_to_date, "5:a"
-        )
-
-    @testing.requires.cextensions
-    def test_c_datetime_invalid_string(self):
+    def test_datetime_invalid_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse datetime string: '5:a'",
-            c_str_to_datetime, "5:a"
+            self.module.str_to_datetime, "5:a"
         )
 
-    def test_py_datetime_invalid_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse datetime string: '5:a'",
-            py_str_to_datetime, "5:a"
-        )
-
-    @testing.requires.cextensions
-    def test_c_time_invalid_string(self):
+    def test_time_invalid_string(self):
         assert_raises_message(
             ValueError,
             "Couldn't parse time string: '5:a'",
-            c_str_to_time, "5:a"
+            self.module.str_to_time, "5:a"
         )
 
-    def test_py_time_invalid_string(self):
-        assert_raises_message(
-            ValueError,
-            "Couldn't parse time string: '5:a'",
-            py_str_to_time, "5:a"
-        )
 
+class PyDateProcessorTest(_DateProcessorTest):
+    module = processors
 
+
+class CDateProcessorTest(_DateProcessorTest):
+    __requires__ = ('cextensions',)
+    module = cprocessors
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.