|
@@ -14,8 +14,17 @@
|
|
|
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
from subprocess import DEVNULL
|
|
from subprocess import DEVNULL
|
|
|
|
+from types import SimpleNamespace
|
|
|
|
|
|
-from grass.benchmark import benchmark_resolutions, num_cells_plot
|
|
|
|
|
|
+from grass.benchmark import (
|
|
|
|
+ benchmark_resolutions,
|
|
|
|
+ join_results,
|
|
|
|
+ load_results,
|
|
|
|
+ load_results_from_file,
|
|
|
|
+ num_cells_plot,
|
|
|
|
+ save_results,
|
|
|
|
+ save_results_to_file,
|
|
|
|
+)
|
|
from grass.gunittest.case import TestCase
|
|
from grass.gunittest.case import TestCase
|
|
from grass.gunittest.main import test
|
|
from grass.gunittest.main import test
|
|
from grass.pygrass.modules import Module
|
|
from grass.pygrass.modules import Module
|
|
@@ -52,5 +61,63 @@ class TestBenchmarksRun(TestCase):
|
|
self.assertTrue(Path(plot_file).is_file())
|
|
self.assertTrue(Path(plot_file).is_file())
|
|
|
|
|
|
|
|
|
|
|
|
+class TestBenchmarkResults(TestCase):
|
|
|
|
+ """Tests that saving results work"""
|
|
|
|
+
|
|
|
|
+ def test_save_load(self):
|
|
|
|
+ """Test that results can be saved and loaded"""
|
|
|
|
+ resolutions = [300, 200]
|
|
|
|
+ results = [
|
|
|
|
+ benchmark_resolutions(
|
|
|
|
+ module=Module(
|
|
|
|
+ "r.univar",
|
|
|
|
+ map="elevation",
|
|
|
|
+ stdout_=DEVNULL,
|
|
|
|
+ stderr_=DEVNULL,
|
|
|
|
+ run_=False,
|
|
|
|
+ ),
|
|
|
|
+ label="Standard output",
|
|
|
|
+ resolutions=resolutions,
|
|
|
|
+ )
|
|
|
|
+ ]
|
|
|
|
+ results = load_results(save_results(results))
|
|
|
|
+ plot_file = "test_res_plot.png"
|
|
|
|
+ num_cells_plot(results.results, filename=plot_file)
|
|
|
|
+ self.assertTrue(Path(plot_file).is_file())
|
|
|
|
+
|
|
|
|
+ def test_data_file_roundtrip(self):
|
|
|
|
+ """Test functions can save and load to a file"""
|
|
|
|
+ original = [SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 1")]
|
|
|
|
+ filename = "test_res_file.json"
|
|
|
|
+
|
|
|
|
+ save_results_to_file(original, filename)
|
|
|
|
+ self.assertTrue(Path(filename).is_file())
|
|
|
|
+
|
|
|
|
+ loaded = load_results_from_file(filename).results
|
|
|
|
+ self.assertEqual(original, loaded)
|
|
|
|
+
|
|
|
|
+ def test_join_results_list(self):
|
|
|
|
+ """Test that we can join lists"""
|
|
|
|
+ list_1 = [
|
|
|
|
+ SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 1"),
|
|
|
|
+ SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 2"),
|
|
|
|
+ ]
|
|
|
|
+ list_2 = [SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 3")]
|
|
|
|
+ new_results = join_results([list_1, list_2])
|
|
|
|
+ self.assertEqual(len(new_results), 3)
|
|
|
|
+
|
|
|
|
+ def test_join_results_structure(self):
|
|
|
|
+ """Test that we can join a full results structure"""
|
|
|
|
+ list_1 = SimpleNamespace(
|
|
|
|
+ results=[
|
|
|
|
+ SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 1"),
|
|
|
|
+ SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 2"),
|
|
|
|
+ ]
|
|
|
|
+ )
|
|
|
|
+ list_2 = [SimpleNamespace(nprocs=[1, 2, 3], times=[3, 2, 1], label="Test 3")]
|
|
|
|
+ new_results = join_results([list_1, list_2])
|
|
|
|
+ self.assertEqual(len(new_results), 3)
|
|
|
|
+
|
|
|
|
+
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
test()
|
|
test()
|