Skip to content

Commit

Permalink
Merge branch 'pfhub-upload-template' into bug-report-template
Browse files Browse the repository at this point in the history
  • Loading branch information
wd15 committed May 6, 2022
2 parents e09e40a + 5c36f6f commit 6a63488
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ script:
";
- nix-shell _apps/data/shell.nix --pure --command "
cd _apps/data &&
#py.test test.py &&
black --check *.py &&
pylint *.py &&
flake8 *.py
Expand Down
28 changes: 24 additions & 4 deletions _data/python-pfhub/pfhub/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml


def make_yaml_content(id_, version):
def make_yaml_content(id_, version, name=None):
"""Generate some test yaml content
Args:
Expand All @@ -15,7 +15,7 @@ def make_yaml_content(id_, version):
Returns:
yaml result content as string
"""
return f"""
data = f"""
---
benchmark:
id: {id_}
Expand Down Expand Up @@ -45,24 +45,30 @@ def make_yaml_content(id_, version):
expr: datum.y * 2
as: b
"""
if name is not None:
data = data + f"\nname: {name}"
return data


def make_yaml(dir_, name, id_, version):
def make_yaml(dir_, name, id_, version, add_name=False):
"""Generate a yaml file for test purposes
Args:
dir_: the result directory to write to
name: name of the result
id_: the benchmark id_ (e.g. "8a")
version: the version (e.g. "1")
name: the name of the simulation (e.g. "fipy1a")
Returns:
name of the file created
"""
dir_name = dir_ / name
dir_name.mkdir(exist_ok=True)
yaml_file = dir_name / "meta.yaml"
yaml_file.write_text(make_yaml_content(id_, version))
yaml_file.write_text(
make_yaml_content(id_, version, name=name if add_name else None)
)
return yaml_file


Expand All @@ -80,6 +86,20 @@ def yaml_data_file(tmp_path):
return make_yaml(tmp_path, "result", "1a", 1)


@pytest.fixture
def yaml_data_file_with_name(tmp_path):
"""Generate a yaml test file with name included
Args:
tmp_path: temporary area to use to write files
Returns:
name of the data file
"""
tmp_path.mkdir(exist_ok=True)
return make_yaml(tmp_path, "result1", "1a", 1, add_name=True)


@pytest.fixture
def test_data_path(tmp_path):
"""Generate two result data files
Expand Down
25 changes: 13 additions & 12 deletions _data/python-pfhub/pfhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ def read_add_name(yaml_url):
>>> assert read_add_name(getfixture('yaml_data_file').as_uri())['name'] == 'result'
>>> assert read_add_name(
... getfixture('yaml_data_file_with_name'
... ).as_uri())['name'] == 'result1'
"""
data = read_yaml_from_url(yaml_url)
if 'name' in data:
if "name" in data:
return data
else:
return assoc(
read_yaml_from_url(yaml_url),
"name",
os.path.split(os.path.split(yaml_url)[0])[1],
)

return assoc(
read_yaml_from_url(yaml_url),
"name",
os.path.split(os.path.split(yaml_url)[0])[1],
)


def maybe(func):
Expand Down Expand Up @@ -210,9 +214,7 @@ def concat_items(items):
"""
concat = lambda x: pandas.concat(x) if x != [] else None
return pipe(
items, map_(lambda x: assign(x[0], x[1])), compact, list, concat
)
return pipe(items, map_(lambda x: assign(x[0], x[1])), compact, list, concat)


@curry
Expand Down Expand Up @@ -573,12 +575,11 @@ def read_vega_data(keys, data):

read_values = sequence(get("values"), pandas.DataFrame)


return pipe(
data,
read_url if "url" in data else read_values,
apply_transforms(data),
maybe(lambda x: get(keys, x))
maybe(lambda x: get(keys, x)),
)


Expand Down

0 comments on commit 6a63488

Please sign in to comment.