Commits

Mike Bayer  committed c939762

- support "fails_if" requirements as __requires__; so far this just skips, doesn't
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

  • Participants
  • Parent commits fb879c7

Comments (0)

Files changed (5)

File lib/sqlalchemy/testing/plugin/noseplugin.py

             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__)

File lib/sqlalchemy/testing/requirements.py

         """
         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() "

File lib/sqlalchemy/testing/suite/test_types.py

 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',
     def test_empty_strings(self):
         self._test_empty_strings()
 
-__all__ = ('UnicodeVarcharTest', 'UnicodeTextTest')
+
+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')
+
+
+

File test/requirements.py

 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,\
      only_on,\
      fails_on_everything_except,\
      fails_if,\
+     succeeds_if,\
      SpecPredicate,\
      against
 
         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(
                 lambda: sys.version_info >= (3,),

File test/sql/test_types.py

                 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):