Skip to content

Commit

Permalink
Merge pull request #129 from catalystneuro/remove_top_level_imports_s…
Browse files Browse the repository at this point in the history
…tand_alone

Run import tests as if they were in a fresh environment
  • Loading branch information
CodyCBakerPhD authored Sep 3, 2022
2 parents 37f9c89 + 94ea18c commit dab71df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
- name: Install neuroconv with minimal requirements
run: pip install .[test]
- name: Run import tests
run: |
pytest tests/imports.py::TestImportStructure::test_top_level
pytest tests/imports.py::TestImportStructure::test_tools
pytest tests/imports.py::TestImportStructure::test_datainterfaces
- name: Run minimal tests
run: pytest tests/test_minimal -n auto --dist loadscope

Expand All @@ -49,6 +54,7 @@ jobs:

- name: Install with icephys requirements
run: pip install .[icephys]

#- name: Run icephys tests # There are no icephys specific tests without data
# run: pytest tests/test_icephys -n auto --dist loadscope

Expand Down
47 changes: 26 additions & 21 deletions tests/test_minimal/test_import_structure.py → tests/imports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest import TestCase
# This module is meant for the tests to be run as stand-alone so as to emulate a fresh import
# Run them by using:
# pytest tests/import_structure.py::TestImportStructure::test_name

import neuroconv
from neuroconv import datainterfaces
from neuroconv import tools
from unittest import TestCase


def _strip_magic_module_attributes(ls: list) -> list:
Expand All @@ -21,37 +21,42 @@ def _strip_magic_module_attributes(ls: list) -> list:


class TestImportStructure(TestCase):
def test_outer_import_structure(self):
current_structure = _strip_magic_module_attributes(ls=dir(neuroconv))
def test_top_level(self):
import neuroconv

current_structure = _strip_magic_module_attributes(ls=neuroconv.__dict__)
expected_structure = [
# Sub-modules
"nwbconverter",
"basedatainterface",
"baseextractorinterface",
"datainterfaces",
"tools",
"utils",
"tools", # Attached to namespace by NWBConverter import
"utils", # Attached to namesapce by NWBconverter import
# Exposed attributes
"NWBConverter",
"run_conversion_from_yaml",
]
self.assertCountEqual(first=current_structure, second=expected_structure)

def test_tools_import_structure(self):
def test_tools(self):
"""Python dir() calls (and __dict__ as well) update dynamically based on global imports."""
current_structure = _strip_magic_module_attributes(ls=dir(tools))
minimal_expected_structure = [

from neuroconv import tools

current_structure = _strip_magic_module_attributes(ls=tools.__dict__)
expected_structure = [
# Sub-Packages
"yaml_conversion_specification", # Attached to namespace by top __init__ call of NWBConverter
# Sub-modules
"importing",
"yaml_conversion_specification", # imported by outer level __init__
# Helper functions
"importing", # Attached to namespace by importing get_package
"nwb_helpers", # Attached to namespace by top __init__ call of NWBConverter
# Functions imported on the __init__
"get_package",
]
for member in minimal_expected_structure:
self.assertIn(member=member, container=current_structure)
self.assertCountEqual(first=current_structure, second=expected_structure)

def test_datainterfaces(self):
from neuroconv import datainterfaces

def test_datainterfaces_import_structure(self):
current_structure = _strip_magic_module_attributes(ls=dir(datainterfaces))
current_structure = _strip_magic_module_attributes(ls=datainterfaces.__dict__)
expected_structure = [
# Sub-modules
"behavior",
Expand Down

0 comments on commit dab71df

Please sign in to comment.