frank: thuban/test test_load.py,1.39,1.40

cvs@intevation.de cvs at intevation.de
Mon Dec 13 12:52:36 CET 2004


Author: frank

Update of /thubanrepository/thuban/test
In directory doto:/tmp/cvs-serv6169/test

Modified Files:
	test_load.py 
Log Message:
Alternative Path feature:
	* test/test_load.py (TestAltPath): New, tests for alternative path feature
	in load_session()
	(Shapefile_CallBack): Helper, implements controllable callback.

	* Thuban/UI/application.py (ThubanApplication.OnInit): 
	Added "alt_path" to self.path
	(ThubanApplication.OpenSession): Added shapefile_callback as second 
	callback similar to db_connection_callback.
	(ThubanApplication.run_alt_path_dialog): New, implementaion of
	shapefile_callback. In addition to raising the dialog the control of
	self.path('alt_path') is implemented here.

	* Thuban/Model/load.py (SessionLoader.__init__): Added shapefile_callback.
	(SessionLoader.open_shapefile): Open shapefile, eventually with 
	alternative path. This wrapps the "theSession.OpenShapefile(filename)" 
	formerly used in start_fileshapesource()/start_layer().
	(SessionLoader.start_fileshapesource): Call open_shapefile().
	(SessionLoader.start_layer): Call open_shapefile().
	(load_session): Added shapefile_callback.

	* Thuban/UI/altpathdialog.py: New, implements dialogs for alternative path
	feature (search / check).


Index: test_load.py
===================================================================
RCS file: /thubanrepository/thuban/test/test_load.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- test_load.py	3 Oct 2004 20:49:24 -0000	1.39
+++ test_load.py	13 Dec 2004 11:52:34 -0000	1.40
@@ -980,5 +980,120 @@
         else:
             self.fail("Missing filetype attribute doesn't raise LoadError")
 
+class Shapefile_CallBack:
+
+    def __init__(self, params):
+        """Initialize the callback return values.
+           
+           params must be a dictionary of the potential CB modes (keys), 
+           with lists of tuples of return values as values.
+           Depending on the test the callback can be called multiple, 
+           each time a return value is poped from the list
+        """
+
+        self.params = params
+
+
+    def s_cb(self, filename, mode = None, second_try= 0):
+        if self.params.has_key(mode):
+            return self.params[mode].pop(0)
+        else:
+            raise LoadError
+        
+class TestAltPath(LoadSessionTest):
+
+    """Test the various cases in the alternative path feature.
+
+       The test checks the reasonable cases:
+       - First recognition of a path error, fixed with user interaction.
+       - First recognition of a path error, load cancelled.
+       - Path error fixed from list, confirmed by user.
+       - Path error fixed from list, changed by user.
+       - Path error fixed from list, cancelled by user.
+       - Path error wrongly fixed from list, manual fix forced.
+    """
+
+    file_contents = '''\
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE session SYSTEM "thuban-1.1.dtd">
+<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">
+    <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>
+    <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>
+    <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>
+    <map title="not the iceland map">
+        <layer title="political" stroke_width="1" shapestore="D1108450956" visible="true" stroke="#000000" fill="#c0c0c0"/>
+        <layer title="roads-line" stroke_width="1" shapestore="D1108900076" visible="true" stroke="#000000" fill="None"/>
+        <layer title="something else" stroke_width="1" shapestore="D1108947244" visible="true" stroke="#000000" fill="None"/>
+    </map>
+</session>
+'''
+
+    def test_01_single_path_error_fix(self):
+        """Test single file path error fix."""
+        # The usual initial case
+        s_cb = Shapefile_CallBack({
+                    "search": [("../Data/iceland/roads-line.shp",0)], 
+                    "check": [(None, None)]})
+        self.session = load_session(self.filename(), 
+                                    shapefile_callback =s_cb.s_cb)
+        self.session.Destroy()
+        self.session = None
+
+    def test_02_path_error_fix_from_list(self):
+        """Test single file path error fix."""
+        # This represents the usual case for "from_list" 
+        s_cb = Shapefile_CallBack({
+                "search": [("../Data/iceland/roads-line.shp",1)], 
+                "check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)]
+               })
+        self.session = load_session(self.filename(), 
+                                    shapefile_callback =s_cb.s_cb)
+        self.session.Destroy()
+        self.session = None
+
+    def test_03_single_path_error_cancelled(self):
+        """Test alternative path cancelled."""
+        s_cb = Shapefile_CallBack({
+                    "search": [(None,0)], 
+                    "check": [(None, None)]})
+        self.assertRaises(LoadCancelled, 
+                            load_session, self.filename(), None, s_cb.s_cb)
+
+    def test_04_path_error_fix_from_list_cancelled(self):
+        """Test alternative path from list cancelled."""
+        s_cb = Shapefile_CallBack({
+                "search": [("../Data/iceland/roads-line.shp",1)], 
+                "check": [(None,1)]
+               })
+        self.assertRaises(LoadCancelled, 
+                            load_session, self.filename(), None, s_cb.s_cb)
+
+    def test_05_path_error_fix_from_list_changed(self):
+        """Test alternative path from list changed."""
+        s_cb = Shapefile_CallBack({
+                "search": [("../Data/iceland/roads-line.shp",1)], 
+                "check": [("../Data/iceland/roads-line.shp",0)]
+               })
+        self.session = load_session(self.filename(), 
+                                    shapefile_callback =s_cb.s_cb)
+        self.session.Destroy()
+        self.session = None
+
+    def test_06_path_error_fix_from_list_fails(self):
+        """Test alternative path recovery from list."""
+        s_cb = Shapefile_CallBack({
+                "search": [("../wrong/iceland/roads-line.shp",1),
+                            ("../Data/iceland/roads-line.shp",0)], 
+                "check": [(None,None)]
+               })
+        self.session = load_session(self.filename(), 
+                                    shapefile_callback =s_cb.s_cb)
+        self.assertRaises(IndexError, 
+                            s_cb.s_cb, None, "search")
+        
+        self.session.Destroy()
+        self.session = None
+
+
 if __name__ == "__main__":
     support.run_tests()





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)