test_qgis_environment.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding=utf-8
  2. """Tests for QGIS functionality.
  3. .. note:: This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. """
  8. __author__ = 'tim@linfiniti.com'
  9. __date__ = '20/01/2011'
  10. __copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
  11. 'Disaster Reduction')
  12. import os
  13. import unittest
  14. from qgis.core import (
  15. QgsProviderRegistry,
  16. QgsCoordinateReferenceSystem,
  17. QgsRasterLayer)
  18. from .utilities import get_qgis_app
  19. QGIS_APP = get_qgis_app()
  20. class QGISTest(unittest.TestCase):
  21. """Test the QGIS Environment"""
  22. def test_qgis_environment(self):
  23. """QGIS environment has the expected providers"""
  24. r = QgsProviderRegistry.instance()
  25. self.assertIn('gdal', r.providerList())
  26. self.assertIn('ogr', r.providerList())
  27. self.assertIn('postgres', r.providerList())
  28. def test_projection(self):
  29. """Test that QGIS properly parses a wkt string.
  30. """
  31. crs = QgsCoordinateReferenceSystem()
  32. wkt = (
  33. 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",'
  34. 'SPHEROID["WGS_1984",6378137.0,298.257223563]],'
  35. 'PRIMEM["Greenwich",0.0],UNIT["Degree",'
  36. '0.0174532925199433]]')
  37. crs.createFromWkt(wkt)
  38. auth_id = crs.authid()
  39. expected_auth_id = 'EPSG:4326'
  40. self.assertEqual(auth_id, expected_auth_id)
  41. # now test for a loaded layer
  42. path = os.path.join(os.path.dirname(__file__), 'tenbytenraster.asc')
  43. title = 'TestRaster'
  44. layer = QgsRasterLayer(path, title)
  45. auth_id = layer.crs().authid()
  46. self.assertEqual(auth_id, expected_auth_id)
  47. if __name__ == '__main__':
  48. unittest.main()