/[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 839 - (hide annotations)
Tue May 6 15:54:18 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: 4161 byte(s)
Convert all table users to use the new table interface. This only
covers Thuban itself, not GREAT-ER or other applications built on
Thuban yet, so the compatibility interface stays in place for the
time being but it now issues DeprecationWarnings.

Finally, the new Table interface has a new method, HasColumn.

* Thuban/Model/table.py (OldTableInterfaceMixin): All methods
issue deprecation warnings when they're. The warnings refer to the
caller of the method.
(OldTableInterfaceMixin.__deprecation_warning): New. Helper method
for the deprecation warnings

* test/test_table.py: Ignore the deprecation warnings for the old
table in the tests in this module. The purpose of the tests is to
test the old interface, after all.

* test/test_transientdb.py
(TestTransientTable.run_iceland_political_tests): Use the
constants for the types. Add a test for HasColumn
(TestTransientTable.test_transient_joined_table): Adapt to new
table interface. Add a test for HasColumn
(TestTransientTable.test_transient_table_read_twice): Adapt to new
table interface

* Thuban/Model/transientdb.py (TransientTableBase.HasColumn)
(AutoTransientTable.HasColumn): Implement the new table interface
method
(AutoTransientTable.ReadRowAsDict, AutoTransientTable.ValueRange)
(AutoTransientTable.UniqueValues): Adapt to new table interface

* Thuban/Model/layer.py (Layer.SetShapeStore, Layer.GetFieldType):
Adapt to new table interface

* test/test_layer.py (TestLayer.open_shapefile): Helper method to
simplify opening shapefiles a bit easier.
(TestLayer.test_arc_layer, TestLayer.test_polygon_layer)
(TestLayer.test_point_layer): Use the new helper method
(TestLayer.test_get_field_type): New. Test for the GetFieldType
method

* test/test_dbf_table.py (TestDBFTable.test_has_column): Test for
the new table method

* test/test_memory_table.py (TestMemoryTable.test_has_column):
Test for the new table method HasColumn

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 bh 839 def test_has_column(self):
69     """Test MemoryTable.HasColumn()"""
70     # HasColumn
71     self.failUnless(self.table.HasColumn("value"))
72     self.failUnless(self.table.HasColumn(2))
73     # HasColumn for non-exisiting columns
74     self.failIf(self.table.HasColumn("non_existing_name"))
75     self.failIf(self.table.HasColumn(100))
76    
77 bh 818 def test_read_row_as_dict(self):
78     """Test MemoryTable.ReadRowAsDict()"""
79     self.assertEquals(self.table.ReadRowAsDict(1),
80     {"type": "Foo", "value": 0.5, "code": -1})
81    
82     def test_read_value(self):
83     """Test MemoryTable.ReadValue()"""
84     # The column in ReadValue may be given as either name or index
85     self.assertEquals(self.table.ReadValue(2, 0), "Foo")
86     self.assertEquals(self.table.ReadValue(3, "code"), 17)
87    
88     def test_value_range(self):
89     """Test MemoryTable.ValueRange()"""
90     self.assertEquals(self.table.ValueRange("code"), (-1, 100))
91     self.assertEquals(self.table.ValueRange(1), (0, 1e10))
92    
93     def test_unique_values(self):
94     """Test MemoryTable.UniqueValues()"""
95     # The column can be specified by name or index
96     self.assertEquals(self.table.UniqueValues("type"),
97     ["Foo", "UNKNOWN", "bar"])
98     self.assertEquals(self.table.UniqueValues(2), [-1, 0, 17, 100])
99    
100     def test_write(self):
101     """Test MemoryTable.write_record()"""
102     # change only one field
103     # TODO: acticate when implemented
104     # table.write_record(2, {"type": "FARMS"})
105    
106     # check whether the table returns the new value
107     # TODO: acticate when implemented
108     #eq(table.read_record(2),
109     # {'type': "FARMS", "height": 400.44, "code": 2})
110    
111     # Check whether we can specify the record as a tuple
112     self.table.write_record(3, ("HUTS", 111.11, 42))
113 bh 839 self.assertEquals(self.table.ReadRowAsDict(3),
114 bh 818 {"type": "HUTS", "value": 111.11, "code": 42})
115    
116    
117    
118     if __name__ == "__main__":
119     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