test_addons_modules.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """
  2. TEST: test_addons_modules.py
  3. AUTHOR(S): Vaclav Petras <wenzeslaus gmail com>
  4. PURPOSE: Test for g.extension individual modules/extensions handling
  5. COPYRIGHT: (C) 2015 Vaclav Petras, and by the GRASS Development Team
  6. This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. from grass.gunittest.main import test
  12. from grass.gunittest.gmodules import SimpleModule
  13. from grass.gunittest.utils import silent_rmtree
  14. import os
  15. MODULES_OUTPUT = """\
  16. d.frame
  17. d.mon2
  18. g.copyall
  19. g.isis3mt
  20. g.proj.all
  21. r.gdd
  22. r.geomorphon
  23. r.le.patch
  24. r.le.pixel
  25. r.traveltime
  26. r.univar2
  27. v.civil
  28. v.class.ml
  29. v.class.mlpy
  30. v.colors2
  31. v.delaunay3d
  32. v.ellipse
  33. v.in.proj
  34. v.in.redwg
  35. v.neighborhoodmatrix
  36. v.transects
  37. wx.metadata
  38. """.replace('\n', os.linesep)
  39. class TestModulesMetadata(TestCase):
  40. url = 'file://' + os.path.abspath('data')
  41. def test_listing(self):
  42. """List individual extensions/modules/addons"""
  43. module = SimpleModule('g.extension', flags='l', url=self.url)
  44. self.assertModule(module)
  45. stdout = module.outputs.stdout
  46. self.assertMultiLineEqual(stdout, MODULES_OUTPUT)
  47. class TestModulesFromDifferentSources(TestCase):
  48. url = 'file://' + os.path.abspath('data/sample_modules')
  49. path = os.path.join('data', 'sample_modules')
  50. install_prefix = 'gextension_test_install_path'
  51. # TODO: this is wrong for MS Win
  52. files = [
  53. os.path.join(install_prefix, 'scripts', 'r.plus.example'),
  54. os.path.join(install_prefix, 'docs', 'html', 'r.plus.example.html'),
  55. ]
  56. # to create archives from the source, the following was used:
  57. # zip r.plus.example.zip r.plus.example/*
  58. # tar czvf r.plus.example.tar.gz r.plus.example
  59. # cd r.plus.example/
  60. # tar czvf ../r.plus.example_sep.tar.gz *
  61. def setUp(self):
  62. """Make sure we are not dealing with some old files"""
  63. if os.path.exists(self.install_prefix):
  64. files = os.listdir(self.install_prefix)
  65. if files:
  66. RuntimeError("Install prefix path '{}' contains files {}"
  67. .format(self.install_prefix, files))
  68. def tearDown(self):
  69. """Remove created files"""
  70. silent_rmtree(self.install_prefix)
  71. def test_directory_install(self):
  72. """Test installing extension from directory"""
  73. self.assertModule('g.extension', extension='r.plus.example',
  74. url=os.path.join(self.path, 'r.plus.example'),
  75. prefix=self.install_prefix)
  76. # TODO: this is wrong for MS Win
  77. for file in self.files:
  78. self.assertFileExists(file)
  79. def test_targz_install(self):
  80. """Test installing extension from local .tar.gz"""
  81. self.assertModule('g.extension', extension='r.plus.example',
  82. url=os.path.join(self.path,
  83. 'r.plus.example.tar.gz'),
  84. prefix=self.install_prefix)
  85. for file in self.files:
  86. self.assertFileExists(file)
  87. def test_remote_targz_without_dir_install(self):
  88. """Test installing extension from (remote) .tar.gz without main dir"""
  89. self.assertModule('g.extension', extension='r.plus.example',
  90. url=self.url + '/' + 'r.plus.example_sep.tar.gz',
  91. prefix=self.install_prefix, verbose=True)
  92. for file in self.files:
  93. self.assertFileExists(file)
  94. def test_remote_zip_install(self):
  95. """Test installing extension from .zip specified by URL (local)"""
  96. self.assertModule('g.extension', extension='r.plus.example',
  97. url=self.url + '/' + 'r.plus.example.zip',
  98. prefix=self.install_prefix)
  99. for file in self.files:
  100. self.assertFileExists(os.path.join(file))
  101. if __name__ == '__main__':
  102. test()