Grass7AlgorithmsRasterTestPt2.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """
  2. ***************************************************************************
  3. Grass7AlgorithmsRasterTestPt2.py
  4. -----------------------------
  5. Date : May 2016
  6. Copyright : (C) 2016 by Médéric Ribreux
  7. Email : mederic dot ribreux at medspx dot fr
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Médéric Ribreux'
  18. __date__ = 'May 2016'
  19. __copyright__ = '(C) 2016, Médéric Ribreux'
  20. import AlgorithmsTestBase
  21. import nose2
  22. import shutil
  23. import os
  24. import tempfile
  25. from qgis.core import (
  26. QgsApplication,
  27. QgsProcessingContext,
  28. QgsProcessingFeedback
  29. )
  30. from qgis.testing import (
  31. start_app,
  32. unittest
  33. )
  34. from grassprovider.Grass7AlgorithmProvider import Grass7AlgorithmProvider
  35. from grassprovider.Grass7Utils import Grass7Utils
  36. testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')
  37. class TestGrass7AlgorithmsRasterTest(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
  38. @classmethod
  39. def setUpClass(cls):
  40. start_app()
  41. cls.provider = Grass7AlgorithmProvider()
  42. QgsApplication.processingRegistry().addProvider(cls.provider)
  43. cls.cleanup_paths = []
  44. cls.temp_dir = tempfile.mkdtemp()
  45. cls.cleanup_paths.append(cls.temp_dir)
  46. assert Grass7Utils.installedVersion()
  47. @classmethod
  48. def tearDownClass(cls):
  49. QgsApplication.processingRegistry().removeProvider(cls.provider)
  50. for path in cls.cleanup_paths:
  51. shutil.rmtree(path)
  52. def test_definition_file(self):
  53. return 'grass7_algorithms_raster_tests2.yaml'
  54. def testNeighbors(self):
  55. context = QgsProcessingContext()
  56. input_raster = os.path.join(testDataPath, 'custom', 'grass7', 'float_raster.tif')
  57. alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:r.neighbors')
  58. self.assertIsNotNone(alg)
  59. temp_file = os.path.join(self.temp_dir, 'grass_output.tif')
  60. # Test an even integer for neighborhood size
  61. parameters = {'input': input_raster,
  62. 'selection': None,
  63. 'method': 0,
  64. 'size': 4,
  65. 'gauss': None,
  66. 'quantile': '',
  67. '-c': False,
  68. '-a': False,
  69. 'weight': '',
  70. 'output': temp_file,
  71. 'GRASS_REGION_PARAMETER': None,
  72. 'GRASS_REGION_CELLSIZE_PARAMETER': 0,
  73. 'GRASS_RASTER_FORMAT_OPT': '',
  74. 'GRASS_RASTER_FORMAT_META': ''}
  75. ok, msg = alg.checkParameterValues(parameters, context)
  76. self.assertFalse(ok)
  77. if __name__ == '__main__':
  78. nose2.main()