Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jul 31, 2017
1 parent 86389d1 commit 15ed34c
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/src/python/test_qgsproject.py
Expand Up @@ -28,7 +28,7 @@
QgsMapCanvas)

from qgis.PyQt.QtTest import QSignalSpy
from qgis.PyQt.QtCore import QT_VERSION_STR
from qgis.PyQt.QtCore import QT_VERSION_STR, QTemporaryFile
import sip

from qgis.testing import start_app, unittest
Expand Down Expand Up @@ -684,6 +684,48 @@ def testTakeLayer(self):
p = None
self.assertTrue(l1.isValid())

def test_zip_new_project(self):
tmpFile = QTemporaryFile()
tmpFile.open()
tmpFile.close()

# zip with existing file
project = QgsProject()
self.assertTrue(project.zip(tmpFile.fileName()))

# zip with non existing file
os.remove(tmpFile.fileName())

project = QgsProject()
self.assertTrue(project.zip(tmpFile.fileName()))
self.assertTrue(os.path.isfile(tmpFile.fileName()))

def test_zip_invalid_path(self):
project = QgsProject()
self.assertFalse(project.zip("/fake/test.zip"))
self.assertFalse(project.zip(""))

def test_zip_unzip(self):
tmpFile = QTemporaryFile()
tmpFile.open()
tmpFile.close()

project = QgsProject()

l0 = QgsVectorLayer(os.path.join(TEST_DATA_DIR, "points.shp"), "points", "ogr")
l1 = QgsVectorLayer(os.path.join(TEST_DATA_DIR, "lines.shp"), "lines", "ogr")
project.addMapLayers([l0, l1])

self.assertTrue(project.zip(tmpFile.fileName()))

project2 = QgsProject()
self.assertTrue(project2.unzip(tmpFile.fileName()))
layers = project2.mapLayers()

self.assertEqual(len(layers.keys()), 2)
self.assertTrue(layers[l0.id()].isValid(), True)
self.assertTrue(layers[l1.id()].isValid(), True)


if __name__ == '__main__':
unittest.main()

0 comments on commit 15ed34c

Please sign in to comment.