test_benchmark_cli.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. """Tests of grass.benchmark CLI"""
  13. from pathlib import Path
  14. from subprocess import DEVNULL
  15. from grass.benchmark import benchmark_resolutions, save_results_to_file
  16. from grass.benchmark.app import main as benchmark_main
  17. from grass.gunittest.case import TestCase
  18. from grass.gunittest.main import test
  19. from grass.pygrass.modules import Module
  20. class TestBenchmarkCLI(TestCase):
  21. """Tests that benchmarkin CLI works"""
  22. def test_plot_workflow(self):
  23. """Test that plot workflow runs"""
  24. label = "Standard output"
  25. repeat = 4
  26. json_filename = "plot_test.json"
  27. png_filename = "plot_test.png"
  28. png_filename_resolutions = "plot_test_resolutions.png"
  29. # The benchmark part has only Python API, not CLI.
  30. result = benchmark_resolutions(
  31. module=Module("r.univar", map="elevation", stdout_=DEVNULL, run_=False),
  32. label=label,
  33. repeat=repeat,
  34. resolutions=[1000, 500],
  35. )
  36. save_results_to_file([result], json_filename)
  37. benchmark_main(["plot", "cells", json_filename, png_filename])
  38. self.assertTrue(Path(png_filename).is_file())
  39. benchmark_main(
  40. ["plot", "cells", "--resolutions", json_filename, png_filename_resolutions]
  41. )
  42. self.assertTrue(Path(png_filename_resolutions).is_file())
  43. if __name__ == "__main__":
  44. test()