本文整理汇总了Python中utilities.unitTestDataPath函数的典型用法代码示例。如果您正苦于以下问题:Python unitTestDataPath函数的具体用法?Python unitTestDataPath怎么用?Python unitTestDataPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unitTestDataPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zip_input_file_not_exist
def test_zip_input_file_not_exist(self):
f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
f1 = os.path.join(unitTestDataPath(), 'fake.shp')
f2 = os.path.join(unitTestDataPath(), 'joins.qgs')
rc = QgsZipUtils.zip(tmpPath(), [f0, f1, f2])
self.assertFalse(rc)
示例2: testEmbedding
def testEmbedding(self):
"""Test embedding large SVGs """
w = QgsImageSourceLineEdit()
spy = QSignalSpy(w.sourceChanged)
w.setSource('source')
self.assertEqual(w.source(), 'source')
self.assertEqual(len(spy), 1)
self.assertEqual(spy[0][0], 'source')
b64 = 'base64:' + ''.join(['x'] * 1000000)
w.setSource(b64)
self.assertEqual(w.source(), b64)
self.assertEqual(len(spy), 2)
self.assertEqual(spy[1][0], b64)
w.setSource(os.path.join(unitTestDataPath(), 'landsat.tif'))
self.assertEqual(w.source(), os.path.join(unitTestDataPath(), 'landsat.tif'))
self.assertEqual(len(spy), 3)
self.assertEqual(spy[2][0], os.path.join(unitTestDataPath(), 'landsat.tif'))
w.setSource(b64)
self.assertEqual(w.source(), b64)
self.assertEqual(len(spy), 4)
self.assertEqual(spy[3][0], b64)
w.setSource('')
self.assertEqual(w.source(), '')
self.assertEqual(len(spy), 5)
self.assertEqual(spy[4][0], '')
示例3: test_zip_file_empty
def test_zip_file_empty(self):
f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
f1 = os.path.join(unitTestDataPath(), 'lines.shp')
f2 = os.path.join(unitTestDataPath(), 'joins.qgs')
rc = QgsZipUtils.zip("", [f0, f1, f2])
self.assertFalse(rc)
示例4: setUpClass
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
cls.port = QGIS_SERVER_ENDPOINT_PORT
# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
for ev in env_vars:
try:
del os.environ[ev]
except KeyError:
pass
cls.testdata_path = unitTestDataPath('qgis_server')
cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'), 'certs_keys')
cls.project_path = os.path.join(cls.testdata_path, "test_project.qgs")
# cls.hostname = 'localhost'
cls.protocol = 'https'
cls.hostname = '127.0.0.1'
cls.setUpAuth()
server_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'qgis_wrapped_server.py')
cls.server = subprocess.Popen([sys.executable, server_path],
env=os.environ, stdout=subprocess.PIPE)
line = cls.server.stdout.readline()
cls.port = int(re.findall(b':(\d+)', line)[0])
assert cls.port != 0
# Wait for the server process to start
assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
示例5: test_zip_ok
def test_zip_ok(self):
f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
f1 = os.path.join(unitTestDataPath(), 'lines.shp')
f2 = os.path.join(unitTestDataPath(), 'joins.qgs')
rc = QgsZipUtils.zip(tmpPath(), [f0, f1, f2])
self.assertTrue(rc)
示例6: setUpClass
def setUpClass(cls):
"""Run before all tests"""
cls.port = QGIS_SERVER_WFST_DEFAULT_PORT
cls.testdata_path = unitTestDataPath('wfs_transactional') + '/'
# Create tmp folder
cls.temp_path = tempfile.mkdtemp()
cls.testdata_path = cls.temp_path + '/' + 'wfs_transactional' + '/'
copytree(unitTestDataPath('wfs_transactional') + '/',
cls.temp_path + '/' + 'wfs_transactional')
cls.project_path = cls.temp_path + '/' + 'wfs_transactional' + '/' + \
'wfs_transactional.qgs'
assert os.path.exists(cls.project_path), "Project not found: %s" % \
cls.project_path
# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
for ev in env_vars:
try:
del os.environ[ev]
except KeyError:
pass
# Clear all test layers
for ln in ['test_point', 'test_polygon', 'test_linestring']:
cls._clearLayer(ln)
os.environ['QGIS_SERVER_DEFAULT_PORT'] = str(cls.port)
server_path = os.path.dirname(os.path.realpath(__file__)) + \
'/qgis_wrapped_server.py'
cls.server = subprocess.Popen(['python', server_path],
env=os.environ)
sleep(2)
示例7: setUp
def setUp(self):
"""Create the server instance"""
self.testdata_path = unitTestDataPath('qgis_server') + '/'
d = unitTestDataPath('qgis_server_accesscontrol') + '/'
self.projectPath = os.path.join(d, "project.qgs")
# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
for ev in env_vars:
try:
del os.environ[ev]
except KeyError:
pass
self.server = QgsServer()
示例8: test_zip_file_yet_exist
def test_zip_file_yet_exist(self):
zip = QTemporaryFile()
zip.open()
zip.close()
os.remove(zip.fileName())
f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
f1 = os.path.join(unitTestDataPath(), 'lines.shp')
f2 = os.path.join(unitTestDataPath(), 'joins.qgs')
rc = QgsZipUtils.zip(zip.fileName(), [f0, f1, f2])
self.assertTrue(rc)
rc = QgsZipUtils.zip(zip.fileName(), [f0, f1, f2])
self.assertFalse(rc)
示例9: test_zip_unzip_ok
def test_zip_unzip_ok(self):
zip = tmpPath()
f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
f1 = os.path.join(unitTestDataPath(), 'lines.shp')
f2 = os.path.join(unitTestDataPath(), 'joins.qgs')
rc = QgsZipUtils.zip(zip, [f0, f1, f2])
self.assertTrue(rc)
outDir = QTemporaryDir()
rc, files = QgsZipUtils.unzip(zip, outDir.path())
self.assertTrue(rc)
self.assertEqual(len(files), 3)
示例10: testOneBandRaster
def testOneBandRaster(self):
path = os.path.join(unitTestDataPath('raster'),
'band1_float32_noct_epsg4326.tif')
info = QFileInfo(path)
base_name = info.baseName()
layer = QgsRasterLayer(path, base_name)
self.assertTrue(layer)
combo = QgsRasterBandComboBox()
combo.setLayer(layer)
self.assertEqual(combo.layer(), layer)
self.assertEqual(combo.currentBand(), 1)
self.assertEqual(combo.count(), 1)
combo.setShowNotSetOption(True)
self.assertEqual(combo.currentBand(), 1)
self.assertEqual(combo.count(), 2)
combo.setBand(-1)
self.assertEqual(combo.currentBand(), -1)
combo.setBand(1)
self.assertEqual(combo.currentBand(), 1)
combo.setShowNotSetOption(False)
self.assertEqual(combo.currentBand(), 1)
self.assertEqual(combo.count(), 1)
示例11: testQgsSVGFillSymbolLayer
def testQgsSVGFillSymbolLayer(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsSVGFillSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsSVGFillSymbolLayer.createFromSld(
mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())
mExpectedValue = type(QgsSVGFillSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 'accommodation_camping.svg'
mValue = os.path.basename(mSymbolLayer.svgFilePath())
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 6
mValue = mSymbolLayer.patternWidth()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
示例12: testQgsSvgMarkerSymbolLayer
def testQgsSvgMarkerSymbolLayer(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsSvgMarkerSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsSvgMarkerSymbolLayer.createFromSld(mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())
mExpectedValue = type(QgsSvgMarkerSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 'skull.svg'
mValue = os.path.basename(mSymbolLayer.path())
print(("VALUE", mSymbolLayer.path()))
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 12
mValue = mSymbolLayer.size()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 45
mValue = mSymbolLayer.angle()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
示例13: testSelectByIds
def testSelectByIds(self):
""" Test selecting by ID"""
layer = QgsVectorLayer(os.path.join(unitTestDataPath(), 'points.shp'), 'Points', 'ogr')
# SetSelection
layer.selectByIds([1, 3, 5, 7], QgsVectorLayer.SetSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 3, 5, 7]))
# check that existing selection is cleared
layer.selectByIds([2, 4, 6], QgsVectorLayer.SetSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 4, 6]))
# AddToSelection
layer.selectByIds([3, 5], QgsVectorLayer.AddToSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 4, 5, 6]))
layer.selectByIds([1], QgsVectorLayer.AddToSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 2, 3, 4, 5, 6]))
# IntersectSelection
layer.selectByIds([1, 3, 5, 6], QgsVectorLayer.IntersectSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 3, 5, 6]))
layer.selectByIds([1, 2, 5, 6], QgsVectorLayer.IntersectSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 5, 6]))
# RemoveFromSelection
layer.selectByIds([2, 6, 7], QgsVectorLayer.RemoveFromSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 5]))
layer.selectByIds([1, 5], QgsVectorLayer.RemoveFromSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([]))
示例14: testSelectByRect
def testSelectByRect(self):
""" Test selecting by rectangle """
layer = QgsVectorLayer(os.path.join(unitTestDataPath(), 'points.shp'), 'Points', 'ogr')
# SetSelection
layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.SetSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 7, 10, 11, 15]))
# check that existing selection is cleared
layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.SetSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
# SetSelection no matching
layer.selectByRect(QgsRectangle(112, 30, 115, 45), QgsVectorLayer.SetSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([]))
# AddToSelection
layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.AddToSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
layer.selectByRect(QgsRectangle(-112, 37, -94, 45), QgsVectorLayer.AddToSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 7, 10, 11, 15]))
# IntersectSelection
layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.IntersectSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
layer.selectByIds([2, 10, 13])
layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.IntersectSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 10]))
# RemoveFromSelection
layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.SetSelection)
layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.RemoveFromSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([7, 11]))
layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.RemoveFromSelection)
self.assertEqual(set(layer.selectedFeaturesIds()), set([]))
示例15: testSetDataSource
def testSetDataSource(self):
"""Test change data source"""
temp_dir = QTemporaryDir()
options = QgsDataProvider.ProviderOptions()
myPath = os.path.join(unitTestDataPath('raster'),
'band1_float32_noct_epsg4326.tif')
myFileInfo = QFileInfo(myPath)
myBaseName = myFileInfo.baseName()
layer = QgsRasterLayer(myPath, myBaseName)
renderer = QgsSingleBandGrayRenderer(layer.dataProvider(), 2)
image = layer.previewAsImage(QSize(400, 400))
self.assertFalse(image.isNull())
self.assertTrue(image.save(os.path.join(temp_dir.path(), 'expected.png'), "PNG"))
layer.setDataSource(myPath.replace('4326.tif', '4326-BAD_SOURCE.tif'), 'bad_layer', 'gdal', options)
self.assertFalse(layer.isValid())
image = layer.previewAsImage(QSize(400, 400))
self.assertTrue(image.isNull())
layer.setDataSource(myPath.replace('4326-BAD_SOURCE.tif', '4326.tif'), 'bad_layer', 'gdal', options)
self.assertTrue(layer.isValid())
image = layer.previewAsImage(QSize(400, 400))
self.assertFalse(image.isNull())
self.assertTrue(image.save(os.path.join(temp_dir.path(), 'actual.png'), "PNG"))
self.assertTrue(filecmp.cmp(os.path.join(temp_dir.path(), 'actual.png'), os.path.join(temp_dir.path(), 'expected.png')), False)