67 |
self.failIf(table.HasColumn("non_existing_name")) |
self.failIf(table.HasColumn("non_existing_name")) |
68 |
self.failIf(table.HasColumn(100)) |
self.failIf(table.HasColumn(100)) |
69 |
|
|
70 |
# Read an `interesting' record |
# Reading rows and values. |
71 |
self.assertEquals(table.ReadRowAsDict(144), |
self.assertEquals(table.ReadRowAsDict(144), |
72 |
{'POPYCOUN': 'IC', 'POPYADMIN': '', 'PONET_': 146, |
{'POPYCOUN': 'IC', 'POPYADMIN': '', 'PONET_': 146, |
73 |
'AREA': 19.462, |
'AREA': 19.462, |
74 |
'POPYTYPE': 1, 'PERIMETER': 88.518000000000001, |
'POPYTYPE': 1, 'PERIMETER': 88.518000000000001, |
75 |
'POPYREG': '1', |
'POPYREG': '1', |
76 |
'PONET_ID': 145}) |
'PONET_ID': 145}) |
77 |
|
self.assertEquals(table.ReadValue(144, "AREA"), 19.462) |
78 |
|
self.assertEquals(table.ReadValue(144, 3), 145) |
79 |
|
|
80 |
# ValueRange may induce a copy to the transient database. |
# ValueRange may induce a copy to the transient database. |
81 |
# Therefore we put it last so that we can execute this method |
# Therefore we put it last so that we can execute this method |
120 |
self.run_iceland_political_tests(table) |
self.run_iceland_political_tests(table) |
121 |
self.run_iceland_political_tests(table) |
self.run_iceland_political_tests(table) |
122 |
|
|
123 |
|
def test_auto_transient_table_query(self): |
124 |
|
"""Test AutoTransientTable.SimpleQuery()""" |
125 |
|
orig_table = DBFTable(os.path.join("..", "Data", "iceland", |
126 |
|
"political.dbf")) |
127 |
|
table = AutoTransientTable(self.transientdb, orig_table) |
128 |
|
# Only a simple test here. The AutoTransientTable simply |
129 |
|
# delegates to its transient table so it should be OK that the |
130 |
|
# real test for it is in test_transient_table_query. However, |
131 |
|
# it's important to check that the column handling works |
132 |
|
# correctly because the AutoTransientTable and it's underlying |
133 |
|
# transient table use different column object types. |
134 |
|
self.assertEquals(table.SimpleQuery(table.Column("AREA"), ">", 10.0), |
135 |
|
[144]) |
136 |
|
|
137 |
|
# test using a Column object as the right parameter |
138 |
|
self.assertEquals(table.SimpleQuery(table.Column("POPYTYPE"), |
139 |
|
"==", |
140 |
|
table.Column("POPYREG")), |
141 |
|
range(156)) |
142 |
|
|
143 |
def test_transient_joined_table(self): |
def test_transient_joined_table(self): |
144 |
"""Test TransientJoinedTable""" |
"""Test TransientJoinedTable""" |
173 |
self.failIf(table.HasColumn("non_existing_name")) |
self.failIf(table.HasColumn("non_existing_name")) |
174 |
self.failIf(table.HasColumn(100)) |
self.failIf(table.HasColumn(100)) |
175 |
|
|
176 |
# Read an `interesting' record |
# Reading rows and values |
177 |
self.assertEquals(table.ReadRowAsDict(22), |
self.assertEquals(table.ReadRowAsDict(22), |
178 |
{'PERIMETER': 0.0, 'CLPOINT_': 23, |
{'PERIMETER': 0.0, 'CLPOINT_': 23, |
179 |
'AREA': 0.0, 'CLPTLABEL': 'RUINS', |
'AREA': 0.0, 'CLPTLABEL': 'RUINS', |
180 |
'CLPOINT_ID': 38, 'CLPTFLAG': 0, |
'CLPOINT_ID': 38, 'CLPTFLAG': 0, |
181 |
'code': 1, 'type': 'RUINS'}) |
'code': 1, 'type': 'RUINS'}) |
182 |
|
self.assertEquals(table.ReadValue(22, "type"), 'RUINS') |
183 |
|
self.assertEquals(table.ReadValue(22, 7), 1) |
184 |
|
|
185 |
# The transient_table method should return the table itself |
# The transient_table method should return the table itself |
186 |
self.assert_(table is table.transient_table()) |
self.assert_(table is table.transient_table()) |
187 |
|
|
188 |
|
|
189 |
def test_transient_table_read_twice(self): |
def test_transient_table_read_twice(self): |
190 |
"""Test TransientTable.read_record() reading the same record twice""" |
"""Test TransientTable.ReadRowAsDict() reading the same record twice""" |
191 |
simple = MemoryTable([("type", FIELDTYPE_STRING), |
simple = MemoryTable([("type", FIELDTYPE_STRING), |
192 |
("code", FIELDTYPE_INT)], |
("code", FIELDTYPE_INT)], |
193 |
[("OTHER/UNKNOWN", 0), |
[("OTHER/UNKNOWN", 0), |
208 |
self.assertEquals(result1, result2) |
self.assertEquals(result1, result2) |
209 |
|
|
210 |
|
|
211 |
|
def test_transient_table_query(self): |
212 |
|
"""Test TransientTable.SimpleQuery()""" |
213 |
|
simple = MemoryTable([("type", FIELDTYPE_STRING), |
214 |
|
("value", FIELDTYPE_DOUBLE), |
215 |
|
("code", FIELDTYPE_INT)], |
216 |
|
[("OTHER/UNKNOWN", -1.5, 11), |
217 |
|
("RUINS", 0.0, 1), |
218 |
|
("FARM", 3.141, 2), |
219 |
|
("BUILDING", 2.5, 3), |
220 |
|
("HUT", 1e6, 4), |
221 |
|
("LIGHTHOUSE", -0.01, 5)]) |
222 |
|
table = TransientTable(self.transientdb, simple) |
223 |
|
|
224 |
|
# A column and a value |
225 |
|
self.assertEquals(table.SimpleQuery(table.Column(0), "==", "RUINS"), |
226 |
|
[1]) |
227 |
|
self.assertEquals(table.SimpleQuery(table.Column(2), "!=", 2), |
228 |
|
[0, 1, 3, 4, 5]) |
229 |
|
self.assertEquals(table.SimpleQuery(table.Column(1), "<", 1.0), |
230 |
|
[0, 1, 5]) |
231 |
|
self.assertEquals(table.SimpleQuery(table.Column(1), "<=", -1.5), |
232 |
|
[0]) |
233 |
|
self.assertEquals(table.SimpleQuery(table.Column(2), ">", 3), |
234 |
|
[0, 4, 5]) |
235 |
|
self.assertEquals(table.SimpleQuery(table.Column(2), ">=", 3), |
236 |
|
[0, 3, 4, 5]) |
237 |
|
|
238 |
|
# Two columns as operands |
239 |
|
self.assertEquals(table.SimpleQuery(table.Column(1), |
240 |
|
"<=", table.Column(2)), |
241 |
|
[0, 1, 3, 5]) |
242 |
|
|
243 |
|
# Test whether invalid operators raise a ValueError |
244 |
|
self.assertRaises(ValueError, |
245 |
|
table.SimpleQuery, |
246 |
|
table.Column(1), "<<", table.Column(2)) |
247 |
|
|
248 |
|
|
249 |
if __name__ == "__main__": |
if __name__ == "__main__": |
250 |
support.run_tests() |
support.run_tests() |