]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- support "fails_if" requirements as __requires__; so far this just skips, doesn't
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Nov 2012 19:30:18 +0000 (14:30 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Nov 2012 19:30:18 +0000 (14:30 -0500)
actually run the test
- add requirements for date/datetime/time capabilities
- remove test/sql/test_types->DateTest and create new tests in suite/test_types
- move the StringTest with the "no length create" test to the suite, though this is a
weird test

lib/sqlalchemy/testing/plugin/noseplugin.py
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py
test/sql/test_types.py

index 1651886b896ba8e0e4bf69411243c3a43af3096b..37f7b29f55577257c0f35f853def4b639ade767c 100644 (file)
@@ -348,7 +348,12 @@ class NoseSQLAlchemy(Plugin):
             test_suite.__name__ = cls.__name__
             for requirement in cls.__requires__:
                 check = getattr(config.requirements, requirement)
-                check(test_suite)()
+
+                if not check.enabled:
+                    raise SkipTest(
+                        "'%s' unsupported on DB implementation '%s'" % (
+                         cls.__name__, config.db.name)
+                        )
 
         if cls.__unsupported_on__:
             spec = exclusions.db_spec(*cls.__unsupported_on__)
index 163e0494708146fa60f995511b2db560c0fdf9da..d58538db91e317cc4d97e325c1426ebc585b027c 100644 (file)
@@ -178,6 +178,56 @@ class SuiteRequirements(Requirements):
         """
         return exclusions.open()
 
+
+    @property
+    def datetime(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects."""
+
+        return exclusions.open()
+
+    @property
+    def datetime_microseconds(self):
+        """target dialect supports representation of Python
+        datetime.datetime() with microsecond objects."""
+
+        return exclusions.open()
+
+    @property
+    def datetime_historic(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects with historic (pre 1970) values."""
+
+        return exclusions.closed()
+
+    @property
+    def date(self):
+        """target dialect supports representation of Python
+        datetime.date() objects."""
+
+        return exclusions.open()
+
+    @property
+    def date_historic(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects with historic (pre 1970) values."""
+
+        return exclusions.closed()
+
+    @property
+    def time(self):
+        """target dialect supports representation of Python
+        datetime.time() objects."""
+
+        return exclusions.open()
+
+    @property
+    def time_microseconds(self):
+        """target dialect supports representation of Python
+        datetime.time() with microsecond objects."""
+
+        return exclusions.open()
+
     @property
     def text_type(self):
         """Target database must support an unbounded Text() "
index cd7b61f42405bfed8a40f31f8df9bc3590f9eff3..259cccff38dd0cc1e95570b4fbce8f1bc35621f5 100644 (file)
@@ -4,8 +4,9 @@ from .. import fixtures, config
 from ..assertions import eq_
 from ..config import requirements
 from sqlalchemy import Integer, Unicode, UnicodeText, select
+from sqlalchemy import Date, DateTime, Time, MetaData, String
 from ..schema import Table, Column
-
+import datetime
 
 class _UnicodeFixture(object):
     __requires__ = 'unicode_data',
@@ -101,4 +102,111 @@ class UnicodeTextTest(_UnicodeFixture, fixtures.TablesTest):
     def test_empty_strings(self):
         self._test_empty_strings()
 
-__all__ = ('UnicodeVarcharTest', 'UnicodeTextTest')
\ No newline at end of file
+
+class StringTest(fixtures.TestBase):
+    @requirements.unbounded_varchar
+    def test_nolength_string(self):
+        metadata = MetaData()
+        foo = Table('foo', metadata,
+                    Column('one', String)
+                )
+
+        foo.create(config.db)
+        foo.drop(config.db)
+
+class _DateFixture(object):
+    compare = None
+
+    @classmethod
+    def define_tables(cls, metadata):
+        Table('date_table', metadata,
+            Column('id', Integer, primary_key=True,
+                        test_needs_autoincrement=True),
+            Column('date_data', cls.datatype),
+            )
+
+    def test_round_trip(self):
+        date_table = self.tables.date_table
+
+        config.db.execute(
+            date_table.insert(),
+            {'date_data': self.data}
+        )
+
+        row = config.db.execute(
+                    select([
+                            date_table.c.date_data,
+                    ])
+                ).first()
+
+        compare = self.compare or self.data
+        eq_(row,
+            (compare, ))
+        assert isinstance(row[0], type(compare))
+
+    def test_null(self):
+        date_table = self.tables.date_table
+
+        config.db.execute(
+            date_table.insert(),
+            {'date_data': None}
+        )
+
+        row = config.db.execute(
+                    select([
+                            date_table.c.date_data,
+                    ])
+                ).first()
+        eq_(row, (None,))
+
+
+class DateTimeTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'datetime',
+    datatype = DateTime
+    data = datetime.datetime(2012, 10, 15, 12, 57, 18)
+
+class DateTimeMicrosecondsTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'datetime_microseconds',
+    datatype = DateTime
+    data = datetime.datetime(2012, 10, 15, 12, 57, 18, 396)
+
+class TimeTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'time',
+    datatype = Time
+    data = datetime.time(12, 57, 18)
+
+class TimeMicrosecondsTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'time_microseconds',
+    datatype = Time
+    data = datetime.time(12, 57, 18, 396)
+
+class DateTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'date',
+    datatype = Date
+    data = datetime.date(2012, 10, 15)
+
+class DateTimeCoercedToDateTimeTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'date',
+    datatype = Date
+    data = datetime.datetime(2012, 10, 15, 12, 57, 18)
+    compare = datetime.date(2012, 10, 15)
+
+class DateTimeHistoricTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'datetime_historic',
+    datatype = DateTime
+    data = datetime.datetime(1850, 11, 10, 11, 52, 35)
+
+class DateHistoricTest(_DateFixture, fixtures.TablesTest):
+    __requires__ = 'date_historic',
+    datatype = Date
+    data = datetime.date(1727, 4, 1)
+
+
+__all__ = ('UnicodeVarcharTest', 'UnicodeTextTest',
+            'DateTest', 'DateTimeTest',
+            'DateTimeHistoricTest', 'DateTimeCoercedToDateTimeTest',
+            'TimeMicrosecondsTest', 'TimeTest', 'DateTimeMicrosecondsTest',
+            'DateHistoricTest', 'StringTest')
+
+
+
index 736c0010809c4da34c8d20554277caf6a698dd74..ab37e66f6a2eb54b29379a3f91a89040d6331fc5 100644 (file)
@@ -6,6 +6,7 @@
 from sqlalchemy import util
 import sys
 from sqlalchemy.testing.requirements import SuiteRequirements
+from sqlalchemy.testing import exclusions
 from sqlalchemy.testing.exclusions import \
      skip, \
      skip_if,\
@@ -13,6 +14,7 @@ from sqlalchemy.testing.exclusions import \
      only_on,\
      fails_on_everything_except,\
      fails_if,\
+     succeeds_if,\
      SpecPredicate,\
      against
 
@@ -374,6 +376,55 @@ class DefaultRequirements(SuiteRequirements):
 
         return fails_on_everything_except('postgresql', 'oracle', 'mssql')
 
+    @property
+    def datetime(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects."""
+
+        return exclusions.open()
+
+    @property
+    def datetime_microseconds(self):
+        """target dialect supports representation of Python
+        datetime.datetime() with microsecond objects."""
+
+        return skip_if(['mssql', 'mysql', 'firebird', '+zxjdbc'])
+
+    @property
+    def datetime_historic(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects with historic (pre 1900) values."""
+
+        return succeeds_if(['sqlite', 'postgresql', 'firebird'])
+
+    @property
+    def date(self):
+        """target dialect supports representation of Python
+        datetime.date() objects."""
+
+        return exclusions.open()
+
+    @property
+    def date_historic(self):
+        """target dialect supports representation of Python
+        datetime.datetime() objects with historic (pre 1900) values."""
+
+        return succeeds_if(['sqlite', 'postgresql', 'firebird'])
+
+    @property
+    def time(self):
+        """target dialect supports representation of Python
+        datetime.time() objects."""
+
+        return exclusions.open()
+
+    @property
+    def time_microseconds(self):
+        """target dialect supports representation of Python
+        datetime.time() with microsecond objects."""
+
+        return skip_if(['mssql', 'mysql', 'firebird', '+zxjdbc'])
+
     @property
     def python2(self):
         return skip_if(
index 98bc516247ab075fa263a38073849ab98aac1e39..5f80e794718878250db6246c6fdb25cf9cae4176 100644 (file)
@@ -1301,157 +1301,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                 allow_dialect_select=True)
 
 
-class DateTest(fixtures.TestBase, AssertsExecutionResults):
-    @classmethod
-    def setup_class(cls):
-        global users_with_date, insert_data
-
-        db = testing.db
-        if testing.against('oracle'):
-            insert_data =  [
-                    (7, 'jack',
-                     datetime.datetime(2005, 11, 10, 0, 0),
-                     datetime.date(2005,11,10),
-                     datetime.datetime(2005, 11, 10, 0, 0, 0, 29384)),
-                    (8, 'roy',
-                     datetime.datetime(2005, 11, 10, 11, 52, 35),
-                     datetime.date(2005,10,10),
-                     datetime.datetime(2006, 5, 10, 15, 32, 47, 6754)),
-                    (9, 'foo',
-                     datetime.datetime(2006, 11, 10, 11, 52, 35),
-                     datetime.date(1970,4,1),
-                     datetime.datetime(2004, 9, 18, 4, 0, 52, 1043)),
-                    (10, 'colber', None, None, None),
-             ]
-            fnames = ['user_id', 'user_name', 'user_datetime',
-                      'user_date', 'user_time']
-
-            collist = [Column('user_id', INT, primary_key=True),
-                       Column('user_name', VARCHAR(20)),
-                       Column('user_datetime', DateTime),
-                       Column('user_date', Date),
-                       Column('user_time', TIMESTAMP)]
-        else:
-            datetime_micro = 54839
-            time_micro = 999
-
-            # Missing or poor microsecond support:
-            if testing.against('mssql', 'mysql', 'firebird', '+zxjdbc'):
-                datetime_micro, time_micro = 0, 0
-            # No microseconds for TIME
-            elif testing.against('maxdb'):
-                time_micro = 0
-
-            insert_data =  [
-                (7, 'jack',
-                 datetime.datetime(2005, 11, 10, 0, 0),
-                 datetime.date(2005, 11, 10),
-                 datetime.time(12, 20, 2)),
-                (8, 'roy',
-                 datetime.datetime(2005, 11, 10, 11, 52, 35),
-                 datetime.date(2005, 10, 10),
-                 datetime.time(0, 0, 0)),
-                (9, 'foo',
-                 datetime.datetime(2005, 11, 10, 11, 52, 35, datetime_micro),
-                 datetime.date(1970, 4, 1),
-                 datetime.time(23, 59, 59, time_micro)),
-                (10, 'colber', None, None, None),
-            ]
-
-
-            fnames = ['user_id', 'user_name', 'user_datetime',
-                      'user_date', 'user_time']
-
-            collist = [Column('user_id', INT, primary_key=True),
-                       Column('user_name', VARCHAR(20)),
-                       Column('user_datetime', DateTime(timezone=False)),
-                       Column('user_date', Date),
-                       Column('user_time', Time)]
-
-        if testing.against('sqlite', 'postgresql'):
-            insert_data.append(
-                (11, 'historic',
-                datetime.datetime(1850, 11, 10, 11, 52, 35, datetime_micro),
-                datetime.date(1727,4,1),
-                None),
-            )
-
-        users_with_date = Table('query_users_with_date',
-                                MetaData(testing.db), *collist)
-        users_with_date.create()
-        insert_dicts = [dict(zip(fnames, d)) for d in insert_data]
-
-        for idict in insert_dicts:
-            users_with_date.insert().execute(**idict)
-
-    @classmethod
-    def teardown_class(cls):
-        users_with_date.drop()
-
-    def test_date_roundtrip(self):
-        global insert_data
-
-        l = map(tuple,
-                users_with_date.select().order_by(users_with_date.c.user_id).execute().fetchall())
-        self.assert_(l == insert_data,
-                     'DateTest mismatch: got:%s expected:%s' % (l, insert_data))
-
-    def test_text_date_roundtrip(self):
-        x = testing.db.execute(text(
-            "select user_datetime from query_users_with_date",
-            typemap={'user_datetime': DateTime})).fetchall()
-
-        self.assert_(isinstance(x[0][0], datetime.datetime))
-
-        x = testing.db.execute(text(
-            "select * from query_users_with_date where user_datetime=:somedate",
-            bindparams=[bindparam('somedate', type_=types.DateTime)]),
-            somedate=datetime.datetime(2005, 11, 10, 11, 52, 35)).fetchall()
-
-    def test_date_mixdatetime_roundtrip(self):
-        meta = MetaData(testing.db)
-        t = Table('testdate', meta,
-                    Column('id', Integer,
-                         Sequence('datetest_id_seq', optional=True),
-                         primary_key=True),
-                    Column('adate', Date),
-                    Column('adatetime', DateTime))
-        t.create(checkfirst=True)
-        try:
-            d1 = datetime.date(2007, 10, 30)
-            t.insert().execute(adate=d1, adatetime=d1)
-            d2 = datetime.datetime(2007, 10, 30)
-            t.insert().execute(adate=d2, adatetime=d2)
-
-            x = t.select().execute().fetchall()[0]
-            eq_(x.adate.__class__, datetime.date)
-            eq_(x.adatetime.__class__, datetime.datetime)
-
-            t.delete().execute()
-
-            # test mismatched date/datetime
-            t.insert().execute(adate=d2, adatetime=d2)
-            eq_(
-                select([t.c.adate, t.c.adatetime], t.c.adate == d1)\
-                    .execute().fetchall(),
-                [(d1, d2)])
-            eq_(
-                select([t.c.adate, t.c.adatetime], t.c.adate == d1)\
-                    .execute().fetchall(),
-                [(d1, d2)])
-
-        finally:
-            t.drop(checkfirst=True)
-
-class StringTest(fixtures.TestBase):
-
-    @testing.requires.unbounded_varchar
-    def test_nolength_string(self):
-        metadata = MetaData(testing.db)
-        foo = Table('foo', metadata, Column('one', String))
 
-        foo.create()
-        foo.drop()
 
 class NumericTest(fixtures.TestBase):
     def setup(self):