-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bat
More file actions
116 lines (94 loc) · 5.05 KB
/
Copy pathtest.bat
File metadata and controls
116 lines (94 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@echo off
setlocal EnableDelayedExpansion
set BL_PATHS_FILE=blender_paths.txt
rem Checks, if there is a "blender_paths.txt"
if not exist "%BL_PATHS_FILE%" (
echo No %BL_PATHS_FILE% found. Example:
echo %BL_PATHS_FILE%
echo full/path/here/blender.exe
echo full/path/to/another/version/here/blender.exe
goto :EOF
)
rem Counts up the lines inside "blender_paths.txt", that contain blender paths
set /a NUM_BL_PATHS=0
for /f "tokens=* usebackq" %%i in ("%BL_PATHS_FILE%") do (
set /a NUM_BL_PATHS+=1
set BL_PATH_!NUM_BL_PATHS!=%%i
)
rem If no blender paths were found, the "blender_paths.txt" is empty
if "%NUM_BL_PATHS%" == "0" (
echo No blender paths found in %BL_PATHS_FILE%
goto :EOF
)
echo On which Blender version would you like to run tests?
rem Sets the default selected Blender version to the first one in the list
set /a SELECTED_BL_PATH=1
:LOOP
for /l %%i in (1,1,%NUM_BL_PATHS%) do (
if "%%i"=="%SELECTED_BL_PATH%" (
echo [x] !BL_PATH_%%i!
) else (
echo [ ] !BL_PATH_%%i!
)
)
rem goto multi-line-comment
rem :multi-line-comment
rem Prompts the user to choose a Blender version by displaying a list of options and waiting for the user to input a character corresponding to the desired option. The /c option specifies the list of valid characters, /n indicates that no prompt message should be displayed, /m specifies the prompt message, /t specifies the timeout in seconds (10 in this case), and /d specifies the default choice if the user doesn't enter anything.
choice /c 123456789abcdefghijklmnopqrstuvwxyz /n /m "Choose a Blender version [1-%NUM_BL_PATHS%, q to quit]: " /t 10 /d 1
set KEY=%errorlevel%
if "%KEY%" lss 11 (
set /a SELECTED_BL_PATH=%KEY%
goto :TEST
) else if "%KEY%" equ "27" (
goto :EOF
) else (
goto :LOOP
)
:TEST
rem Assigns the value of the variable BL_PATH_%SELECTED_BL_PATH% (which corresponds to the selected Blender version path) to the variable BL_PATH.
set BL_PATH=!BL_PATH_%SELECTED_BL_PATH%!
rem Checks if the file or directory specified by BL_PATH exists.
if not exist "!BL_PATH!" (
echo Invalid path: !BL_PATH!
goto :EOF
)
rem This checks if the pytest package is installed in the Python environment. If it isn't, the script installs it using pip install pytest. If the installation fails, the script prints an error message (Failed to install pytest.).
echo Checking if pytest is installed...
pip show pytest > nul
if %errorlevel% neq 0 (
echo Installing pytest...
pip install pytest > nul 2>&1 || echo Failed to install pytest.
) else (
echo pytest is already installed.
)
rem This checks if the pytest-blender package is installed in the Python environment. If it isn't, the script installs it using pip install pytest-blender --blender-executable "!BL_PATH!". The --blender-executable option specifies the path to the Blender executable to use for running the tests. If the installation fails, the script prints an error message (Failed to install pytest-blender.).
echo Checking if pytest-blender is installed...
pip show pytest-blender > nul
if %errorlevel% neq 0 (
echo Installing pytest-blender...
pip install pytest-blender --blender-executable "!BL_PATH!" > nul 2>&1 || echo Failed to install pytest-blender.
) else (
echo pytest-blender is already installed.
)
rem This determines the path to the Python interpreter that will be used to run the tests. It does this by running pytest-blender --blender-executable "!BL_PATH!" and capturing the output using a for loop. If the path to the interpreter can't be determined, the script prints an error message (Failed to determine location of the Python interpreter.) and exits the code block.
echo Determining location of the Python interpreter...
set PYTHON_EXE=
for /f "tokens=*" %%i in ('pytest-blender --blender-executable "!BL_PATH!"') do set PYTHON_EXE=%%i
if not defined PYTHON_EXE (
echo Failed to determine location of the Python interpreter.
goto :EOF
)
rem This checks if the test requirements (specified in test-requirements.txt) are already installed in the Python environment. If they aren't, the script installs them using pip install -r test-requirements.txt. If the installation fails, the script prints an error message (`Failed to install test requirements
echo Checking if test requirements are already installed...
"%PYTHON_EXE%" -m pip freeze | findstr /i /c:"pytest==" > nul
if %errorlevel% neq 0 (
echo Installing test requirements...
"%PYTHON_EXE%" -m pip install -r test-requirements.txt > nul 2>&1 || echo Failed to install test requirements.
) else (
echo Test requirements are already installed.
)
echo Running tests...
rem This line executes the pytest command with the --blender-executable flag set to the selected Blender version path stored in the BL_PATH variable. It also specifies the directory where the tests are located using the tests argument. This command will run all the tests in the tests directory using the selected Blender version.
pytest --blender-executable "!BL_PATH!" tests --verbose
pause
endlocal