Skip to content

Commit

Permalink
Add a test for the JSON rendering
Browse files Browse the repository at this point in the history
- this is really mostly for me to design the new API
  • Loading branch information
smarr committed Feb 18, 2024
1 parent ead2649 commit bb414e9
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions rebench/tests/persistency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .persistence import TestPersistence

from ..persistence import DataStore, _ReBenchDB
from ..rebenchdb import ReBenchDB

from ..configurator import Configurator, load_config
from ..environment import git_not_available, git_repo_not_initialized
Expand Down Expand Up @@ -235,6 +236,14 @@ def test_check_single_csv_header(self):
invocation_lines = [line for line in lines if line.startswith('invocation')]
self.assertEqual(len(invocation_lines), 1)

def _create_dummy_rebench_db_persistence(self):
class _Cfg(object):
@staticmethod
def get_rebench_db_connector():
return None

return _ReBenchDB(_Cfg(), None, self.ui)

def _run_exp_to_get_data_points_with_inconsistent_set_of_criteria(self):
yaml = load_config(self._path + '/features/issue_16.conf')
yaml['executors']['TestRunner']['executable'] = 'features/issue_16_vm2.py'
Expand All @@ -247,15 +256,7 @@ def _run_exp_to_get_data_points_with_inconsistent_set_of_criteria(self):
run_id_obj = list(runs)[0]
ex = Executor(runs, False, self.ui)
ex.execute()
cache = {list(runs)[0]: persistence.get_data_points()}

class _Cfg(object):
def get_rebench_db_connector(self):
return None

all_data, criteria_index, num_measurements = _ReBenchDB(
_Cfg(), None, self.ui).convert_data_to_api_format(cache)
return all_data, criteria_index, num_measurements, run_id_obj
return {list(runs)[0]: persistence.get_data_points()}, run_id_obj

def _assert_criteria_index_structure(self, criteria_index):
criteria = ['bar', 'baz', 'total', 'foo']
Expand Down Expand Up @@ -317,8 +318,13 @@ def _assert_data_point_structure(self, data):
self.assertEqual(criterion, m['c'])
self.assertEqual(i, int(m['v']))

def _create_dummy_rebench_db_adapter(self):
return ReBenchDB('http://localhost', '', '', self.ui)

def test_data_conversion_to_rebench_db_api(self):
all_data, criteria_index, num_measurements, run_id_obj = self._run_exp_to_get_data_points_with_inconsistent_set_of_criteria()
cache, run_id_obj = self._run_exp_to_get_data_points_with_inconsistent_set_of_criteria()
rebench_db = self._create_dummy_rebench_db_persistence()
all_data, criteria_index, num_measurements = rebench_db.convert_data_to_api_format(cache)

self.assertEqual(24, num_measurements)

Expand All @@ -331,3 +337,16 @@ def test_data_conversion_to_rebench_db_api(self):
self._assert_benchmark_structure(run_id, run_id_obj)
self._assert_data_point_structure(data)

rdb = self._create_dummy_rebench_db_adapter()

self.assertEqual('[{"in":1,"it":1,"m":[{"v":0.0,"c":0},{"v":0.0,"c":1},{"v":0.0,"c":2}]},' +
'{"in":1,"it":2,"m":[{"v":1.1,"c":3},{"v":1.1,"c":2}]},' +
'{"in":1,"it":3,"m":[{"v":2.2,"c":0},{"v":2.2,"c":2}]},' +
'{"in":1,"it":4,"m":[{"v":3.3,"c":1},{"v":3.3,"c":3},{"v":3.3,"c":2}]},' +
'{"in":1,"it":5,"m":[{"v":4.4,"c":0},{"v":4.4,"c":2}]},' +
'{"in":1,"it":6,"m":[{"v":5.5,"c":3},{"v":5.5,"c":2}]},' +
'{"in":1,"it":7,"m":[{"v":6.6,"c":0},{"v":6.6,"c":1},{"v":6.6,"c":2}]},' +
'{"in":1,"it":8,"m":[{"v":7.7,"c":3},{"v":7.7,"c":2}]},' +
'{"in":1,"it":9,"m":[{"v":8.8,"c":0},{"v":8.8,"c":2}]},' +
'{"in":1,"it":10,"m":[{"v":9.9,"c":1},{"v":9.9,"c":3},{"v":9.9,"c":2}]}]',
rdb.convert_data_to_json(data))

0 comments on commit bb414e9

Please sign in to comment.