19 |
import support |
import support |
20 |
support.initthuban() |
support.initthuban() |
21 |
|
|
22 |
|
import dbflib |
23 |
from Thuban.Model.table import DBFTable, MemoryTable, FIELDTYPE_STRING, \ |
from Thuban.Model.table import DBFTable, MemoryTable, FIELDTYPE_STRING, \ |
24 |
FIELDTYPE_INT, FIELDTYPE_DOUBLE |
FIELDTYPE_INT, FIELDTYPE_DOUBLE, table_to_dbf |
25 |
from Thuban.Model.transientdb import TransientDatabase, TransientTable, \ |
from Thuban.Model.transientdb import TransientDatabase, TransientTable, \ |
26 |
TransientJoinedTable, AutoTransientTable |
TransientJoinedTable, AutoTransientTable |
27 |
|
|
362 |
table.SimpleQuery, |
table.SimpleQuery, |
363 |
table.Column(1), "<<", table.Column(2)) |
table.Column(1), "<<", table.Column(2)) |
364 |
|
|
365 |
|
def test_transienttable_to_dbf(self): |
366 |
|
memtable = MemoryTable([("type", FIELDTYPE_STRING), |
367 |
|
("value", FIELDTYPE_DOUBLE), |
368 |
|
("code", FIELDTYPE_INT)], |
369 |
|
[("UNKNOWN", 0.0, 0), |
370 |
|
("Foo", 0.5, -1), |
371 |
|
("Foo", 1.0/256, 100), |
372 |
|
("bar", 1e10, 17)]) |
373 |
|
table = TransientTable(self.transientdb, memtable) |
374 |
|
filename = self.temp_file_name("test_transienttable_to_dbf.dbf") |
375 |
|
table_to_dbf(table, filename) |
376 |
|
|
377 |
|
dbf = dbflib.DBFFile(filename) |
378 |
|
self.assertEquals(dbf.read_record(2), |
379 |
|
{'code': 100, 'type': 'Foo', 'value': 0.00390625}) |
380 |
|
self.assertEquals(dbf.field_count(), 3) |
381 |
|
self.assertEquals(dbf.record_count(), 4) |
382 |
|
self.assertEquals(dbf.field_info(0), |
383 |
|
(dbflib.FTString, "type", 7, 0)) |
384 |
|
self.assertEquals(dbf.field_info(1), |
385 |
|
(dbflib.FTDouble, "value", 24, 12)) |
386 |
|
self.assertEquals(dbf.field_info(2), |
387 |
|
(dbflib.FTInteger, "code", 3, 0)) |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
if __name__ == "__main__": |
if __name__ == "__main__": |
392 |
support.run_tests() |
support.run_tests() |