⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layertest.py

📁 Welcome to MS4W, the no fuss installer for setting up MapServer on Microsoft Windows platforms. The
💻 PY
📖 第 1 页 / 共 2 页
字号:
# $Id: layertest.py,v 1.22 2005/01/07 19:12:22 sean Exp $## Project:  MapServer# Purpose:  xUnit style Python mapscript tests of Layer# Author:   Sean Gillies, sgillies@frii.com## ===========================================================================# Copyright (c) 2004, Sean Gillies# # Permission is hereby granted, free of charge, to any person obtaining a# copy of this software and associated documentation files (the "Software"),# to deal in the Software without restriction, including without limitation# the rights to use, copy, modify, merge, publish, distribute, sublicense,# and/or sell copies of the Software, and to permit persons to whom the# Software is furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included# in all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER# DEALINGS IN THE SOFTWARE.# ===========================================================================## Execute this module as a script from mapserver/mapscript/python##     python tests/cases/layertest.py -v## ===========================================================================import os, sysimport unittest# the testing module helps us import the pre-installed mapscriptfrom testing import mapscriptfrom testing import MapTestCase# Base classclass MapLayerTestCase(MapTestCase):    def setUp(self):        MapTestCase.setUp(self)        self.layer = self.map.getLayer(1)# ===========================================================================# Test begins nowclass AlphaTransparencyTestCase(unittest.TestCase):        def testMSGDALPHA(self):        """test to make sure that no one has hidden ALPHA"""        assert mapscript.MS_GD_ALPHA == 1000class LayerConstructorTestCase(MapLayerTestCase):    def testLayerConstructorNoArg(self):        """test layer constructor with no argument"""        layer = mapscript.layerObj()        t = type(layer)        assert str(t) == "<class 'mapscript.layerObj'>", t        assert layer.thisown == 1        assert layer.index == -1        def testLayerConstructorMapArg(self):        """test layer constructor with map argument"""        layer = mapscript.layerObj(self.map)        t = type(layer)        assert str(t) == "<class 'mapscript.layerObj'>", t        assert layer.thisown == 1        assert str(layer) == str(self.map.getLayer(self.map.numlayers-1))     class LayerCloningTestCase(MapLayerTestCase):    def testLayerCloning(self):        """check attributes of a cloned layer"""        clone = self.layer.clone()        assert clone.thisown == 1        assert str(clone) != str(self.layer)        assert clone.name == self.layer.name        assert clone.numclasses == self.layer.numclasses        assert clone.map == None, clone.map        assert clone.data == self.layer.data        class LayerExtentTestCase(MapTestCase):       def setUp(self):        MapTestCase.setUp(self)        self.layer = self.map.getLayerByName('POLYGON')    def testPolygonExtent(self):        """retrieve the extent of a polygon layer"""        e = mapscript.rectObj()        self.assertRectsEqual(e, self.layer.extent)    def testPolygonGetExtent(self):        """retrieve the extent of a polygon layer"""        e = mapscript.rectObj(-0.25, 51.227222, 0.25, 51.727222)        self.assertRectsEqual(e, self.layer.getExtent())            def testGetPresetExtent(self):        """test layer.setExtent() and layer.getExtent() to return preset instead of calculating extents"""        r = mapscript.rectObj(1.0, 1.0, 3.0, 3.0)        self.layer.setExtent(r.minx, r.miny, r.maxx, r.maxy)        rect = self.layer.extent        assert r.minx == rect.minx, rect        assert r.miny == rect.miny, rect.miny        assert r.maxx == rect.maxx, rect.maxx        assert r.maxy == rect.maxy, rect.maxy            def testResetLayerExtent(self):        """test resetting a layer's extent"""        layer = self.map.getLayerByName('POLYGON')        layer.setExtent()        self.assertRectsEqual(layer.extent, mapscript.rectObj())    def testDirectExtentAccess(self):        """direct access to a layer's extent works properly"""        pt_layer = self.map.getLayerByName('POINT')        rect = pt_layer.extent        assert str(pt_layer.extent) == str(rect), (pt_layer.extent, rect)        e = mapscript.rectObj(-0.5, 51.0, 0.5, 52.0)        self.assertRectsEqual(e, rect)        class LayerRasterProcessingTestCase(MapLayerTestCase):        def testSetProcessing(self):        """setting a layer's processing directive works"""        self.layer.setProcessing('directive0=foo')        assert self.layer.numprocessing == 1, self.layer.numprocessing        self.layer.setProcessing('directive1=bar')        assert self.layer.numprocessing == 2, self.layer.numprocessing        directives = [self.layer.getProcessing(i) \                      for i in range(self.layer.numprocessing)]        assert directives == ['directive0=foo', 'directive1=bar']    def testClearProcessing(self):        """clearing a self.layer's processing directive works"""        self.layer.setProcessing('directive0=foo')        assert self.layer.numprocessing == 1, self.layer.numprocessing        self.layer.setProcessing('directive1=bar')        assert self.layer.numprocessing == 2, self.layer.numprocessing        assert self.layer.clearProcessing() == mapscript.MS_SUCCESSclass RemoveClassTestCase(MapLayerTestCase):    def testRemoveClass1NumClasses(self):        """RemoveClassTestCase.testRemoveClass1NumClasses: removing the layer's first class by index leaves one class left"""        c = self.layer.removeClass(0)        assert c.thisown == 1        assert self.layer.numclasses == 1        def testRemoveClass1ClassName(self):        """RemoveClassTestCase.testRemoveClass1ClassName: confirm removing the layer's first class reverts the name of the second class"""        c2name = self.layer.getClass(1).name        c = self.layer.removeClass(0)        assert self.layer.getClass(0).name == c2name        def testRemoveClass2NumClasses(self):        """RemoveClassTestCase.testRemoveClass2NumClasses: removing the layer's second class by index leaves one class left"""        c = self.layer.removeClass(1)        assert self.layer.numclasses == 1        def testRemoveClass2ClassName(self):        """RemoveClassTestCase.testRemoveClass2ClassName: confirm removing the layer's second class reverts the name of the first class"""        c1name = self.layer.getClass(0).name        c = self.layer.removeClass(1)        assert self.layer.getClass(0).name == c1nameclass InsertClassTestCase(MapLayerTestCase):    def testLayerInsertClass(self):        """insert class at default index"""        n = self.layer.numclasses        new_class = mapscript.classObj()        new_class.name = 'foo'        new_index = self.layer.insertClass(new_class)        assert new_index == n        assert self.layer.numclasses == n + 1        c = self.layer.getClass(new_index)        assert c.thisown == 0        assert c.name == new_class.name            def testLayerInsertClassAtZero(self):        """insert class at index 0"""        n = self.layer.numclasses        new_class = mapscript.classObj()        new_class.name = 'foo'        new_index = self.layer.insertClass(new_class, 0)        assert new_index == 0        assert self.layer.numclasses == n + 1        c = self.layer.getClass(new_index)        assert c.thisown == 0        assert c.name == new_class.name    def testInsertNULLClass(self):        """inserting NULL class should raise an error"""        self.assertRaises(mapscript.MapServerChildError,                          self.layer.insertClass, None)    class LayerTestCase(MapTestCase):    def testLayerConstructorOwnership(self):        """LayerTestCase.testLayerConstructorOwnership: newly constructed layer has proper ownership"""        layer = mapscript.layerObj(self.map)        assert layer.thisown == 1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -