-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(api): install opentrons and simulate (#17048)
- Loading branch information
Showing
11 changed files
with
574 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,5 @@ opentrons-robot-app.tar.gz | |
mock_dir | ||
.npm-cache/ | ||
.eslintcache | ||
|
||
package-testing/results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
VENV_DIR ?= venv | ||
RESULTS_DIR ?= results | ||
TESTS ?= all | ||
|
||
.PHONY: setup | ||
setup: | ||
@echo "Setting up environment for Unix-like system..." | ||
./setup.sh $(VENV_DIR) | ||
|
||
.PHONY: setup-windows | ||
setup-windows: | ||
@echo "Setting up environment for Windows..." | ||
pwsh -ExecutionPolicy Bypass -File ./setup.ps1 $(VENV_DIR) | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "Removing the results directory $(RESULTS_DIR)..." | ||
rm -rf $(RESULTS_DIR) || true | ||
|
||
.PHONY: clean-windows | ||
clean-windows: | ||
@echo "Removing the results directory $(RESULTS_DIR)..." | ||
pwsh -Command "if (Test-Path '$(RESULTS_DIR)') { Remove-Item -Recurse -Force '$(RESULTS_DIR)' }" | ||
|
||
.PHONY: teardown | ||
teardown: clean | ||
rm -rf $(VENV_DIR) || true | ||
|
||
.PHONY: teardown-windows | ||
teardown-windows: clean-windows | ||
pwsh -Command "if (Test-Path '$(VENV_DIR)') { Remove-Item -Recurse -Force '$(VENV_DIR)' }" | ||
|
||
|
||
|
||
.PHONY: test | ||
test: clean | ||
@echo "Running $(TESTS) tests for Unix-like system..." | ||
python run_tests.py $(VENV_DIR) $(RESULTS_DIR) $(TESTS) | ||
|
||
.PHONY: test-windows | ||
test-windows: clean-windows | ||
@echo "Running $(TESTS) tests for Windows..." | ||
python run_tests.py $(VENV_DIR) $(RESULTS_DIR) $(TESTS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Test Scripts for the opentrons package | ||
|
||
## Structure | ||
|
||
- Makefile has targets for setting up, tearing down, and running tests for windows and unix-ish systems | ||
- setup.\* is the script run create the virtual environment and install the packages | ||
- help.\* is a script to test --help | ||
- simulate.\* is a script to test that the simulation runs and produces the expected status code | ||
- run_tests.py is the main script that drives test execution and contains the test mapping data | ||
|
||
## Use the tests on Linux and Mac | ||
|
||
1. cd package-testing | ||
2. pyenv local 3.10 | ||
3. make setup - note that this deletes and recreates the virtual environment | ||
4. make test | ||
|
||
## Use the tests on Windows | ||
|
||
- powershell is mapped to pwsh and is version 7 | ||
- python is on the path is version 3.10.\* | ||
|
||
1. cd package-testing | ||
2. make setup-windows - note that this deletes and recreates the virtual environment | ||
3. make test-windows | ||
|
||
## Notes | ||
|
||
- find . -name "\*.sh" -exec shellcheck {} + | ||
|
||
## TODO | ||
|
||
- setup shellcheck and python linting | ||
- more tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
<# | ||
.SYNOPSIS | ||
Validate `opentrons_simulate --help`. | ||
.PARAMETER TestKey | ||
The test key to identify the test. | ||
.PARAMETER ExpectedOutput | ||
The expected string to validate in the output of `opentrons_simulate --help`. | ||
.PARAMETER Venv | ||
The virtual environment directory (default: "venv"). | ||
.PARAMETER ResultDir | ||
The result directory to store logs (default: "results"). | ||
#> | ||
|
||
param ( | ||
[string]$TestKey, | ||
[string]$ExpectedOutput, | ||
[string]$Venv = "venv", | ||
[string]$ResultDir = "results" | ||
) | ||
|
||
# Ensure the result directory exists | ||
if (-not (Test-Path -Path $ResultDir)) { | ||
New-Item -ItemType Directory -Path $ResultDir | Out-Null | ||
} | ||
|
||
$resultFile = Join-Path -Path $ResultDir -ChildPath "$TestKey.txt" | ||
|
||
Write-Output "Activating virtual environment $Venv..." | ||
$venvActivate = Join-Path -Path $Venv -ChildPath "Scripts/Activate.ps1" | ||
if (-not (Test-Path -Path $venvActivate)) { | ||
Write-Error "FAIL: Virtual environment not found at $venv" | ||
exit 1 | ||
} | ||
|
||
# Source the virtual environment | ||
& $venvActivate | ||
|
||
Write-Output "Validating opentrons_simulate --help for test: $TestKey..." | ||
|
||
# Run the command and capture the output and return code | ||
$output = & opentrons_simulate --help 2>&1 | ||
$returnCode = $LASTEXITCODE | ||
|
||
if ($returnCode -ne 0) { | ||
Write-Output "FAIL: Return code is $returnCode, expected 0" | Tee-Object -FilePath $resultFile | ||
Write-Output "Output was:" | Add-Content -Path $resultFile | ||
$output | Add-Content -Path $resultFile | ||
Rename-Item -Path $resultFile -NewName "${resultFile.Substring(0, $resultFile.Length - 4)}_FAIL.txt" | ||
exit 1 | ||
} | ||
|
||
Write-Output "PASS: Return code is $returnCode, expected 0" | Tee-Object -FilePath $resultFile | ||
Write-Output "Output was:" | Add-Content -Path $resultFile | ||
$output | Add-Content -Path $resultFile | ||
|
||
if ($output -match [regex]::Escape($ExpectedOutput)) { | ||
Write-Output "PASS: Output contains expected string" | Tee-Object -FilePath $resultFile -Append | ||
Write-Output "PASS: Test $TestKey completed successfully." | Tee-Object -FilePath $resultFile -Append | ||
exit 0 | ||
} | ||
|
||
Write-Output "FAIL: Output does not contain expected string" | Tee-Object -FilePath $resultFile -Append | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Function to validate `opentrons_simulate --help` | ||
# Arguments: | ||
# 1. Test Key (required) | ||
# 2. Virtual Environment Directory (optional, default: "venv") | ||
# 3. Result Directory (optional, default: "results") | ||
test_opentrons_simulate_help() { | ||
local test_key="$1" | ||
local expected_output="${2}" | ||
local venv="${3:-"venv"}" | ||
local result_dir="${4:-"results"}" | ||
mkdir -p "$result_dir" | ||
local result_file="$result_dir/$test_key.txt" | ||
|
||
echo "Activating virtual environment $venv..." | ||
# shellcheck disable=SC1091 | ||
source "$venv/bin/activate" | ||
|
||
echo "Validating opentrons_simulate --help for test: $test_key..." | ||
|
||
local output | ||
local return_code | ||
output=$(opentrons_simulate --help 2>&1) | ||
return_code=$? | ||
|
||
if [ $return_code -ne 0 ]; then | ||
echo "FAIL: Return code is $return_code, expected 0" | tee "$result_file" | ||
echo "Output was:" >> "$result_file" | ||
echo "$output" >> "$result_file" | ||
mv "$result_file" "${result_file%.txt}_FAIL.txt" | ||
return 1 | ||
fi | ||
|
||
echo "PASS: Return code is $return_code, expected 0" | tee "$result_file" | ||
echo "Output was:" >> "$result_file" | ||
echo "$output" >> "$result_file" | ||
|
||
if echo "$output" | grep -q "$expected_output"; then | ||
echo "PASS: Output contains expected string" | tee -a "$result_file" | ||
echo "PASS: Test $test_key completed successfully." | tee -a "$result_file" | ||
return 0 | ||
fi | ||
echo "FAIL: Output does not contain expected string" | tee -a "$result_file" | ||
return 1 | ||
} | ||
|
||
test_opentrons_simulate_help "$@" |
Oops, something went wrong.