Commits

paj committed 0932b67

MSSQL unit test fixes

  • Participants
  • Parent commits 673bde5
  • Branches rel_0_3

Comments (0)

Files changed (4)

lib/sqlalchemy/databases/mssql.py

     def preparer(self):
         return MSSQLIdentifierPreparer(self)
 
-    def get_default_schema_name(self):
+    def get_default_schema_name(self, connection):
         return self.schema_name
 
     def set_default_schema_name(self, schema_name):
     def has_table(self, connection, tablename, schema=None):
         import sqlalchemy.databases.information_schema as ischema
 
-        current_schema = schema or self.get_default_schema_name()
+        current_schema = schema or self.get_default_schema_name(connection)
         columns = self.uppercase_table(ischema.columns)
         s = sql.select([columns],
                    current_schema
         if table.schema is not None:
             current_schema = table.schema
         else:
-            current_schema = self.get_default_schema_name()
+            current_schema = self.get_default_schema_name(connection)
 
         columns = self.uppercase_table(ischema.columns)
         s = sql.select([columns],

test/orm/query.py

     def test_basic(self):
         assert [User(id=7), User(id=8), User(id=9),User(id=10)] == create_session().query(User).all()
 
+    @testbase.unsupported('mssql')
     def test_limit(self):
         assert [User(id=8), User(id=9)] == create_session().query(User).limit(2).offset(1).all()
 

test/sql/testtypes.py

             ]
 
             if db.engine.name == 'mssql':
-                # MSSQL Datetime values have only a 3.33 milliseconds precision
-                insert_data[2] = [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35, 547000), datetime.date(1970,4,1), datetime.time(23,59,59,997000)]
+                # MSSQL can't reliably fetch the millisecond part
+                insert_data[2] = [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35), datetime.date(1970,4,1), datetime.time(23,59,59)]
 
             fnames = ['user_id', 'user_name', 'user_datetime', 'user_date', 'user_time']
 
         ctx = self.ctx
         statement = unicode(ctx.compiled)
         statement = re.sub(r'\n', '', ctx.statement)
+        if db.engine.name == 'mssql' and statement.endswith('; select scope_identity()'):
+            statement = statement[:-25]
         if testdata.buffer is not None:
             testdata.buffer.write(statement + "\n")
 
                         testdata.assert_list.pop()
                     item = (statement, entry)
                 except KeyError:
+                    print "Testing for one of the following queries: %s, received '%s'" % (repr([k for k in item.keys()]), statement)
                     self.unittest.assert_(False, "Testing for one of the following queries: %s, received '%s'" % (repr([k for k in item.keys()]), statement))
 
             (query, params) = item
                 parameters = [p.get_original_dict() for p in ctx.compiled_parameters]
                     
             query = self.convert_statement(query)
-            if db.engine.name == 'mssql' and statement.endswith('; select scope_identity()'):
-                statement = statement[:-25]
             testdata.unittest.assert_(statement == query and (params is None or params == parameters), "Testing for query '%s' params %s, received '%s' with params %s" % (query, repr(params), statement, repr(parameters)))
         testdata.sql_count += 1
         self.ctx.post_exec()