Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed up the tests added for #9779 to run under Python 2.3, w…

…hich doesn't have set.

Merge of the part of [10392] that applies to the 1.0.X branch.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10393 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2d20e5265a9cfcca82eee4e2a7f2afac15bd1641 1 parent cfe9b6f
Karen Tracey authored
35  tests/regressiontests/introspection/tests.py
@@ -5,13 +5,18 @@
5 5
 
6 6
 from models import Reporter, Article
7 7
 
  8
+try:
  9
+    set
  10
+except NameError:
  11
+    from sets import Set as set     # Python 2.3 fallback
  12
+
8 13
 #
9 14
 # The introspection module is optional, so methods tested here might raise
10 15
 # NotImplementedError. This is perfectly acceptable behavior for the backend
11 16
 # in question, but the tests need to handle this without failing. Ideally we'd
12 17
 # skip these tests, but until #4788 is done we'll just ignore them.
13 18
 #
14  
-# The easiest way to accomplish this is to decorate every test case with a 
  19
+# The easiest way to accomplish this is to decorate every test case with a
15 20
 # wrapper that ignores the exception.
16 21
 #
17 22
 # The metaclass is just for fun.
@@ -35,14 +40,14 @@ def __new__(cls, name, bases, attrs):
35 40
 
36 41
 class IntrospectionTests(TestCase):
37 42
     __metaclass__ = IgnoreNotimplementedError
38  
-    
  43
+
39 44
     def test_table_names(self):
40 45
         tl = connection.introspection.table_names()
41  
-        self.assert_(Reporter._meta.db_table in tl, 
  46
+        self.assert_(Reporter._meta.db_table in tl,
42 47
                      "'%s' isn't in table_list()." % Reporter._meta.db_table)
43  
-        self.assert_(Article._meta.db_table in tl, 
  48
+        self.assert_(Article._meta.db_table in tl,
44 49
                      "'%s' isn't in table_list()." % Article._meta.db_table)
45  
-                     
  50
+
46 51
     def test_django_table_names(self):
47 52
         cursor = connection.cursor()
48 53
         cursor.execute('CREATE TABLE django_introspection_test_table (id INTEGER);');
@@ -50,26 +55,26 @@ def test_django_table_names(self):
50 55
         cursor.execute("DROP TABLE django_introspection_test_table;")
51 56
         self.assert_('django_introspection_testcase_table' not in tl,
52 57
                      "django_table_names() returned a non-Django table")
53  
-                        
  58
+
54 59
     def test_installed_models(self):
55 60
         tables = [Article._meta.db_table, Reporter._meta.db_table]
56 61
         models = connection.introspection.installed_models(tables)
57 62
         self.assertEqual(models, set([Article, Reporter]))
58  
-        
  63
+
59 64
     def test_sequence_list(self):
60 65
         sequences = connection.introspection.sequence_list()
61 66
         expected = {'table': Reporter._meta.db_table, 'column': 'id'}
62  
-        self.assert_(expected in sequences, 
  67
+        self.assert_(expected in sequences,
63 68
                      'Reporter sequence not found in sequence_list()')
64  
-                     
  69
+
65 70
     def test_get_table_description_names(self):
66 71
         cursor = connection.cursor()
67 72
         desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
68 73
         self.assertEqual([r[0] for r in desc],
69 74
                          [f.column for f in Reporter._meta.fields])
70  
-    
  75
+
71 76
     def test_get_table_description_types(self):
72  
-        cursor = connection.cursor()            
  77
+        cursor = connection.cursor()
73 78
         desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
74 79
         self.assertEqual([datatype(r[1]) for r in desc],
75 80
                           ['IntegerField', 'CharField', 'CharField', 'CharField'])
@@ -78,7 +83,7 @@ def test_get_table_description_types(self):
78 83
     if settings.DATABASE_ENGINE.startswith('postgresql'):
79 84
         def test_postgresql_real_type(self):
80 85
             cursor = connection.cursor()
81  
-            cursor.execute("CREATE TABLE django_introspection_real_test_table (number REAL);") 
  86
+            cursor.execute("CREATE TABLE django_introspection_real_test_table (number REAL);")
82 87
             desc = connection.introspection.get_table_description(cursor, 'django_introspection_real_test_table')
83 88
             cursor.execute('DROP TABLE django_introspection_real_test_table;')
84 89
             self.assertEqual(datatype(desc[0][1]), 'FloatField')
@@ -86,19 +91,19 @@ def test_postgresql_real_type(self):
86 91
     def test_get_relations(self):
87 92
         cursor = connection.cursor()
88 93
         relations = connection.introspection.get_relations(cursor, Article._meta.db_table)
89  
-        
  94
+
90 95
         # Older versions of MySQL don't have the chops to report on this stuff,
91 96
         # so just skip it if no relations come back. If they do, though, we
92 97
         # should test that the response is correct.
93 98
         if relations:
94 99
             # That's {field_index: (field_index_other_table, other_table)}
95 100
             self.assertEqual(relations, {3: (0, Reporter._meta.db_table)})
96  
-            
  101
+
97 102
     def test_get_indexes(self):
98 103
         cursor = connection.cursor()
99 104
         indexes = connection.introspection.get_indexes(cursor, Article._meta.db_table)
100 105
         self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False})
101  
-        
  106
+
102 107
 def datatype(dbtype):
103 108
     """Helper to convert a data type into a string."""
104 109
     dt = connection.introspection.data_types_reverse[dbtype]

0 notes on commit 2d20e52

Please sign in to comment.
Something went wrong with that request. Please try again.