Skip to content

Commit edde3c1

Browse files
committed
refactor: extract CI test scripts from GitHub Actions workflows
Extract inline Python code from CI workflows into dedicated scripts: 🔧 New Test Scripts: - scripts/test_maya_docker_integration.py: Maya Docker environment testing - scripts/test_windows_python27_ci.py: Windows Python 2.7 CI testing 📝 Improved Maintainability: - Remove 200+ lines of inline Python code from YAML files - Better error handling and structured output - Easier to debug and modify test logic - Consistent test reporting across platforms 🚀 Simplified Workflows: - Maya Python 2.7 workflow now calls dedicated script - Windows Python 2.7 workflow uses single script call - Cleaner YAML syntax and better readability - Reduced workflow file complexity by 80% ✅ Benefits: - Scripts can be run locally for debugging - Better code organization and separation of concerns - Easier to add new test cases - Improved error messages and logging - Version control friendly (proper syntax highlighting) The workflows now simply call the appropriate test scripts, making them much more maintainable and easier to understand. Signed-off-by: longhao <[email protected]>
1 parent aca8879 commit edde3c1

File tree

4 files changed

+580
-291
lines changed

4 files changed

+580
-291
lines changed

.github/workflows/maya-python27-test.yml

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -46,88 +46,11 @@ jobs:
4646
-e MAYA_DISABLE_CIP=1 \
4747
-e MAYA_DISABLE_CER=1 \
4848
-e MAYA_DISABLE_CLIC_IPM=1 \
49+
-e MAYA_VERSION=${{ matrix.maya-version }} \
4950
mottosso/maya:${{ matrix.maya-version }} \
50-
mayapy -c "
51-
import sys
52-
import os
53-
print('=' * 60)
54-
print('Maya ${{ matrix.maya-version }} Python 2.7 Integration Test')
55-
print('=' * 60)
56-
print('Python version:', sys.version)
57-
print('Python executable:', sys.executable)
58-
print('Platform:', sys.platform)
59-
60-
# Add workspace to Python path
61-
sys.path.insert(0, '/workspace')
62-
63-
try:
64-
# Test Maya environment
65-
import maya.standalone
66-
maya.standalone.initialize()
67-
print('✅ Maya standalone initialized successfully')
68-
69-
import maya.cmds as cmds
70-
maya_version = cmds.about(version=True)
71-
maya_build = cmds.about(buildDirectory=True)
72-
print('✅ Maya version: {}'.format(maya_version))
73-
print('✅ Maya build: {}'.format(maya_build))
74-
75-
# Test Maya Umbrella core imports
76-
print('\\n--- Testing Maya Umbrella Imports ---')
77-
from maya_umbrella import MayaVirusDefender, MayaVirusScanner
78-
print('✅ Core classes imported successfully')
79-
80-
from maya_umbrella.vaccines import get_all_vaccines
81-
vaccines = get_all_vaccines()
82-
print('✅ Vaccines loaded: {} vaccines available'.format(len(vaccines)))
83-
84-
# List available vaccines
85-
for vaccine in vaccines:
86-
print(' - {}'.format(vaccine.__class__.__name__))
87-
88-
# Test basic defender functionality
89-
print('\\n--- Testing Defender Functionality ---')
90-
cmds.file(new=True, force=True)
91-
92-
defender = MayaVirusDefender()
93-
defender.start()
94-
print('✅ Defender started successfully')
95-
print('✅ Issues detected: {}'.format(defender.have_issues))
96-
97-
# Test scanner functionality
98-
print('\\n--- Testing Scanner Functionality ---')
99-
scanner = MayaVirusScanner()
100-
print('✅ Scanner created successfully')
101-
102-
# Test file system utilities
103-
print('\\n--- Testing File System Utilities ---')
104-
from maya_umbrella.filesystem import write_file, read_file
105-
106-
test_file = '/tmp/test_maya_umbrella.txt'
107-
test_content = 'Maya Umbrella Python 2.7 Test'
51+
mayapy scripts/test_maya_docker_integration.py --maya-version ${{ matrix.maya-version }}
10852
109-
write_file(test_file, test_content)
110-
read_content = read_file(test_file)
111-
112-
if read_content.strip() == test_content:
113-
print('✅ File system utilities working correctly')
114-
else:
115-
raise Exception('File system test failed')
116-
117-
# Clean up
118-
os.remove(test_file)
119-
maya.standalone.uninitialize()
120-
121-
print('\\n🎉 All Maya ${{ matrix.maya-version }} Python 2.7 tests passed!')
122-
123-
except Exception as e:
124-
print('❌ ERROR: {}'.format(e))
125-
import traceback
126-
traceback.print_exc()
127-
sys.exit(1)
128-
"
129-
130-
- name: Test Maya Umbrella vaccines in Maya ${{ matrix.maya-version }}
53+
- name: Verify Maya Umbrella installation in Maya ${{ matrix.maya-version }}
13154
run: |
13255
docker run --rm \
13356
-v ${{ github.workspace }}:/workspace \
@@ -140,42 +63,12 @@ except Exception as e:
14063
mayapy -c "
14164
import sys
14265
sys.path.insert(0, '/workspace')
143-
14466
try:
145-
import maya.standalone
146-
maya.standalone.initialize()
147-
148-
import maya.cmds as cmds
149-
cmds.file(new=True, force=True)
150-
151-
print('\\n--- Testing Individual Vaccines ---')
152-
from maya_umbrella.vaccines import get_all_vaccines
153-
154-
vaccines = get_all_vaccines()
155-
for vaccine in vaccines:
156-
try:
157-
vaccine_name = vaccine.__class__.__name__
158-
print('Testing vaccine: {}'.format(vaccine_name))
159-
160-
# Test vaccine initialization
161-
vaccine_instance = vaccine()
162-
print(' ✅ {} initialized successfully'.format(vaccine_name))
163-
164-
# Test vaccine scan (if method exists)
165-
if hasattr(vaccine_instance, 'scan'):
166-
result = vaccine_instance.scan()
167-
print(' ✅ {} scan completed'.format(vaccine_name))
168-
169-
except Exception as e:
170-
print(' ❌ {} failed: {}'.format(vaccine_name, e))
171-
172-
maya.standalone.uninitialize()
173-
print('\\n✅ Vaccine testing completed')
174-
67+
from maya_umbrella import __version__
68+
print('Maya Umbrella version: {}'.format(__version__))
69+
print('✅ Maya Umbrella installation verified')
17570
except Exception as e:
176-
print('❌ ERROR: {}'.format(e))
177-
import traceback
178-
traceback.print_exc()
71+
print('❌ Installation verification failed: {}'.format(e))
17972
sys.exit(1)
18073
"
18174

.github/workflows/windows-python27-test.yml

Lines changed: 2 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -33,191 +33,16 @@ jobs:
3333
python -c "
3434
import sys
3535
import platform
36-
print('=' * 60)
37-
print('Windows Python 2.7 Compatibility Test')
38-
print('=' * 60)
3936
print('Python version:', sys.version)
40-
print('Python executable:', sys.executable)
4137
print('Platform:', platform.platform())
4238
print('Architecture:', platform.architecture())
4339
"
4440
45-
- name: Test Core Module Imports (Python 2.7)
41+
- name: Run Python 2.7 Compatibility Tests
4642
run: |
47-
python -c "
48-
import sys
49-
import os
50-
51-
# Add project root to Python path
52-
project_root = os.getcwd()
53-
sys.path.insert(0, project_root)
54-
55-
try:
56-
print('\\n--- Testing Core Module Imports ---')
57-
58-
# Test filesystem utilities
59-
from maya_umbrella.filesystem import write_file, read_file
60-
print('✅ Filesystem utilities imported successfully')
61-
62-
# Test vaccines module
63-
from maya_umbrella.vaccines import get_all_vaccines
64-
vaccines = get_all_vaccines()
65-
print('✅ Vaccines module imported: {} vaccines available'.format(len(vaccines)))
66-
67-
# List available vaccines
68-
for vaccine in vaccines:
69-
print(' - {}'.format(vaccine.__class__.__name__))
70-
71-
# Test version module
72-
from maya_umbrella import __version__
73-
print('✅ Version module imported: {}'.format(__version__))
74-
75-
print('\\n🎉 All core module imports successful on Python 2.7!')
76-
77-
except Exception as e:
78-
print('❌ ERROR: {}'.format(e))
79-
import traceback
80-
traceback.print_exc()
81-
sys.exit(1)
82-
"
83-
84-
- name: Test Python 2.7 Syntax Compatibility
85-
run: |
86-
python -c "
87-
import sys
88-
import os
89-
sys.path.insert(0, os.getcwd())
90-
91-
try:
92-
print('\\n--- Testing Python 2.7 Syntax Compatibility ---')
93-
94-
# Test string formatting (Python 2.7 style)
95-
test_string = 'Test message: {}'.format('success')
96-
print('✅ String formatting: {}'.format(test_string))
97-
98-
# Test dictionary operations
99-
test_dict = {'key1': 'value1', 'key2': 'value2'}
100-
for key, value in test_dict.items():
101-
print('✅ Dictionary iteration: {} = {}'.format(key, value))
102-
103-
# Test list comprehensions
104-
test_list = [x * 2 for x in range(5)]
105-
print('✅ List comprehension: {}'.format(test_list))
106-
107-
# Test exception handling
108-
try:
109-
raise ValueError('Test exception')
110-
except ValueError as e:
111-
print('✅ Exception handling: {}'.format(e))
112-
113-
# Test file operations
114-
import tempfile
115-
temp_file = tempfile.mktemp(suffix='.txt')
116-
117-
with open(temp_file, 'w') as f:
118-
f.write('Python 2.7 test content')
119-
120-
with open(temp_file, 'r') as f:
121-
content = f.read()
122-
123-
if content == 'Python 2.7 test content':
124-
print('✅ File operations working correctly')
125-
126-
os.remove(temp_file)
43+
python scripts/test_windows_python27_ci.py
12744
128-
print('\\n🎉 All Python 2.7 syntax compatibility tests passed!')
129-
130-
except Exception as e:
131-
print('❌ ERROR: {}'.format(e))
132-
import traceback
133-
traceback.print_exc()
134-
sys.exit(1)
135-
"
136-
137-
- name: Test File System Utilities (Python 2.7)
138-
run: |
139-
python -c "
140-
import sys
141-
import os
142-
import tempfile
143-
sys.path.insert(0, os.getcwd())
14445
145-
try:
146-
print('\\n--- Testing File System Utilities ---')
147-
148-
from maya_umbrella.filesystem import write_file, read_file
149-
150-
# Create temporary test file
151-
temp_dir = tempfile.mkdtemp()
152-
test_file = os.path.join(temp_dir, 'test_python27.txt')
153-
test_content = 'Maya Umbrella Python 2.7 Windows Test\\nLine 2\\nLine 3'
154-
155-
# Test write_file
156-
write_file(test_file, test_content)
157-
print('✅ write_file function works on Python 2.7')
158-
159-
# Test read_file
160-
read_content = read_file(test_file)
161-
if read_content.strip() == test_content.strip():
162-
print('✅ read_file function works on Python 2.7')
163-
else:
164-
raise Exception('File content mismatch')
165-
166-
# Clean up
167-
os.remove(test_file)
168-
os.rmdir(temp_dir)
169-
170-
print('\\n✅ File system utilities compatible with Python 2.7')
171-
172-
except Exception as e:
173-
print('❌ ERROR: {}'.format(e))
174-
import traceback
175-
traceback.print_exc()
176-
sys.exit(1)
177-
"
178-
179-
- name: Test Vaccine Classes (Python 2.7)
180-
run: |
181-
python -c "
182-
import sys
183-
import os
184-
sys.path.insert(0, os.getcwd())
185-
186-
try:
187-
print('\\n--- Testing Vaccine Classes ---')
188-
189-
from maya_umbrella.vaccines import get_all_vaccines
190-
191-
vaccines = get_all_vaccines()
192-
print('Found {} vaccine classes'.format(len(vaccines)))
193-
194-
for vaccine_class in vaccines:
195-
try:
196-
vaccine_name = vaccine_class.__name__
197-
print('Testing vaccine class: {}'.format(vaccine_name))
198-
199-
# Test class instantiation
200-
vaccine_instance = vaccine_class()
201-
print(' ✅ {} instantiated successfully'.format(vaccine_name))
202-
203-
# Test common attributes
204-
if hasattr(vaccine_instance, 'name'):
205-
print(' ✅ {} has name attribute: {}'.format(vaccine_name, vaccine_instance.name))
206-
207-
if hasattr(vaccine_instance, 'description'):
208-
print(' ✅ {} has description attribute'.format(vaccine_name))
209-
210-
except Exception as e:
211-
print(' ❌ {} failed: {}'.format(vaccine_name, e))
212-
213-
print('\\n✅ Vaccine class testing completed on Python 2.7')
214-
215-
except Exception as e:
216-
print('❌ ERROR: {}'.format(e))
217-
import traceback
218-
traceback.print_exc()
219-
sys.exit(1)
220-
"
22146
22247
windows-python27-summary:
22348
name: Windows Python 2.7 Test Summary

0 commit comments

Comments
 (0)