diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 6a3d8c3..c56d78c 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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: @@ -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() diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index 49c1510..4649d5d 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -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 @@ -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", + ]: + unexpected_file = os.path.join(project_dir, unexpected_file) + assert not os.path.exists(unexpected_file), f"Unexpected file: {unexpected_file}" + if __name__ == "__main__": # python test_bake_project.py ndx-my-namespace ndx-my-namespace