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): |
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), |
146 |
|
|
147 |
def test_transient_table_read_twice(self): |
def test_transient_table_read_twice(self): |
148 |
"""Test TransientTable.read_record() reading the same record twice""" |
"""Test TransientTable.read_record() reading the same record twice""" |
149 |
simple = SimpleTable([("type", FIELDTYPE_STRING), |
simple = MemoryTable([("type", FIELDTYPE_STRING), |
150 |
("code", FIELDTYPE_INT)], |
("code", FIELDTYPE_INT)], |
151 |
[("OTHER/UNKNOWN", 0), |
[("OTHER/UNKNOWN", 0), |
152 |
("RUINS", 1), |
("RUINS", 1), |