test_init.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # coding=utf-8
  2. """Tests QGIS plugin init."""
  3. __author__ = 'Tim Sutton <tim@linfiniti.com>'
  4. __revision__ = '$Format:%H$'
  5. __date__ = '17/10/2010'
  6. __license__ = "GPL"
  7. __copyright__ = 'Copyright 2012, Australia Indonesia Facility for '
  8. __copyright__ += 'Disaster Reduction'
  9. import os
  10. import unittest
  11. import logging
  12. import configparser
  13. LOGGER = logging.getLogger('QGIS')
  14. class TestInit(unittest.TestCase):
  15. """Test that the plugin init is usable for QGIS.
  16. Based heavily on the validator class by Alessandro
  17. Passoti available here:
  18. http://github.com/qgis/qgis-django/blob/master/qgis-app/
  19. plugins/validator.py
  20. """
  21. def test_read_init(self):
  22. """Test that the plugin __init__ will validate on plugins.qgis.org."""
  23. # You should update this list according to the latest in
  24. # https://github.com/qgis/qgis-django/blob/master/qgis-app/
  25. # plugins/validator.py
  26. required_metadata = [
  27. 'name',
  28. 'description',
  29. 'version',
  30. 'qgisMinimumVersion',
  31. 'email',
  32. 'author']
  33. file_path = os.path.abspath(os.path.join(
  34. os.path.dirname(__file__), os.pardir,
  35. 'metadata.txt'))
  36. LOGGER.info(file_path)
  37. metadata = []
  38. parser = configparser.ConfigParser()
  39. parser.optionxform = str
  40. parser.read(file_path)
  41. message = 'Cannot find a section named "general" in %s' % file_path
  42. assert parser.has_section('general'), message
  43. metadata.extend(parser.items('general'))
  44. for expectation in required_metadata:
  45. message = ('Cannot find metadata "%s" in metadata source (%s).' % (
  46. expectation, file_path))
  47. self.assertIn(expectation, dict(metadata), message)
  48. if __name__ == '__main__':
  49. unittest.main()