]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Split AsGenericTest methods by types with and without customer as_generic implementat...
authorAndrew Hannigan <andrewhannigan@Andrews-MacBook-Pro.local>
Sun, 6 Dec 2020 19:24:42 +0000 (13:24 -0600)
committerAndrew Hannigan <andrewhannigan@Andrews-MacBook-Pro.local>
Sun, 6 Dec 2020 19:24:42 +0000 (13:24 -0600)
lib/sqlalchemy/sql/sqltypes.py
test/sql/test_types.py

index 45d4f0b7f1c24c75ef81e1dc52814dc31d9b8b0d..e2684d732c676df4b15328c61adf062df64d802b 100644 (file)
@@ -1982,6 +1982,9 @@ class Interval(Emulated, _AbstractInterval, TypeDecorator):
         self.second_precision = second_precision
         self.day_precision = day_precision
 
+    def __repr__(self):
+        return util.generic_repr(self)
+
     @property
     def python_type(self):
         return dt.timedelta
index 6fe413ab6176066da5696833cb0e730df096a49c..63ae6969ec7853a47677ecdd9966e5a6b157eb7a 100644 (file)
@@ -59,6 +59,7 @@ from sqlalchemy import Unicode
 from sqlalchemy import util
 from sqlalchemy import VARCHAR
 import sqlalchemy.dialects.mysql as mysql
+import sqlalchemy.dialects.oracle as oracle
 import sqlalchemy.dialects.postgresql as pg
 from sqlalchemy.engine import default
 from sqlalchemy.schema import AddConstraint
@@ -397,12 +398,23 @@ class AsGenericTest(fixtures.TestBase):
         (Enum("a", "b", "c"), Enum("a", "b", "c")),
         (pg.ENUM("a", "b", "c"), Enum("a", "b", "c")),
         (mysql.ENUM("a", "b", "c"), Enum("a", "b", "c")),
+        (pg.INTERVAL(precision=5), Interval(native=True, second_precision=5)),
+        (
+            oracle.INTERVAL(second_precision=5, day_precision=5),
+            Interval(native=True, day_precision=5, second_precision=5),
+        ),
     )
     def test_as_generic(self, t1, t2):
         assert repr(t1.as_generic()) == repr(t2)
 
-    @testing.combinations(*[(t,) for t in _all_types(omit_special_types=True)])
-    def test_as_generic_all_types(self, type_):
+    @testing.combinations(
+        *[
+            (t,)
+            for t in _all_types(omit_special_types=True)
+            if t._uses_as_generic_heuristic()
+        ]
+    )
+    def test_as_generic_all_types_heuristic(self, type_):
         if issubclass(type_, ARRAY):
             t1 = type_(String)
         else:
@@ -410,35 +422,31 @@ class AsGenericTest(fixtures.TestBase):
 
         try:
             gentype = t1.as_generic()
-        except NotImplementedError as e:
+        except NotImplementedError:
             pass
         else:
-            if t1.__class__._uses_as_generic_heuristic():
-                assert isinstance(t1, gentype.__class__)
+            assert isinstance(t1, gentype.__class__)
+            assert isinstance(gentype, TypeEngine)
 
+        gentype = t1.as_generic(allow_nulltype=True)
+        if not isinstance(gentype, types.NULLTYPE.__class__):
+            assert isinstance(t1, gentype.__class__)
             assert isinstance(gentype, TypeEngine)
 
-    @testing.combinations(*[(t,) for t in _all_types(omit_special_types=True)])
-    def test_as_generic_all_types_allow_nulltype(self, type_):
+    @testing.combinations(
+        *[
+            (t,)
+            for t in _all_types(omit_special_types=True)
+            if not t._uses_as_generic_heuristic()
+        ]
+    )
+    def test_as_generic_all_types_custom(self, type_):
         if issubclass(type_, ARRAY):
             t1 = type_(String)
         else:
             t1 = type_()
 
-        # The `allow_nulltype` argument may not be available in custom
-        # implementations of as_generic() which override the
-        # TypeEngine.as_generic heuristic.
-        if t1.__class__._uses_as_generic_heuristic():
-            gentype = t1.as_generic(allow_nulltype=True)
-        else:
-            gentype = t1.as_generic()
-
-        if isinstance(gentype, types.NULLTYPE.__class__):
-            return
-
-        if t1.__class__._uses_as_generic_heuristic():
-            assert isinstance(t1, gentype.__class__)
-
+        gentype = t1.as_generic()
         assert isinstance(gentype, TypeEngine)