jschuengel: thuban/Extensions/umn_mapserver/test test_mapserver.py, 1.2, 1.3

cvs@intevation.de cvs at intevation.de
Thu Jul 8 16:29:51 CEST 2004


Author: jschuengel

Update of /thubanrepository/thuban/Extensions/umn_mapserver/test
In directory doto:/tmp/cvs-serv25088/test

Modified Files:
	test_mapserver.py 
Log Message:
Added new test for most of the new setting which were added during the last changes.
Removed the MF_Size Test.


Index: test_mapserver.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/test/test_mapserver.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_mapserver.py	16 Jun 2004 10:52:01 -0000	1.2
+++ test_mapserver.py	8 Jul 2004 14:29:49 -0000	1.3
@@ -23,10 +23,14 @@
 # Import  necessary classes from Thuban
 from Thuban.Model.color import Color, Transparent
 
+from Thuban.Model.proj import Projection
+
 # Import the Classes to test
 from Extensions.umn_mapserver.mapfile import MF_Color, \
-    MF_Rectangle, MF_Size, MF_Style, MF_Map, MF_Projection, \
-    MF_Class, MF_Layer
+    MF_Rectangle, MF_Style, MF_Map, MF_Projection, \
+    MF_Class, MF_Layer, MF_Metadata, MF_Outputformat, \
+    MF_Symbol, MF_SymbolSet, MF_Scalebar, \
+    MF_Label, MF_Legend, MF_Web
 
 from Extensions.umn_mapserver.mapfile import shp_type
 
@@ -35,141 +39,280 @@
 testMap = mapObj(testMapfile)
 
 
-class mapserver_import_Test_generalClasses(unittest.TestCase):
+class mapserver_generalClasses(unittest.TestCase):
+
+    def setUp(self):
+        """
+        Running this funktion befor each test
+        """
+        self.eq = self.assertEquals
+
 
     def test_MF_Color(self):
         """
         Testing Color Objects from MapServer.
         """
-        eq = self.assertEquals
-        
         # IMAGECOLOR  255 255 255
         testcolor = MF_Color(testMap.imagecolor)        
-        eq(testcolor.get_red(), 255)
-        eq(testcolor.get_green(), 255)
-        eq(testcolor.get_blue(), 255)
+        self.eq(testcolor.get_red(), 255)
+        self.eq(testcolor.get_green(), 255)
+        self.eq(testcolor.get_blue(), 255)
         
         # set Color with Thuban color obj
         testthubancolor = Color(0.5,1,0)
         testcolor.set_thubancolor(testthubancolor)
-        eq(testcolor.get_red(),127)
-        eq(testcolor.get_green(),255)
-        eq(testcolor.get_blue(),0)
+        self.eq(testcolor.get_red(),127)
+        self.eq(testcolor.get_green(),255)
+        self.eq(testcolor.get_blue(),0)
         
         # check if Thubancolor is set correct
         testtbcolor = testcolor.get_thubancolor()
-        eq(testtbcolor.red, 0.5)
-        eq(testtbcolor.green, 1)
-        eq(testtbcolor.blue, 0)
-    
-    
+        self.eq(testtbcolor.red, 0.5)
+        self.eq(testtbcolor.green, 1)
+        self.eq(testtbcolor.blue, 0)
+
+
     def test_MF_Rectangle(self):
         """
         Testing rectangle objects by example like
         the mapfile parameter extent.
         """
-        eq = self.assertEquals
-        
         # EXTENT  622877.17 7019306.94 1095667.78 7447709.31 
         testrect = MF_Rectangle(testMap.extent)        
-        eq(testrect.get_minx(), 622877.17)
-        eq(testrect.get_miny(), 7019306.94)
-        eq(testrect.get_maxx(), 1095667.78)
-        eq(testrect.get_maxy(), 7447709.31)
-   
-    def test_MF_Size(self):
+        self.eq(testrect.get_minx(), 622877.17)
+        self.eq(testrect.get_miny(), 7019306.94)
+        self.eq(testrect.get_maxx(), 1095667.78)
+        self.eq(testrect.get_maxy(), 7447709.31)
+        
+        # Set a new Rectangle and test if is set correctly
+        testrect.set_rect(50,50,200,200)
+        self.eq(testrect.get_rect(), (50,50,200,200))
+        self.eq(testrect.get_minx(), 50)
+        self.eq(testrect.get_miny(), 50)
+        self.eq(testrect.get_maxx(), 200)
+        self.eq(testrect.get_maxy(), 200)
+
+
+    def test_MF_Metadata(self):
         """
-        Testing size object by an example parameter.
+        Testing the meta data
         """
-        eq = self.assertEquals
+        # set up to keys to test
+        testmetadata = MF_Metadata()
+        self.eq(testMap.getMetaData("titel"), "Iceland Test")
+        testmetadata.add_metadata("test", "test eintrag")
+        self.eq(testmetadata.get_metadatabykey("test"),"test eintrag")
         
-        # SIZE  600 450
-        testsize = MF_Size(testMap.width, testMap.height)
-        eq(testsize.get_width(), 600)
-        eq(testsize.get_height(), 450)
-    
-    # TODO:
-    #def test_MF_Metadata(self):
+        # generate the MetaData from the testMap
+        testMap2 = MF_Map(testMap)
+        testmetadata = testMap2.get_metadata()
+        self.eq(testmetadata.get_metadatabykey("titel"),"Iceland Test")
 
-class mapserver_import_Test(unittest.TestCase):
 
-    def test_MF_Class(self):
+class mapserver_Classes(unittest.TestCase):
+
+    def setUp(self):
         """
-        Testing the class object.
+        Running this funktion befor each test
         """
+        self.eq = self.assertEquals
+
+
+    def test_MF_OutputFormat(self):
+        """
+        Testing the outputformat object
+        """
+        testoutputformat = MF_Outputformat(testMap.getOutputFormatByName("png"))
+        self.eq(testoutputformat.get_name(),"png")
+
+
+    def test_MF_Symbolset(self):
+        """
+        Testing the symbolset
+        """
+        testsymbolset = MF_SymbolSet(testMap.symbolset)
+        self.eq(testsymbolset.get_symbol(1).get_name(), "circle") 
+
+
+    def test_MF_Symbol(self):
+        """
+        Testing the symbol object
+        """
+        testsymbol = MF_Symbol(testMap.symbolset.getSymbolByName("circle"))
+        self.eq(testsymbol.get_name(), "circle")
+        assert(testsymbol.get_symbolObj(), testMap.symbolset.getSymbolByName("circle"))
         
-        eq = self.assertEquals
+        testsymbol.set_filled(True)
+        self.eq(testsymbol.get_filled(), True)
         
+        testsymbol.set_type(4)
+        self.eq(testsymbol.get_type(), 4)
+
+
+    def test_MF_Class(self):
+        """
+        Testing the class object.
+        """        
         # only test the number of styles at the moment
         testclass = MF_Class(testMap.getLayer(0).getClass(0))
-        eq (len(testclass.get_styles()), testMap.getLayer(0).getClass(0).numstyles)
-    
-    
+        self.eq (len(testclass.get_styles()), testMap.getLayer(0).getClass(0).numstyles)
+
+        # check the name
+        self.eq(testclass.get_name(), "testclass")
+        testclass.set_name("checkout")
+        self.eq(testclass.get_name(), "checkout")
+
+        # check the expressionstring
+        testclass = MF_Class(testMap.getLayer(2).getClass(0))
+        self.eq(testclass.get_expressionstring(), '"9"')
+        testclass.set_expressionstring("3")
+        self.eq(testclass.get_expressionstring(), '"3"')
+
+
     def test_MF_Layer(self):
         """
         Testing the layer object with some
         sample data and classes.
         """
-        
-        eq = self.assertEquals
-        
-        testlayer = MF_Layer(testMap.getLayer(0))
+        testlayer = MF_Layer(testMap.getLayer(2))
         # NAME 'political' only from layer 1
-        eq(testlayer.get_name(), 'political')
+        self.eq(testlayer.get_name(), 'cultural')
+        testlayer.set_name('checkout')
+        self.eq(testlayer.get_name(), 'checkout')        
         # check number of classes
-        eq(len(testlayer.get_classes()), testMap.getLayer(0).numclasses)
+        self.eq(len(testlayer.get_classes()), testMap.getLayer(2).numclasses)
+        # check classitem
+        self.eq(testlayer.get_classitem(), "CLPOINT_")
+        testlayer.set_classitem("CLCHECK")
+        self.eq(testlayer.get_classitem(), "CLCHECK")
+        # check data
+        self.eq(testlayer.get_data(), "cultural_landmark-point")
+        testlayer.set_data("test.shp")
+        # .shp will be cutted becouse the source is always a .shp,
+        # or maybe a grafik
+        self.eq(testlayer.get_data(), "test")
+        # check projection (used the pojection obj a little bit)
+        self.eq(testlayer.get_projection().get_projection(), "+proj=latlong+ellps=clrk66")
         # TYPE POLYGON
-        eq(testlayer.get_type(), 'polygon')
-        
-    
+        self.eq(testlayer.get_type(), "point")
+        testlayer.set_type("circle")
+        self.eq(testlayer.get_type(), "circle")
+        # Check status
+        # 0 = off, 1 = on, 2 = default
+        self.eq(testlayer.get_status(), True)
+        testlayer.set_status(False)
+        self.eq(testlayer.get_status(), False)
+
+
     def test_MF_Map(self):
         """
         Testing the mapfile object with samples.
         """
-        eq = self.assertEquals
-        
         testmap = MF_Map(testMap)
         # NAME 'ISLAND'
-        eq(testmap.get_name(), 'ISLAND')
-        eq(len(testmap.get_layers()), testMap.numlayers)
+        self.eq(testmap.get_name(), 'ISLAND')
+        self.eq(len(testmap.get_layers()), testMap.numlayers)
+    
+        testmapfile = mapObj("")
+        newtestmap = MF_Map(testmapfile)
+        # proj=utm
+        # ellps=clrk66
+        # zone=26
+        # north
+        # test see in test_MF_Projection
+        testproj = Projection(['proj=utm', 'ellps=clrk66', 'zone=26', 'north'])
+        newtestmap.set_projection(testproj)
+        self.eq(testmapfile.getProjection(), "+proj=utm+ellps=clrk66+zone=26+north")
+        self.eq(newtestmap.get_projection().get_params(), ['proj=utm', 'ellps=clrk66', 'zone=26', 'north'])
         
-       
+        self.eq(testmap.get_size(), (600,450))
+        testmap.set_size(500,600)
+        self.eq(testmap.get_size(), (500,600))
+
+
+    def test_MF_Scalebar(self):
+        """
+        Test the Scalebarobj from the testfile
+        """
+        testscalebar = MF_Scalebar(testMap.scalebar)
+        self.eq(testscalebar.get_position(mode="string"),"ll")
+        self.eq(testscalebar.get_position(), 3)
+        self.eq(testscalebar.get_intervals(), 4)
+        self.eq(testscalebar.get_status(mode="string"), "OFF")
+
+
+    def test_MF_Label(self):
+        """
+        Test a Label object. In this test use the Label from 
+        from the Scalebarobj in the testfile
+        """
+        testlabel = MF_Label(testMap.scalebar.label)
+        self.eq(testlabel.get_force(), False)
+        self.eq(testlabel.get_buffer(),0)
+        self.eq(testlabel.get_type(), "bitmap") 
+
+
+    def test_MF_Legend(self):
+        """
+        test the legend object from the testfile
+        """
+        testlegend = MF_Legend(testMap.legend)
+        self.eq(testlegend.get_status(), False)
+        testlegend.set_status(True)
+        self.eq(testlegend.get_status(), True)
+        testlegend.set_position("ul")
+        self.eq(testlegend.get_position(mode="string"), "ul")
+        testlegend.set_keyspacing(4,5)
+        self.eq(testlegend.get_keyspacing(), (4,5))
+        testlegend.set_keysize(6,7)
+        self.eq(testlegend.get_keysize(), (6,7))
+
+
     def test_MF_Projection(self):
         """
         Projection object is tested with parameters
         and an epsg code.
         """
-        eq = self.assertEquals
-
         # proj=utm
         # ellps=clrk66
         # zone=26
         # north
         testproj = MF_Projection(testMap.getProjection())
         if testproj.get_params():
-            eq(testproj.get_params(), ['proj=utm','ellps=WGS84','zone=26','north']) 
+            self.eq(testproj.get_params(), ['proj=utm','ellps=WGS84','zone=26','north']) 
         
         #"init=epsg:26915"
         if testproj.get_epsgcode():
-            eq(testproj.get_epsgcode(), '26915') 
+            self.eq(testproj.get_epsgcode(), '26915') 
 
 
     def test_MF_Style(self):
         """
         Tests a style object with all parameters.
         """
-        eq = self.assertEquals
-        
         teststyle = MF_Style(testMap.getLayer(0).getClass(0).getStyle(0))
         # OUTLINECOLOR 0 0 0
-        eq(teststyle.get_outlinecolor().get_red(), 0)
+        self.eq(teststyle.get_outlinecolor().get_red(), 0)
         # COLOR 100 200 100
-        eq(teststyle.get_color().get_red(), 100)
-        eq(teststyle.get_color().get_green(), 200)
-        eq(teststyle.get_color().get_blue(), 100)
+        self.eq(teststyle.get_color().get_red(), 100)
+        self.eq(teststyle.get_color().get_green(), 200)
+        self.eq(teststyle.get_color().get_blue(), 100)
         # SIZE 2
-        eq(teststyle.get_size(), 2)
+        self.eq(teststyle.get_size(), 2)
+
+
+    def test_MF_Web(self):
+        """
+        Tests a web object
+        """
+        testweb = MF_Web(testMap.web)
+        self.eq(testweb.get_imagepath(), "/tmpimg/")
+        testweb.set_imagepath("/tmppathset/")
+        self.eq(testweb.get_imagepath(), "/tmppathset/")
+        self.eq(testweb.get_imageurl(),"/tmpurl/")
+        testweb.set_imageurl("/tmpurlset/")
+        self.eq(testweb.get_imageurl(), "/tmpurlset/")
+
 
-    
 if __name__ == '__main__':
     unittest.main()





More information about the Thuban-devel mailing list

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