Skip to content

Commit

Permalink
Fix and add test for widgets False
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Sep 9, 2024
1 parent 14a5d44 commit b959934
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _remove_widget_files():
# user specifies that they do not want to add widgets, remove these files from the template.
# This is easier than adding the files only if they want to add widgets.
dirs_to_remove = {
"./notebooks", # currently contains only widget demo -- be more specific if others exist
"notebooks", # currently contains only widget demo -- be more specific if others exist
"src/pynwb/{{ cookiecutter.py_pkg_name }}/widgets"
}
for path in dirs_to_remove:
Expand All @@ -61,7 +61,7 @@ def _remove_widget_files():
def main():
"""Run the post gen project hook main entry point."""

if "{{ cookiecutter.widgets }}" == "True":
if "{{ cookiecutter.widgets }}" != "True":
_remove_widget_files()

_generate_doc()
Expand Down
12 changes: 11 additions & 1 deletion tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_bake_project_extra(cookies):

def test_bake_project_widgets(cookies):
"""Test evaluating the template with widgets."""
result = cookies.bake(extra_context={"widgets": "yes"})
result = cookies.bake(extra_context={"widgets": True})

assert result.exit_code == 0
assert result.exception is None
Expand Down Expand Up @@ -75,6 +75,16 @@ def _check_gen_files(project_dir: str, namespace: str):
with open(expected_file, "r") as fp:
assert fp.read().strip() != "", f"Empty file: {expected_file}"

# Widgets = False by default, so these files should not exist
for unexpected file in [
"notebooks/example.ipynb",
"src/pynwb/ndx_my_namespace/widgets/__init__.py",
"src/pynwb/ndx_my_namespace/widgets/tetrode_series_widget.py",
"src/pynwb/ndx_my_namespace/widgets/README.md",
]:
expected_file = os.path.join(project_dir, expected_file)
assert not os.path.exists(expected_file), f"Unexpected file: {expected_file}"


if __name__ == "__main__":
# python test_bake_project.py ndx-my-namespace ndx-my-namespace
Expand Down

0 comments on commit b959934

Please sign in to comment.