Skip to content

Commit a06f343

Browse files
tests updated
1 parent 7ac9c1b commit a06f343

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

tests/test_deep_simulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_07_lockin_backend(self):
192192
"1.23,4.56" # SNAP? 3,4
193193
]
194194
self.run_module_safely(
195-
"Lock_in_amplifier.BasicTest_S830_Instrument_Control", {})
195+
"pica.lockin.BasicTest_S830_Instrument_Control", {})
196196

197197
@pytest.mark.usefixtures("mock_tkinter")
198198
def test_08_combined_2400_2182(self):
@@ -213,7 +213,7 @@ def test_08_combined_2400_2182(self):
213213
with patch('builtins.input', side_effect=inputs), \
214214
patch('pandas.DataFrame.to_csv'):
215215
self.run_module_safely(
216-
"Keithley_2400_Keithley_2182.Backends.IV_K2400_K2182_Backend_v1", {})
216+
"pica.keithley.k2400_2182.Instrument_Control.IV_K2400_K2182_Instrument_Control", {})
217217

218218
@pytest.mark.usefixtures("mock_tkinter")
219219
def test_09_poling(self):
@@ -266,7 +266,7 @@ def test_12_gpib_rescue(self):
266266
rm = MockRM.return_value
267267
rm.list_resources.return_value = ('GPIB0::1::INSTR',)
268268
self.run_module_safely(
269-
"Utilities.GPIB_Interface_Rescue_Simple_Instrument_Control_v2_", {})
269+
"pica.utils.GPIB_Interface_Rescue_Simple_Instrument_Control_v2_", {})
270270

271271

272272
if __name__ == '__main__':

tests/test_gui_modules_initialization.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717

1818
def find_gui_modules():
1919
"""
20-
Recursively finds all GUI modules in the project, excluding non-GUI files.
21-
Returns them in a format suitable for importlib (e.g., 'Keithley_2400.IV_K2400_GUI').
20+
Recursively finds all GUI modules in the `pica` directory.
21+
Returns them in a format suitable for importlib (e.g., 'pica.keithley.k2400.IV_K2400_GUI').
2222
"""
2323
gui_files = []
24-
for root, _, files in os.walk(project_root):
25-
# Exclude directories that are not part of the main source code
26-
if 'tests' in root or '.git' in root or 'venv' in root or '__pycache__' in root or 'assets' in root or 'Setup' in root:
27-
continue
24+
pica_dir = os.path.join(project_root, 'pica')
25+
for root, _, files in os.walk(pica_dir):
2826
for file in files:
29-
if file.endswith('_GUI_v' or '_GUI.py') and file != '__init__.py':
27+
if file.endswith('_GUI.py') and not file.startswith('__'):
3028
full_path = os.path.join(root, file)
3129
# Convert file path to module path
32-
# e.g., F:\...\PICA\Keithley_2400\IV_K2400_GUI.py -> Keithley_2400.IV_K2400_GUI
3330
relative_path = os.path.relpath(full_path, project_root)
3431
module_path = os.path.splitext(relative_path)[0].replace(os.path.sep, '.')
3532
gui_files.append(module_path)
@@ -50,20 +47,24 @@ def test_gui_module_initialization(module_path):
5047
gui_module = importlib.import_module(module_path)
5148

5249
# The main application class is assumed to have the same name as the file,
53-
# but without the version suffix (e.g., 'IV_K2400_GUI' from 'IV_K2400_GUI.py')
54-
# This logic needs to be robust to handle different naming conventions.
5550
base_name = module_path.split('.')[-1]
56-
if '_GUI_v' in base_name:
57-
class_name = base_name.split('_GUI_v')[0] + "_GUI"
58-
elif base_name.endswith('_GUI'):
59-
class_name = base_name
60-
else:
61-
pytest.fail(f"Could not determine class name from module path: {module_path}")
51+
52+
# A more robust way to find the class.
53+
# We look for a class in the module that ends with 'GUI' and is defined in that module.
54+
gui_class = None
55+
for name, obj in gui_module.__dict__.items():
56+
if isinstance(obj, type) and obj.__module__ == gui_module.__name__:
57+
if name.endswith('GUI'):
58+
gui_class = obj
59+
break
60+
61+
if not gui_class:
62+
pytest.fail(f"Could not find a suitable GUI class in module: {module_path}")
63+
6264

6365
# Get the class from the module and instantiate it
64-
AppClass = getattr(gui_module, class_name)
6566
mock_root = MagicMock()
66-
app_instance = AppClass(mock_root)
67+
app_instance = gui_class(mock_root)
6768

6869
assert app_instance is not None, "GUI class failed to instantiate."
6970

tests/test_package_integrity.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818

1919
def find_python_files():
2020
"""
21-
Recursively finds all python files in the project,
22-
excluding the test directory, git, and virtual environments.
21+
Recursively finds all python files in the `pica` directory.
2322
"""
2423
py_files = []
25-
for root, _, files in os.walk(project_root):
26-
if 'tests' in root or '.git' in root or 'venv' in root or '__pycache__' in root:
27-
continue
24+
pica_dir = os.path.join(project_root, 'pica')
25+
for root, _, files in os.walk(pica_dir):
2826
for file in files:
2927
if file.endswith('.py'):
30-
# Return the full path for reading, and relative for reporting
3128
full_path = os.path.join(root, file)
3229
py_files.append(full_path)
3330
return py_files

tests/test_pica_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Try importing the Launcher. If it fails due to imports, we skip.
1818
try:
19-
from PICA import PICALauncherApp
19+
from pica.main import PICALauncherApp
2020
except ImportError:
2121
PICALauncherApp = None
2222

0 commit comments

Comments
 (0)