/[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 998 - (hide annotations)
Thu May 22 19:29:39 2003 UTC (21 years, 9 months ago) by bh
Original Path: trunk/thuban/test/test_memory_table.py
File MIME type: text/x-python
File size: 4477 byte(s)
Give the tables titles so that the GUI can display more meaningful
names. For now the titles are fixed but depend on e.g. filenames
or the titles of the joined tables.

* Thuban/Model/transientdb.py (TransientTable.Title)
(TransientJoinedTable.Title, AutoTransientTable.Title): New.

* Thuban/Model/table.py (DBFTable.Title, MemoryTable.Title): New.

* test/test_transientdb.py
(TestTransientTable.test_auto_transient_table_title): New. Test
for the Title method
(TestTransientTable.test_transient_joined_table)
(TestTransientTable.test_transient_table): Add test for the Title
methods

* test/test_memory_table.py (TestMemoryTable.test_title): New.
Test for the Title method

* test/test_dbf_table.py (TestDBFTable.test_title): New. Test for
the Title method

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 bh 984 def test_dependencies(self):
117     """Test MemoryTable.Dependencies()"""
118     # A MemoryTable doesn't have dependencies
119     self.assertEquals(len(self.table.Dependencies()), 0)
120 bh 818
121 bh 998 def test_title(self):
122     """Test MemoryTable.Title()"""
123     self.assertEquals(self.table.Title(), "MemoryTable")
124 bh 818
125     if __name__ == "__main__":
126     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