diff --git a/pfhub/new_to_old.py b/pfhub/new_to_old.py index 8d539fed..f2bcfec7 100644 --- a/pfhub/new_to_old.py +++ b/pfhub/new_to_old.py @@ -113,11 +113,31 @@ def subs(data_all, lines_and_contours): "memory_usage": data_all.results.memory_in_kb, "lines": lines_and_contours["lines"], "contours": lines_and_contours.get("contours", []), - "name": data_all.id, + "name": make_name(data_all), "repo_version": "aaaaa", } +def make_name(data_all): + """Generate a name from a new schema record + + Args: + data_all: new schema dictionary + + Returns: + a sensibel name string + """ + return ( + data_all.framework[0].name + + "-" + + data_all.benchmark_problem + + "-" + + data_all.contributors[0].id.split(":")[1] + + "-" + + data_all.date_created + ) + + def render_meta(data_all): """Render the meta file""" return render( diff --git a/pfhub/scripts/test_cli.py b/pfhub/scripts/test_cli.py index 2dd20fbc..e24ee5a3 100644 --- a/pfhub/scripts/test_cli.py +++ b/pfhub/scripts/test_cli.py @@ -322,3 +322,16 @@ def test_adding_new_result(tmpdir): outpath2 = os.path.join(tmpdir, "result_list_1a.1.yaml") assert result.exit_code == 0 assert result.output.splitlines()[-1] == f"Writing: {outpath1}, {outpath2}" + + +def test_name_generation(tmpdir): + """Test name generation when converting from new to old""" + runner = CliRunner() + base = os.path.split(__file__)[0] + yaml_path = os.path.join(base, "..", "test_data", "meumapps", "pfhub.yaml") + result = runner.invoke(convert_to_old, [yaml_path, "--dest", tmpdir]) + outpath = os.path.join(tmpdir, "meta.yaml") + assert result.exit_code == 0 + assert result.output.splitlines()[-1] == f"Writing: {outpath}" + data = read_yaml(outpath) + assert data["name"] == "meumapps-1a.1-stvdwtt-2021-04-01"