/[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 1662 - (hide annotations)
Wed Aug 27 13:51:01 2003 UTC (21 years, 6 months ago) by bh
Original Path: trunk/thuban/test/test_memory_table.py
File MIME type: text/x-python
File size: 5434 byte(s)
Make the table interface distinguish between row ids (an integer
that uniquely identifies a row) and row ordinals (a simple row
count from 0 to NumRows() - 1)

* Thuban/Model/postgisdb.py (PostGISTable.RowIdToOrdinal)
(PostGISTable.RowOrdinalToId): New methods to conver between row
ids and row ordinals
(PostGISTable.ReadRowAsDict, PostGISTable.ReadValue): New keyword
parameter row_is_ordinal to indicate whether the row parameter is
the row id or the ordinal

* Thuban/Model/transientdb.py (TransientTableBase.RowIdToOrdinal)
(TransientTableBase.RowOrdinalToId)
(AutoTransientTable.RowIdToOrdinal)
(AutoTransientTable.RowOrdinalToId): Same new methods as in
PostGISTable.
(TransientTableBase.ReadRowAsDict, TransientTableBase.ReadValue)
(AutoTransientTable.ReadRowAsDict, AutoTransientTable.ReadValue):
Same new parameter as in PostGISTable.

* Thuban/Model/table.py (DBFTable.RowIdToOrdinal)
(DBFTable.RowOrdinalToId, MemoryTable.RowIdToOrdinal)
(MemoryTable.RowOrdinalToId): Same new methods as in PostGISTable.
(DBFTable.ReadValue, DBFTable.ReadRowAsDict)
(MemoryTable.ReadValue, MemoryTable.ReadRowAsDict): Same new
parameter as in PostGISTable.

* Thuban/UI/tableview.py (DataTable.RowIdToOrdinal)
(DataTable.RowOrdinalToId): New methods to convert between row ids
and row ordinals.
(TableGrid.SelectRowById): New method to select a row based on its
ID as opposed to its ordinal
(DataTable.GetValue, TableGrid.OnRangeSelect)
(TableGrid.OnSelectCell, LayerTableGrid.select_shapes)
(QueryTableFrame.OnQuery, QueryTableFrame.get_selected)
(LayerTableFrame.__init__): Convert between row ids and row
ordinals as appropriate

* test/postgissupport.py (PostGISDatabase.__init__): Add
doc-string.
(PostGISDatabase.initdb): The optional third item in a tuple in
tables is now a (key, value) list with additional arguments to
pass to upload_shapefile
(upload_shapefile): New parameter gid_offset to allow gids that
are not the same as the shapeids in the shapefile
(PostgreSQLServer.get_default_static_data_db): Use the new
gid_offset to make the gids in landmarks 1000 higher than the
shapeids in the shapefile

* test/test_viewport.py
(TestViewportWithPostGIS.test_find_shape_at_point): Adapt to the
new shapeids in the landmarks table

* test/test_transientdb.py
(TestTransientTable.run_iceland_political_tests)
(TestTransientTable.test_transient_joined_table): Add tests for
the new table methods and new keywords arguments.

* test/test_postgis_db.py
(TestPostGISTable.test_read_row_as_dict_row_count_mode)
(TestPostGISTable.test_read_value_row_count_mode)
(TestPostGISTable.test_row_id_to_ordinal)
(TestPostGISTable.test_row_oridnal_to_id): New test for the new
table methods and the new arguments
(TestPostGISShapestorePoint.test_shapes_in_region)
(TestPostGISShapestorePoint.test_shape_raw_data)
(TestPostGISShapestorePoint.test_shape_points)
(TestPostGISShapestorePoint.test_shape_shapeid)
(TestPostGISShapestorePoint.test_all_shapes)
(TestPostGISTable.test_simple_query)
(TestPostGISTable.test_simple_query)
(TestPostGISTable.test_simple_query)
(TestPostGISTable.test_read_value)
(TestPostGISTable.test_read_row_as_dict): Adapt to the new
shapeids in the landmarks table

* test/test_memory_table.py
(TestMemoryTable.test_read_row_as_dict_row_count_mode)
(TestMemoryTable.test_read_value_row_count_mode)
(TestMemoryTable.test_row_id_to_ordinal)
(TestMemoryTable.test_row_oridnal_to_id): New test for the new
table methods and the new arguments

* test/test_dbf_table.py
(TestDBFTable.test_read_row_as_dict_row_count_mode)
(TestDBFTable.test_read_value_row_count_mode)
(TestDBFTable.test_row_id_to_ordinal)
(TestDBFTable.test_row_oridnal_to_id): New test for the new table
methods and the new arguments

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 bh 1662 def test_read_row_as_dict_row_count_mode(self):
83     """Test MemoryTable.ReadRowAsDict() row count address mode"""
84     self.assertEquals(self.table.ReadRowAsDict(1, row_is_ordinal = 1),
85     {"type": "Foo", "value": 0.5, "code": -1})
86    
87 bh 818 def test_read_value(self):
88     """Test MemoryTable.ReadValue()"""
89     # The column in ReadValue may be given as either name or index
90     self.assertEquals(self.table.ReadValue(2, 0), "Foo")
91     self.assertEquals(self.table.ReadValue(3, "code"), 17)
92    
93 bh 1662 def test_read_value_row_count_mode(self):
94     """Test MemoryTable.ReadValue() row count address mode"""
95     # The column in ReadValue may be given as either name or index
96     self.assertEquals(self.table.ReadValue(2, 0, row_is_ordinal = 1),
97     "Foo")
98     self.assertEquals(self.table.ReadValue(3, "code", row_is_ordinal=1),
99     17)
100    
101     def test_row_id_to_ordinal(self):
102     """Test MemoryTable.RowIdToOrdinal()"""
103     self.assertEquals(self.table.RowIdToOrdinal(5), 5)
104    
105     def test_row_oridnal_to_id(self):
106     """Test MemoryTable.RowOrdinalToId()"""
107     self.assertEquals(self.table.RowOrdinalToId(5), 5)
108    
109 bh 818 def test_value_range(self):
110     """Test MemoryTable.ValueRange()"""
111     self.assertEquals(self.table.ValueRange("code"), (-1, 100))
112     self.assertEquals(self.table.ValueRange(1), (0, 1e10))
113    
114     def test_unique_values(self):
115     """Test MemoryTable.UniqueValues()"""
116     # The column can be specified by name or index
117     self.assertEquals(self.table.UniqueValues("type"),
118     ["Foo", "UNKNOWN", "bar"])
119     self.assertEquals(self.table.UniqueValues(2), [-1, 0, 17, 100])
120    
121     def test_write(self):
122     """Test MemoryTable.write_record()"""
123     # change only one field
124     # TODO: acticate when implemented
125     # table.write_record(2, {"type": "FARMS"})
126    
127     # check whether the table returns the new value
128     # TODO: acticate when implemented
129     #eq(table.read_record(2),
130     # {'type': "FARMS", "height": 400.44, "code": 2})
131    
132     # Check whether we can specify the record as a tuple
133     self.table.write_record(3, ("HUTS", 111.11, 42))
134 bh 839 self.assertEquals(self.table.ReadRowAsDict(3),
135 bh 818 {"type": "HUTS", "value": 111.11, "code": 42})
136    
137 bh 984 def test_dependencies(self):
138     """Test MemoryTable.Dependencies()"""
139     # A MemoryTable doesn't have dependencies
140     self.assertEquals(len(self.table.Dependencies()), 0)
141 bh 818
142 bh 998 def test_title(self):
143     """Test MemoryTable.Title()"""
144     self.assertEquals(self.table.Title(), "MemoryTable")
145 bh 818
146     if __name__ == "__main__":
147     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