/[thuban]/branches/WIP-pyshapelib-bramz/test/test_transientdb.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/test_transientdb.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 765 by bh, Tue Apr 29 12:42:14 2003 UTC revision 805 by jan, Fri May 2 16:42:35 2003 UTC
# Line 19  import unittest Line 19  import unittest
19  import support  import support
20  support.initthuban()  support.initthuban()
21    
22  from Thuban.Model.table import DBFTable, FIELDTYPE_STRING, FIELDTYPE_INT  from Thuban.Model.table import DBFTable, MemoryTable, FIELDTYPE_STRING, \
23                                   FIELDTYPE_INT
24  from Thuban.Model.transientdb import TransientDatabase, TransientTable, \  from Thuban.Model.transientdb import TransientDatabase, TransientTable, \
25       TransientJoinedTable, AutoTransientTable       TransientJoinedTable, AutoTransientTable
26    
27    
 class SimpleTable:  
   
     """Very simple table implementation that operates on a list of tuples"""  
   
     def __init__(self, fields, data):  
         """Initialize the SimpleTable  
   
         Parameters:  
         fields -- List of (name, field_type) pairs  
         data -- List of tuples, one for each row of data  
         """  
         self.fields = fields  
         self.data = data  
   
     def field_count(self):  
         return len(self.fields)  
   
     def field_info(self, index):  
         name, type = self.fields[index]  
         return (type, name, 0, 0)  
   
     def record_count(self):  
         return len(self.data)  
   
     def read_record(self, index):  
         return dict([(self.fields[i][0], self.data[index][i])  
                       for i in range(len(self.fields))])  
   
   
28  class TestTransientTable(unittest.TestCase, support.FileTestMixin):  class TestTransientTable(unittest.TestCase, support.FileTestMixin):
29    
30      def setUp(self):      def setUp(self):
# Line 139  class TestTransientTable(unittest.TestCa Line 111  class TestTransientTable(unittest.TestCa
111    
112      def test_transient_joined_table(self):      def test_transient_joined_table(self):
113          """Test TransientJoinedTable"""          """Test TransientJoinedTable"""
114          simple = SimpleTable([("type", FIELDTYPE_STRING),          simple = MemoryTable([("type", FIELDTYPE_STRING),
115                                ("code", FIELDTYPE_INT)],                                ("code", FIELDTYPE_INT)],
116                               [("OTHER/UNKNOWN", 0),                               [("OTHER/UNKNOWN", 0),
117                                ("RUINS", 1),                                ("RUINS", 1),
# Line 172  class TestTransientTable(unittest.TestCa Line 144  class TestTransientTable(unittest.TestCa
144          self.assert_(table is table.transient_table())          self.assert_(table is table.transient_table())
145    
146    
147        def test_transient_table_read_twice(self):
148            """Test TransientTable.read_record() reading the same record twice"""
149            simple = MemoryTable([("type", FIELDTYPE_STRING),
150                                  ("code", FIELDTYPE_INT)],
151                                 [("OTHER/UNKNOWN", 0),
152                                  ("RUINS", 1),
153                                  ("FARM", 2),
154                                  ("BUILDING", 3),
155                                  ("HUT", 4),
156                                  ("LIGHTHOUSE", 5)])
157            table = TransientTable(self.transientdb, simple)
158    
159            # There was a bug where reading the same record twice would
160            # raise an exception in the second call because of an
161            # unitialized local variable, so for passing the test it's
162            # enough if reading simply succeeds. OTOH, while we're at it we
163            # might as well check whether the results are equal anyway :)
164            result1 = table.read_record(3)
165            result2 = table.read_record(3)
166            self.assertEquals(result1, result2)
167    
168  if __name__ == "__main__":  if __name__ == "__main__":
169      support.run_tests()      support.run_tests()

Legend:
Removed from v.765  
changed lines
  Added in v.805

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26