📄 symbolsettest.py
字号:
# $Id: symbolsettest.py,v 1.8.6.1 2006/01/16 20:01:56 sean Exp $## Project: MapServer# Purpose: xUnit style Python mapscript tests of SymbolSet# 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/symbolsettest.py -v## ===========================================================================import os, sysimport unittest# the testing module helps us import the pre-installed mapscriptfrom testing import mapscript, MapTestCase, TESTMAPFILE, XMARKS_IMAGESYMBOLSET = '../../../../tests/symbols.txt'# ===========================================================================# Test begins nowclass SymbolSetTestCase(unittest.TestCase): def testConstructorNoArgs(self): """new instance of symbolSetObj should have one symbol""" symbolset = mapscript.symbolSetObj() num = symbolset.numsymbols assert num == 1, num def testConstructorFile(self): """new instance of symbolSetObj from symbols.txt""" symbolset = mapscript.symbolSetObj(SYMBOLSET) num = symbolset.numsymbols assert num == 4, num def testAddSymbolToNewSymbolSet(self): """add two new symbols to a SymbolSet""" symbolset = mapscript.symbolSetObj(SYMBOLSET) symbola = mapscript.symbolObj('testa') symbolb = mapscript.symbolObj('testb') symbolset.appendSymbol(symbola) symbolset.appendSymbol(symbolb) num = symbolset.numsymbols assert num == 6, num names = [None, 'circle', 'xmarks-png', 'home-png', 'testa', 'testb'] for i in range(symbolset.numsymbols): symbol = symbolset.getSymbol(i) assert symbol.name == names[i], symbol.name def testRemoveSymbolFromNewSymbolSet(self): """after removing a symbol, expect numsymbols -= 1""" symbolset = mapscript.symbolSetObj(SYMBOLSET) symbolset.removeSymbol(1) num = symbolset.numsymbols assert num == 3, num def testSaveNewSymbolSet(self): """save a new SymbolSet to disk""" symbolset = mapscript.symbolSetObj(SYMBOLSET) symbola = mapscript.symbolObj('testa') symbolb = mapscript.symbolObj('testb') symbolset.appendSymbol(symbola) symbolset.appendSymbol(symbolb) assert symbolset.save('new_symbols.txt') == mapscript.MS_SUCCESS def testError(self): symbolset = mapscript.symbolSetObj(SYMBOLSET) symbola = mapscript.symbolObj('testa') symbolb = mapscript.symbolObj('testb') symbolset.appendSymbol(symbola) symbolset.appendSymbol(symbolb) self.assertRaises(mapscript.MapServerError, symbolset.save, '/bogus/new_symbols.txt')class MapSymbolSetTestCase(MapTestCase): def testGetNumSymbols(self): """expect getNumSymbols == 2 from test fixture test.map""" num = self.map.getNumSymbols() assert num == 4, num def testSymbolSetNumsymbols(self): """expect numsymbols == 2 from test fixture test.map""" num = self.map.symbolset.numsymbols assert num == 4, num def testSymbolSetSymbolNames(self): """test names of symbols in test fixture's symbolset""" set = self.map.symbolset names = [None, 'circle', 'xmarks-png', 'home-png'] for i in range(set.numsymbols): symbol = set.getSymbol(i) assert symbol.name == names[i], symbol.name def testSymbolIndex(self): """expect index of 'circle' symbol to be 1 in test fixture symbolset""" i = self.map.symbolset.index('circle') assert i == 1, i def testDrawNewSymbol(self): """draw using a new symbol added to the fixture""" symbol = mapscript.symbolObj('xmarks', XMARKS_IMAGE) symbol_index = self.map.symbolset.appendSymbol(symbol) assert symbol_index == 4, symbol_index num = self.map.symbolset.numsymbols assert num == 5, num inline_layer = self.map.getLayerByName('INLINE') s = inline_layer.getClass(0).getStyle(0) s.symbol = symbol_index #s.size = 24 msimg = self.map.draw() assert msimg.thisown == 1 data = msimg.saveToString() filename = 'testDrawNewSymbol.png' fh = open(filename, 'wb') fh.write(data) fh.close() # ===========================================================================# Run the tests outside of the main suiteif __name__ == '__main__': unittest.main()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -