1+ import os
2+
3+ original_dir = 'tests'
4+ parallel_dir = 'tests/test_parallel'
5+
6+ # 1. Create the directory if it doesn't exist
7+ if not os .path .exists (parallel_dir ):
8+ os .makedirs (parallel_dir )
9+
10+ # 2. Create __init__.py with the Matplotlib fix for headless CI
11+ with open (os .path .join (parallel_dir , '__init__.py' ), 'w' ) as f :
12+ f .write ("import matplotlib\n matplotlib.use('Agg')\n " )
13+
14+ # 3. Identify all serial test files (excluding the parallel folder itself)
15+ test_files = [f for f in os .listdir (original_dir )
16+ if f .startswith ('test_' ) and f .endswith ('.py' ) and f != 'test_parallel.py' ]
17+
18+ for filename in test_files :
19+ module_name = filename [:- 3 ] # Removes '.py' to get 'test_gpr', etc.
20+
21+ # Generate the Dynamic Wrapper content
22+ content = f"""import unittest
23+ import pytest
24+ import sys
25+
26+ try:
27+ from ezyrb.parallel import ReducedOrderModel as ParallelROM
28+ import tests.{ module_name } as serial_module
29+ HAS_PARALLEL = True
30+ except ImportError:
31+ HAS_PARALLEL = False
32+
33+ if not HAS_PARALLEL:
34+ raise unittest.SkipTest("Parallel dependencies (pycompss/pyeddl) missing")
35+
36+ serial_module.ROM = ParallelROM
37+ if hasattr(serial_module, 'ReducedOrderModel'):
38+ serial_module.ReducedOrderModel = ParallelROM
39+
40+ sys.modules['tests.{ module_name } '] = serial_module
41+
42+
43+ from tests.{ module_name } import *
44+ """
45+
46+ # Write the unique file to the parallel directory
47+ with open (os .path .join (parallel_dir , filename ), 'w' ) as f :
48+ f .write (content )
49+
50+ print (f"Done! Generated { len (test_files )} dynamic wrappers in { parallel_dir } " )
0 commit comments