(testmodels-allexudynmodulestest)= # allExudynModulesTest.py You can view and download this file on Github: [allExudynModulesTest.py](https://github.com/jgerstmayr/EXUDYN/tree/master/python/TestModels/allExudynModulesTest.py) ```{code-block} python :linenos: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This is an EXUDYN example # # Details: Test for import of all exudyn modules, like utilities, etc.; # done to ensure that they do not contain any major error due to docstring conversion # # Author: Johannes Gerstmayr # Date: 2025-06-14 # # Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details. # #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import exudyn as exu testIsActive = exu.sys.get('testIsActive', False) from pathlib import Path import importlib.util import sys import os # Set the directory path ('.' for current directory) exudynPath = os.path.dirname(exu.__file__) directory = Path(exudynPath) # Get all files ending in .py recursively allModules = list(directory.rglob('*.py')) #list of file objects testSolution = 1 exu.Print('first module location=',str(allModules[0])) excludeModules = ['__init__.py', #fail '__main__.py', #the command line of the package; importing it RUNS it 'rosInterface.py', #rospy usually missing #'artificialIntelligence.py' ] try: import stable_baselines3 #ok except: exu.Print('stable-baselines3 not available: skip artificialIntelligence.py') excludeModules.append('artificialIntelligence.py') #the dialogs need tkinter, which a Python may lack: the Python of the cibuildwheel tests on Windows has none (#2920) try: import tkinter except ImportError: exu.Print('tkinter not available: skip GUI.py') excludeModules.append('GUI.py') #test all modules for moduleCheck in allModules: #moduleCheck converts to string as path+fileName if moduleCheck.name in excludeModules: continue exu.Print('check module:',moduleCheck.name) try: spec = importlib.util.spec_from_file_location(moduleCheck.stem, moduleCheck) testModule = importlib.util.module_from_spec(spec) sys.modules[moduleCheck.stem] = testModule #moduleCheck.name is the filename with ending, moduleCheck.stem is without ending spec.loader.exec_module(testModule) #now execute module except FileNotFoundError: testSolution = 0 exu.Print(f"Error: The module {moduleCheck} does not exist.") except SyntaxError as e: testSolution = 0 exu.Print(f"Error: module {moduleCheck} has invalid Python syntax: {e}") except Exception as e: testSolution = 0 exu.Print(f"Error: Failed to execute {moduleCheck}: {e}") if testSolution==1: exu.Print('\n*** all imports successful! ***\n') #also add test for demos try: exu.Print('test demo1') exu.demos.Demo1() exu.Print('test demo2') exu.demos.Demo2(showAll=False) except Exception as e: exu.Print(f"Error: Demos failed: {e}") #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exu.Print('\nsolution of allExudynModulesTest (should be 1)=',testSolution) exu.sys['testResult'] = testSolution ```