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

Annotation of /branches/WIP-pyshapelib-bramz/test/test_memory_table.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 818 - (hide annotations)
Mon May 5 17:18:31 2003 UTC (21 years, 10 months ago) by bh
Original Path: trunk/thuban/test/test_memory_table.py
File MIME type: text/x-python
File size: 3804 byte(s)
Convert the table implementations to a new table interface. All
tables use a common mixin class to provide backwards compatibility
until all table users have been updated.

* Thuban/Model/table.py (OldTableInterfaceMixin): Mixin class to
provide backwards compatibility for table classes implementing the
new interface
(DBFTable, MemoryTable): Implement the new table interface. Use
OldTableInterfaceMixin as base for compatibility
(DBFColumn, MemoryColumn): New. Column description for DBFTable
and MemoryTable resp.

* test/test_dbf_table.py: New. Test cases for the DBFTable with
the new table interface.

* test/test_memory_table.py: New. Test cases for the MemoryTable
with the new table interface.

* test/test_table.py: Document the all tests in this file as only
for backwards compatibility. The equivalent tests for the new
interface are in test_memory_table.py and test_dbf_table.py
(MemoryTableTest.test_read): field_info should be returning tuples
with four items
(MemoryTableTest.test_write): Make doc-string a more precise.

* Thuban/Model/transientdb.py (TransientTableBase): Convert to new
table interface. Derive from from OldTableInterfaceMixin for
compatibility.
(TransientTableBase.create): New intance variable column_map to
map from names and indices to column objects
(TransientTable.create): Use the new table interface of the input
table
(AutoTransientTable): Convert to new table interface. Derive from
from OldTableInterfaceMixin for compatibility.
(AutoTransientTable.write_record): Removed. It's not implemented
yet and we still have to decide how to handle writing with the new
table and data framework.

* test/test_transientdb.py
(TestTransientTable.run_iceland_political_tests)
(TestTransientTable.test_transient_joined_table): Use the new
table interface

1 bh 818 # Copyright (c) 2002, 2003 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Test the MemoryTable class
10     """
11    
12     __version__ = "$Revision$"
13     # $Source$
14     # $Id$
15    
16     import os
17     import unittest
18    
19     import support
20     support.initthuban()
21    
22     from Thuban.Model.table import MemoryTable, \
23     FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING
24     import dbflib
25    
26    
27    
28     class TestMemoryTable(unittest.TestCase):
29    
30     def setUp(self):
31     """Create a new dbf file. The name is in self.filename"""
32     self.table = MemoryTable([("type", FIELDTYPE_STRING),
33     ("value", FIELDTYPE_DOUBLE),
34     ("code", FIELDTYPE_INT)],
35     [("UNKNOWN", 0.0, 0),
36     ("Foo", 0.5, -1),
37     ("Foo", 0.25, 100),
38     ("bar", 1e10, 17)])
39    
40     def test_num_rows(self):
41     """Test MemoryTable.NumRows()"""
42     self.assertEquals(self.table.NumRows(), 4)
43    
44     def test_num_columns(self):
45     """Test MemoryTable.NumColumns()"""
46     self.assertEquals(self.table.NumColumns(), 3)
47    
48     def test_columns(self):
49     """Test MemoryTable.Columns()"""
50     columns = self.table.Columns()
51     self.assertEquals(columns[0].name, "type")
52     self.assertEquals(columns[0].type, FIELDTYPE_STRING)
53     self.assertEquals(columns[1].name, "value")
54     self.assertEquals(columns[1].type, FIELDTYPE_DOUBLE)
55     self.assertEquals(columns[2].name, "code")
56     self.assertEquals(columns[2].type, FIELDTYPE_INT)
57    
58     def test_column(self):
59     """Test MemoryTable.Column()"""
60     # The Column method can be called with either an index or a name
61     col = self.table.Column(2)
62     self.assertEquals(col.name, "code")
63     self.assertEquals(col.type, FIELDTYPE_INT)
64     col = self.table.Column("value")
65     self.assertEquals(col.name, "value")
66     self.assertEquals(col.type, FIELDTYPE_DOUBLE)
67    
68     def test_read_row_as_dict(self):
69     """Test MemoryTable.ReadRowAsDict()"""
70     self.assertEquals(self.table.ReadRowAsDict(1),
71     {"type": "Foo", "value": 0.5, "code": -1})
72    
73     def test_read_value(self):
74     """Test MemoryTable.ReadValue()"""
75     # The column in ReadValue may be given as either name or index
76     self.assertEquals(self.table.ReadValue(2, 0), "Foo")
77     self.assertEquals(self.table.ReadValue(3, "code"), 17)
78    
79     def test_value_range(self):
80     """Test MemoryTable.ValueRange()"""
81     self.assertEquals(self.table.ValueRange("code"), (-1, 100))
82     self.assertEquals(self.table.ValueRange(1), (0, 1e10))
83    
84     def test_unique_values(self):
85     """Test MemoryTable.UniqueValues()"""
86     # The column can be specified by name or index
87     self.assertEquals(self.table.UniqueValues("type"),
88     ["Foo", "UNKNOWN", "bar"])
89     self.assertEquals(self.table.UniqueValues(2), [-1, 0, 17, 100])
90    
91     def test_write(self):
92     """Test MemoryTable.write_record()"""
93     # change only one field
94     # TODO: acticate when implemented
95     # table.write_record(2, {"type": "FARMS"})
96    
97     # check whether the table returns the new value
98     # TODO: acticate when implemented
99     #eq(table.read_record(2),
100     # {'type': "FARMS", "height": 400.44, "code": 2})
101    
102     # Check whether we can specify the record as a tuple
103     self.table.write_record(3, ("HUTS", 111.11, 42))
104     self.assertEquals(self.table.read_record(3),
105     {"type": "HUTS", "value": 111.11, "code": 42})
106    
107    
108    
109     if __name__ == "__main__":
110     support.run_tests()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26