test_benchmark.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # MODULE: Test of grass.benchmark
  2. #
  3. # AUTHOR(S): Vaclav Petras <wenzeslaus gmail com>
  4. #
  5. # PURPOSE: Benchmarking for GRASS GIS modules
  6. #
  7. # COPYRIGHT: (C) 2021 Vaclav Petras, and by the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General Public
  10. # License (>=v2). Read the file COPYING that comes with GRASS
  11. # for details.
  12. """Basic tests of grass.benchmark"""
  13. from pathlib import Path
  14. from subprocess import DEVNULL
  15. from grass.benchmark import benchmark_resolutions, num_cells_plot
  16. from grass.gunittest.case import TestCase
  17. from grass.gunittest.main import test
  18. from grass.pygrass.modules import Module
  19. class TestBenchmarksRun(TestCase):
  20. """Tests that functions for benchmarking can run"""
  21. def test_resolutions(self):
  22. """Test that resolution tests runs without nprocs and plots to file"""
  23. benchmarks = [
  24. dict(
  25. module=Module("r.univar", map="elevation", stdout_=DEVNULL, run_=False),
  26. label="Standard output",
  27. ),
  28. dict(
  29. module=Module(
  30. "r.univar", map="elevation", flags="g", stdout_=DEVNULL, run_=False
  31. ),
  32. label="Standard output",
  33. ),
  34. ]
  35. resolutions = [300, 200, 100]
  36. results = []
  37. for benchmark in benchmarks:
  38. results.append(
  39. benchmark_resolutions(
  40. **benchmark,
  41. resolutions=resolutions,
  42. )
  43. )
  44. plot_file = "test_res_plot.png"
  45. num_cells_plot(results, filename=plot_file)
  46. self.assertTrue(Path(plot_file).is_file())
  47. if __name__ == "__main__":
  48. test()