test_addons_modules.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. from grass.script.utils import decode
  15. import os
  16. MODULES_OUTPUT = """\
  17. d.frame
  18. d.mon2
  19. g.copyall
  20. g.isis3mt
  21. g.proj.all
  22. r.gdd
  23. r.geomorphon
  24. r.le.patch
  25. r.le.pixel
  26. r.traveltime
  27. r.univar2
  28. v.civil
  29. v.class.ml
  30. v.class.mlpy
  31. v.colors2
  32. v.delaunay3d
  33. v.ellipse
  34. v.in.proj
  35. v.in.redwg
  36. v.neighborhoodmatrix
  37. v.transects
  38. wx.metadata
  39. """.replace(
  40. "\n", os.linesep
  41. )
  42. class TestModulesMetadata(TestCase):
  43. url = "file://" + os.path.abspath("data")
  44. def test_listing(self):
  45. """List individual extensions/modules/addons"""
  46. module = SimpleModule("g.extension", flags="l", url=self.url)
  47. self.assertModule(module)
  48. stdout = decode(module.outputs.stdout)
  49. self.assertMultiLineEqual(stdout, MODULES_OUTPUT)
  50. class TestModulesFromDifferentSources(TestCase):
  51. url = "file://" + os.path.abspath("data/sample_modules")
  52. path = os.path.join("data", "sample_modules")
  53. install_prefix = "gextension_test_install_path"
  54. # TODO: this is wrong for MS Win
  55. files = [
  56. os.path.join(install_prefix, "scripts", "r.plus.example"),
  57. os.path.join(install_prefix, "docs", "html", "r.plus.example.html"),
  58. ]
  59. # to create archives from the source, the following was used:
  60. # zip r.plus.example.zip r.plus.example/*
  61. # tar czvf r.plus.example.tar.gz r.plus.example
  62. # cd r.plus.example/
  63. # tar czvf ../r.plus.example_sep.tar.gz *
  64. def setUp(self):
  65. """Make sure we are not dealing with some old files"""
  66. if os.path.exists(self.install_prefix):
  67. files = os.listdir(self.install_prefix)
  68. if files:
  69. RuntimeError(
  70. "Install prefix path '{}' contains files {}".format(
  71. self.install_prefix, files
  72. )
  73. )
  74. def tearDown(self):
  75. """Remove created files"""
  76. silent_rmtree(self.install_prefix)
  77. def test_directory_install(self):
  78. """Test installing extension from directory"""
  79. self.assertModule(
  80. "g.extension",
  81. extension="r.plus.example",
  82. url=os.path.join(self.path, "r.plus.example"),
  83. prefix=self.install_prefix,
  84. )
  85. # TODO: this is wrong for MS Win
  86. for file in self.files:
  87. self.assertFileExists(file)
  88. def test_targz_install(self):
  89. """Test installing extension from local .tar.gz"""
  90. self.assertModule(
  91. "g.extension",
  92. extension="r.plus.example",
  93. url=os.path.join(self.path, "r.plus.example.tar.gz"),
  94. prefix=self.install_prefix,
  95. )
  96. for file in self.files:
  97. self.assertFileExists(file)
  98. def test_remote_targz_without_dir_install(self):
  99. """Test installing extension from (remote) .tar.gz without main dir"""
  100. self.assertModule(
  101. "g.extension",
  102. extension="r.plus.example",
  103. url=self.url + "/" + "r.plus.example_sep.tar.gz",
  104. prefix=self.install_prefix,
  105. verbose=True,
  106. )
  107. for file in self.files:
  108. self.assertFileExists(file)
  109. def test_remote_zip_install(self):
  110. """Test installing extension from .zip specified by URL (local)"""
  111. self.assertModule(
  112. "g.extension",
  113. extension="r.plus.example",
  114. url=self.url + "/" + "r.plus.example.zip",
  115. prefix=self.install_prefix,
  116. )
  117. for file in self.files:
  118. self.assertFileExists(os.path.join(file))
  119. if __name__ == "__main__":
  120. test()