237 |
outer_join = True) |
outer_join = True) |
238 |
|
|
239 |
self.assertEquals(table.NumRows(), 4) |
self.assertEquals(table.NumRows(), 4) |
240 |
self.assertEquals(table.NumColumns(), 2) |
self.assertEquals(table.NumColumns(), 3) |
241 |
|
|
242 |
# HasColumn |
# HasColumn |
243 |
self.failUnless(table.HasColumn("stretch_id")) |
self.failUnless(table.HasColumn("stretch_id")) |
247 |
def test_transient_joined_table_with_equal_column_names(self): |
def test_transient_joined_table_with_equal_column_names(self): |
248 |
"""Test TransientJoinedTable join on tables with equal column names |
"""Test TransientJoinedTable join on tables with equal column names |
249 |
|
|
250 |
The join of two tables contains all fields from both tables instead |
If a name collision occurs for the field names, underscores are |
251 |
th field the join was performed on. This special field is included |
appended as long as any collision is resolved. |
|
once. If a name collision occurs for the field names, underscores are |
|
|
appended as long as any collision is resolved. |
|
252 |
""" |
""" |
253 |
mem_stretches = MemoryTable([("stretch_id", FIELDTYPE_INT), |
mem_stretches = MemoryTable([("stretch_id", FIELDTYPE_INT), |
254 |
("name", FIELDTYPE_INT)], |
("name", FIELDTYPE_INT)], |
266 |
outer_join = True) |
outer_join = True) |
267 |
|
|
268 |
self.assertEquals(table.NumRows(), 4) |
self.assertEquals(table.NumRows(), 4) |
269 |
self.assertEquals(table.NumColumns(), 4) |
self.assertEquals(table.NumColumns(), 5) |
270 |
|
|
271 |
# HasColumn |
# HasColumn |
272 |
self.failUnless(table.HasColumn("stretch_id")) |
self.assertEquals([c.name for c in table.Columns()], |
273 |
self.failUnless(table.HasColumn("disch_id")) |
["stretch_id", "name", "disch_id", "stretch_id_", |
274 |
self.failUnless(table.HasColumn("name")) |
"name_"]) |
275 |
self.failUnless(table.HasColumn("name_")) |
|
276 |
|
def test_transient_joined_table_name_collisions_dont_modify_in_place(self): |
277 |
|
"""Test TransientJoinedTable name-collisions do not modifying in place |
278 |
|
|
279 |
|
The name collision work-around by appending underscores |
280 |
|
accidentally modified the column objects in place. We do two |
281 |
|
joins therefore in reverse order to detect this: The first join |
282 |
|
will lead to a modified name in the column object of the right |
283 |
|
table which is then used as the left table in the second join so |
284 |
|
the underscored name will appear before the non-underscored one |
285 |
|
in the list of column names after the second join. |
286 |
|
""" |
287 |
|
mem1 = MemoryTable([("stretch_id", FIELDTYPE_INT), |
288 |
|
("name", FIELDTYPE_INT)], |
289 |
|
[(0, 10), (1, 11), (2, 12), (3, 13) ]) |
290 |
|
table1 = AutoTransientTable(self.transientdb, mem1) |
291 |
|
|
292 |
|
mem2 = MemoryTable([("stretch_id", FIELDTYPE_INT), |
293 |
|
("name", FIELDTYPE_INT)], |
294 |
|
[(0, 10), (1, 11), (2, 12), (3, 13) ]) |
295 |
|
table2 = AutoTransientTable(self.transientdb, mem2) |
296 |
|
|
297 |
|
table = TransientJoinedTable(self.transientdb, table1, "stretch_id", |
298 |
|
table2, "stretch_id", outer_join = True) |
299 |
|
table = TransientJoinedTable(self.transientdb, table2, "stretch_id", |
300 |
|
table1, "stretch_id", outer_join = True) |
301 |
|
|
302 |
|
self.assertEquals([c.name for c in table.Columns()], |
303 |
|
["stretch_id", "name", "stretch_id_", "name_"]) |
304 |
|
|
305 |
def test_transient_table_read_twice(self): |
def test_transient_table_read_twice(self): |
306 |
"""Test TransientTable.ReadRowAsDict() reading the same record twice""" |
"""Test TransientTable.ReadRowAsDict() reading the same record twice""" |