diff --git a/.github/workflows/run-templates.yml b/.github/workflows/run-templates.yml deleted file mode 100644 index e750daa..0000000 --- a/.github/workflows/run-templates.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Run Python Mock-up Data Script - -on: - schedule: - # Run every weekday at 7:00 AM UTC - - cron: "0 7 * * 1-5" - # Run the script from GitHub interface - workflow_dispatch: - -jobs: - execute-python-scripts: - runs-on: ubuntu-latest - - steps: - # Checkout the repository - - name: Checkout code - uses: actions/checkout@v3 - - # Set up Python environment - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - # Install tofupilot package - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - # Set TOFUPILOT_API_KEY and run all Python files in corresponding folder - - name: Run Battery-Testing Script - env: - TOFUPILOT_API_KEY: ${{ secrets.GET_STARTED_BATTERY_API_KEY }} - run: | - cd welcome_aboard/battery_testing - for i in {1..10}; do - echo "Execution $i" - python main.py - done diff --git a/.github/workflows/test-scripts.yml b/.github/workflows/test-scripts.yml deleted file mode 100644 index d712852..0000000 --- a/.github/workflows/test-scripts.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Run Python Scripts - -on: - push: - branches: - - main - pull_request: - branches: - - main - # Run the script from GitHub interface - workflow_dispatch: - -jobs: - execute-python-scripts: - # Running on both ubuntu and windows - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - runs-on: ${{ matrix.os }} - - env: - TOFUPILOT_API_KEY: ${{ secrets.PRODUCTION_API_KEY}} - # Forcing Python to run in UTF-8 mode for all steps in this job - PYTHONUTF8: "1" - - steps: - # Checking out the repository - - name: Checking out the repository - uses: actions/checkout@v3 - - - name: Changing code page to UTF-8 (Windows only) - if: runner.os == 'Windows' - run: chcp 65001 - - # Setting up Python - - name: Setting up Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - # Installing dependencies - - name: Installing dependencies - shell: bash - run: | - if [[ "$RUNNER_OS" == "Windows" ]]; then - python -m pip install --upgrade pip - else - pip install --upgrade pip - fi - - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - # Running all Python scripts - - name: Running all Python scripts - shell: bash - run: | - find . -type f -name 'main.py' \ - -not -path '*/venv/*' \ - -not -path '*/.*/*' \ - -print0 | while IFS= read -r -d '' file; do - - directory="$(dirname "$file")" - - if [ -f "$directory/requirements.txt" ]; then - pip install -r "$directory/requirements.txt" - fi - - echo "Running files in $directory" - - ( - cd "$directory" || exit - python main.py - ) - done diff --git a/docs_tofupilot/api_v1/assembly_test_with_voltage_sampling.py b/docs_tofupilot/api_v1/assembly_test_with_voltage_sampling.py new file mode 100644 index 0000000..3ba6708 --- /dev/null +++ b/docs_tofupilot/api_v1/assembly_test_with_voltage_sampling.py @@ -0,0 +1,417 @@ +import random +from datetime import datetime, timedelta + +from tofupilot import TofuPilotClient + +client = TofuPilotClient() + + +# Simulate passing probability for a test result +def simulate_test_result(passed_prob): + return random.random() < passed_prob + + +# Cell Test Functions +def esr_test(): + passed = simulate_test_result(0.98) + value_measured = ( + round( + random.uniform( + 5, + 10), + 2) if passed else round( + random.uniform( + 15, + 20), + 2)) + return passed, value_measured, "mΩ", 5, 15 + + +def cell_voltage_test(): + passed = simulate_test_result(0.98) + value_measured = ( + round(random.uniform(3.0, 3.5), 2) + if passed + else round(random.uniform(2.5, 2.9), 2) + ) + return passed, value_measured, "V", 3.0, 3.5 + + +def ir_test(): + passed = simulate_test_result(0.98) + value_measured = ( + round( + random.uniform( + 5, + 10), + 2) if passed else round( + random.uniform( + 15, + 20), + 2)) + return passed, value_measured, "mΩ", 5, 15 + + +def charge_discharge_cycle_test(): + passed = simulate_test_result(0.95) + value_measured = ( + round(random.uniform(95, 100), 1) + if passed + else round(random.uniform(80, 94), 1) + ) + return passed, value_measured, "% Capacity", 95, 100 + + +# PCBA Test function +def flash_firmware_and_version(): + passed = simulate_test_result(0.99) + value_measured = "1.2.8" if passed else None + return passed, value_measured, None, None, None + + +def configuration_battery_gauge(): + passed = simulate_test_result(0.98) + return passed, None, None, None, None + + +def get_calibration_values_and_internal_statuses(): + passed = simulate_test_result(0.98) + return passed, None, None, None, None + + +def overvoltage_protection_test(): + passed = simulate_test_result(0.98) + value_measured = ( + round(random.uniform(4.20, 4.25), 3) + if passed + else round(random.uniform(4.30, 4.35), 3) + ) + return passed, value_measured, "V", 4.20, 4.25 + + +def undervoltage_protection_test(): + passed = simulate_test_result(0.98) + value_measured = ( + round(random.uniform(2.5, 2.6), 2) + if passed + else round(random.uniform(2.3, 2.4), 2) + ) + return passed, value_measured, "V", 2.5, 2.6 + + +def test_LED_and_button(): + passed = simulate_test_result(0.95) + return passed, None, None, None, None + + +def save_information_in_memory(): + passed = simulate_test_result(0.99) + return passed, None, None, None, None + + +def config_battery_gauge(): + passed = simulate_test_result(0.95) + return passed, None, None, None, None + + +def calibrate_temperature(): + passed = simulate_test_result(0.98) + value_measured = round(random.uniform(20.0, 25.0), 1) + return passed, value_measured, "°C", 20, 25 + + +# Assembly Test Functions +def battery_connection(): + passed = simulate_test_result(1.0) + return passed, None, None, None, None + + +def voltage_value(): + passed = simulate_test_result(0.98) + value_measured = ( + round(random.uniform(10.0, 12.0), 2) + if passed + else round(random.uniform(8.0, 9.5), 2) + ) + return passed, value_measured, "V", 10.0, 12.0 + + +def voltage_sampling_test(): + """ + Multi-dimensional voltage sampling test. + Samples 100 voltage measurements over time. + Returns: (passed, measurements, units, limit_low, limit_high) + where measurements is a list of (timestamp, voltage) tuples + """ + passed_prob = 0.98 + num_samples = 100 + limit_low = 10.0 + limit_high = 12.0 + + measurements = [] + all_passed = True + + # Simulate voltage measurements over time + for i in range(num_samples): + timestamp = i / num_samples # Time in seconds (0 to 0.99) + + # Determine if this sample should pass + sample_passed = simulate_test_result(passed_prob) + + if sample_passed: + voltage = round(random.uniform(limit_low, limit_high), 2) + else: + voltage = round(random.uniform(8.0, 9.5), 2) + all_passed = False + + measurements.append((timestamp, voltage)) + + # Return multi-dimensional measurement + # Format: (passed, value_measured, unit, limit_low, limit_high) + # For multi-dimensional, value_measured is the list of tuples + # and unit should be a list of units for each dimension + return all_passed, measurements, ["s", "V"], limit_low, limit_high + + +def internal_resistance(): + passed = simulate_test_result(0.98) + value_measured = ( + round( + random.uniform( + 5, + 10), + 2) if passed else round( + random.uniform( + 15, + 20), + 2)) + return passed, value_measured, "mΩ", 5, 15 + + +def thermal_runaway_detection(): + passed = simulate_test_result(0.98) + value_measured = ( + round( + random.uniform( + 55, + 65), + 2) if passed else round( + random.uniform( + 66, + 70), + 2)) + return passed, value_measured, "°C", 55, 65 + + +def state_of_health(): + passed = simulate_test_result(0.98) + value_measured = ( + round(random.uniform(95, 100), 1) + if passed + else round(random.uniform(85, 94), 1) + ) + return passed, value_measured, "%", 95, None + + +def state_of_charge(): + passed = simulate_test_result(0.98) + value_measured = ( + round( + random.uniform( + 40, + 60), + 1) if passed else round( + random.uniform( + 25, + 35), + 1)) + return passed, value_measured, "%", 40, 60 + + +def visual_inspection(): + passed = simulate_test_result(1) + return passed, None, None, None, None + + +# Run a single test +def run_test(test, duration): + start_time = datetime.now() + passed, value_measured, unit, limit_low, limit_high = test() + + step = { + "name": test.__name__, + "started_at": start_time, + "duration": duration, + "step_passed": passed, + "measurement_unit": unit, + "measurement_value": value_measured, + "limit_low": limit_low, + "limit_high": limit_high, + } + return passed, step + + +def run_all_tests(tests, previous_failed_step=None): + steps = [] + all_tests_passed = True + failed_at_step = None + + for index, (test, duration) in enumerate(tests): + if previous_failed_step is not None and index == previous_failed_step["index"]: + passed = previous_failed_step["step_passed"] + step = previous_failed_step + else: + passed, step = run_test(test, duration) + + steps.append(step) + + if not passed: + failed_at_step = { + "index": index, + "step_passed": passed, + "name": step["name"], + "started_at": step["started_at"], + "duration": step["duration"], + "measurement_unit": step["measurement_unit"], + "measurement_value": step["measurement_value"], + "limit_low": step["limit_low"], + "limit_high": step["limit_high"], + } + all_tests_passed = False + break + + return all_tests_passed, steps, failed_at_step + + +# Run a list of tests sequentially +def handle_procedure( + procedure_id, + tests, + serial_number, + part_number, + revision, + batch_number, + sub_units, + attachments, +): + run_passed, steps, failed_step = run_all_tests(tests) + + if procedure_id == "FVT3" and run_passed: # Assembly Procedure + internal_resistance = steps[2]["measurement_value"] + voltage_value = steps[1]["measurement_value"] + + client.create_run( + procedure_id=procedure_id, + unit_under_test={ + "part_number": part_number, + "revision": revision, + "serial_number": serial_number, + "batch_number": batch_number, + }, + run_passed=run_passed, + steps=steps, + sub_units=sub_units, + attachments=attachments, + ) + return run_passed, failed_step + + +# Main Function for Executing Procedures +def execute_procedures(end): + for _ in range(end): + # Generate unique serial numbers + part_number_cell = "00143" + part_number_pcb = "00786" + part_number_assembly = "SI02430" + revision_cell = "A" + revision_pcb = "B" + revision_assembly = "B" + static_segment = "4J" + random_digits_cell = "".join( + [str(random.randint(0, 9)) for _ in range(5)]) + random_digits_pcb = "".join( + [str(random.randint(0, 9)) for _ in range(5)]) + random_digits_assembly = "".join( + [str(random.randint(0, 9)) for _ in range(5)]) + serial_number_cell = ( + f"{part_number_cell}{revision_cell}{static_segment}{random_digits_cell}" + ) + serial_number_pcb = ( + f"{part_number_pcb}{revision_pcb}{static_segment}{random_digits_pcb}" + ) + serial_number_assembly = f"{part_number_assembly}{revision_assembly}{static_segment}{random_digits_assembly}" + batch_number = "1024" + + # Execute PCBA Tests + tests_pcb = [ + (flash_firmware_and_version, timedelta(seconds=90)), + (configuration_battery_gauge, timedelta(seconds=1)), + (get_calibration_values_and_internal_statuses, timedelta(seconds=1)), + (overvoltage_protection_test, timedelta(seconds=5)), + (undervoltage_protection_test, timedelta(seconds=5)), + (test_LED_and_button, timedelta(seconds=6)), + (save_information_in_memory, timedelta(seconds=0.1)), + (visual_inspection, timedelta(seconds=10)), + ] + passed_pcb, failed_step_pcb = handle_procedure( + "FVT1", + tests_pcb, + serial_number_pcb, + part_number_pcb, + revision_pcb, + batch_number, + None, + ["data/pcb_coating.jpeg"], + ) + if not passed_pcb: + continue + + # Execute Cell Tests + tests_cell = [ + (esr_test, timedelta(seconds=2)), + (cell_voltage_test, timedelta(seconds=0.1)), + (ir_test, timedelta(seconds=5)), + (charge_discharge_cycle_test, timedelta(seconds=2)), + ] + passed_cell, failed_step_cell = handle_procedure( + "FVT2", + tests_cell, + serial_number_cell, + part_number_cell, + revision_cell, + batch_number, + None, + None, + ) + if not passed_cell: + continue + + # Execute Assembly Tests with voltage sampling + tests_assembly = [ + (battery_connection, timedelta(seconds=0.1)), + ( + voltage_sampling_test, + timedelta(seconds=10), + ), # New multi-dimensional test + (internal_resistance, timedelta(seconds=1)), + (thermal_runaway_detection, timedelta(seconds=2)), + (state_of_health, timedelta(seconds=2)), + (state_of_charge, timedelta(seconds=2)), + ] + handle_procedure( + "FVT4", + tests_assembly, + serial_number_assembly, + part_number_assembly, + revision_assembly, + batch_number, + [ + {"serial_number": serial_number_pcb}, + {"serial_number": serial_number_cell}, + ], + None, + ) + + +if __name__ == "__main__": + execute_procedures(1) diff --git a/docs_tofupilot/attachments/client/data/temperature-map.png b/docs_tofupilot/api_v1/attachments/client/data/temperature-map.png similarity index 100% rename from docs_tofupilot/attachments/client/data/temperature-map.png rename to docs_tofupilot/api_v1/attachments/client/data/temperature-map.png diff --git a/docs_tofupilot/attachments/client/main.py b/docs_tofupilot/api_v1/attachments/client/main.py similarity index 100% rename from docs_tofupilot/attachments/client/main.py rename to docs_tofupilot/api_v1/attachments/client/main.py diff --git a/docs_tofupilot/attachments/openhtf/data/temperature-map.png b/docs_tofupilot/api_v1/attachments/openhtf/data/temperature-map.png similarity index 100% rename from docs_tofupilot/attachments/openhtf/data/temperature-map.png rename to docs_tofupilot/api_v1/attachments/openhtf/data/temperature-map.png diff --git a/docs_tofupilot/attachments/openhtf/main.py b/docs_tofupilot/api_v1/attachments/openhtf/main.py similarity index 100% rename from docs_tofupilot/attachments/openhtf/main.py rename to docs_tofupilot/api_v1/attachments/openhtf/main.py diff --git a/docs_tofupilot/integrations/client/main.py b/docs_tofupilot/api_v1/integrations/client/main.py similarity index 100% rename from docs_tofupilot/integrations/client/main.py rename to docs_tofupilot/api_v1/integrations/client/main.py diff --git a/docs_tofupilot/integrations/openhtf/main.py b/docs_tofupilot/api_v1/integrations/openhtf/main.py similarity index 100% rename from docs_tofupilot/integrations/openhtf/main.py rename to docs_tofupilot/api_v1/integrations/openhtf/main.py diff --git a/docs_tofupilot/logger/client/main.py b/docs_tofupilot/api_v1/logger/client/main.py similarity index 100% rename from docs_tofupilot/logger/client/main.py rename to docs_tofupilot/api_v1/logger/client/main.py diff --git a/docs_tofupilot/logger/openhtf/main.py b/docs_tofupilot/api_v1/logger/openhtf/main.py similarity index 100% rename from docs_tofupilot/logger/openhtf/main.py rename to docs_tofupilot/api_v1/logger/openhtf/main.py diff --git a/docs_tofupilot/measurements/boolean/client/main.py b/docs_tofupilot/api_v1/measurements/boolean/client/main.py similarity index 100% rename from docs_tofupilot/measurements/boolean/client/main.py rename to docs_tofupilot/api_v1/measurements/boolean/client/main.py diff --git a/docs_tofupilot/measurements/boolean/openhtf/main.py b/docs_tofupilot/api_v1/measurements/boolean/openhtf/main.py similarity index 100% rename from docs_tofupilot/measurements/boolean/openhtf/main.py rename to docs_tofupilot/api_v1/measurements/boolean/openhtf/main.py diff --git a/docs_tofupilot/measurements/dimensional/client/main.py b/docs_tofupilot/api_v1/measurements/dimensional/client/main.py similarity index 100% rename from docs_tofupilot/measurements/dimensional/client/main.py rename to docs_tofupilot/api_v1/measurements/dimensional/client/main.py diff --git a/docs_tofupilot/measurements/dimensional/openhtf/main.py b/docs_tofupilot/api_v1/measurements/dimensional/openhtf/main.py similarity index 100% rename from docs_tofupilot/measurements/dimensional/openhtf/main.py rename to docs_tofupilot/api_v1/measurements/dimensional/openhtf/main.py diff --git a/docs_tofupilot/measurements/multi-measurements/client/main.py b/docs_tofupilot/api_v1/measurements/multi-measurements/client/main.py similarity index 100% rename from docs_tofupilot/measurements/multi-measurements/client/main.py rename to docs_tofupilot/api_v1/measurements/multi-measurements/client/main.py diff --git a/docs_tofupilot/measurements/multi-measurements/openhtf/main.py b/docs_tofupilot/api_v1/measurements/multi-measurements/openhtf/main.py similarity index 100% rename from docs_tofupilot/measurements/multi-measurements/openhtf/main.py rename to docs_tofupilot/api_v1/measurements/multi-measurements/openhtf/main.py diff --git a/docs_tofupilot/measurements/numerical/client/main.py b/docs_tofupilot/api_v1/measurements/numerical/client/main.py similarity index 100% rename from docs_tofupilot/measurements/numerical/client/main.py rename to docs_tofupilot/api_v1/measurements/numerical/client/main.py diff --git a/docs_tofupilot/measurements/numerical/openhtf/main.py b/docs_tofupilot/api_v1/measurements/numerical/openhtf/main.py similarity index 100% rename from docs_tofupilot/measurements/numerical/openhtf/main.py rename to docs_tofupilot/api_v1/measurements/numerical/openhtf/main.py diff --git a/docs_tofupilot/measurements/string/client/main.py b/docs_tofupilot/api_v1/measurements/string/client/main.py similarity index 100% rename from docs_tofupilot/measurements/string/client/main.py rename to docs_tofupilot/api_v1/measurements/string/client/main.py diff --git a/docs_tofupilot/measurements/string/openhtf/main.py b/docs_tofupilot/api_v1/measurements/string/openhtf/main.py similarity index 100% rename from docs_tofupilot/measurements/string/openhtf/main.py rename to docs_tofupilot/api_v1/measurements/string/openhtf/main.py diff --git a/docs_tofupilot/offline-upload/client/main.py b/docs_tofupilot/api_v1/offline-upload/client/main.py similarity index 100% rename from docs_tofupilot/offline-upload/client/main.py rename to docs_tofupilot/api_v1/offline-upload/client/main.py diff --git a/docs_tofupilot/offline-upload/openhtf/data/PCB01A69658.openhtf_test.2025-01-20_15-32-06-058.json b/docs_tofupilot/api_v1/offline-upload/openhtf/data/PCB01A69658.openhtf_test.2025-01-20_15-32-06-058.json similarity index 100% rename from docs_tofupilot/offline-upload/openhtf/data/PCB01A69658.openhtf_test.2025-01-20_15-32-06-058.json rename to docs_tofupilot/api_v1/offline-upload/openhtf/data/PCB01A69658.openhtf_test.2025-01-20_15-32-06-058.json diff --git a/docs_tofupilot/offline-upload/openhtf/main.py b/docs_tofupilot/api_v1/offline-upload/openhtf/main.py similarity index 100% rename from docs_tofupilot/offline-upload/openhtf/main.py rename to docs_tofupilot/api_v1/offline-upload/openhtf/main.py diff --git a/docs_tofupilot/phases/advanced/client/main.py b/docs_tofupilot/api_v1/phases/advanced/client/main.py similarity index 100% rename from docs_tofupilot/phases/advanced/client/main.py rename to docs_tofupilot/api_v1/phases/advanced/client/main.py diff --git a/docs_tofupilot/phases/advanced/openhtf/main.py b/docs_tofupilot/api_v1/phases/advanced/openhtf/main.py similarity index 100% rename from docs_tofupilot/phases/advanced/openhtf/main.py rename to docs_tofupilot/api_v1/phases/advanced/openhtf/main.py diff --git a/docs_tofupilot/phases/optional/client/main.py b/docs_tofupilot/api_v1/phases/optional/client/main.py similarity index 100% rename from docs_tofupilot/phases/optional/client/main.py rename to docs_tofupilot/api_v1/phases/optional/client/main.py diff --git a/docs_tofupilot/phases/optional/openhtf/main.py b/docs_tofupilot/api_v1/phases/optional/openhtf/main.py similarity index 100% rename from docs_tofupilot/phases/optional/openhtf/main.py rename to docs_tofupilot/api_v1/phases/optional/openhtf/main.py diff --git a/docs_tofupilot/phases/required/client/main.py b/docs_tofupilot/api_v1/phases/required/client/main.py similarity index 100% rename from docs_tofupilot/phases/required/client/main.py rename to docs_tofupilot/api_v1/phases/required/client/main.py diff --git a/docs_tofupilot/phases/required/openhtf/main.py b/docs_tofupilot/api_v1/phases/required/openhtf/main.py similarity index 100% rename from docs_tofupilot/phases/required/openhtf/main.py rename to docs_tofupilot/api_v1/phases/required/openhtf/main.py diff --git a/docs_tofupilot/procedures/client/main.py b/docs_tofupilot/api_v1/procedures/client/main.py similarity index 100% rename from docs_tofupilot/procedures/client/main.py rename to docs_tofupilot/api_v1/procedures/client/main.py diff --git a/docs_tofupilot/procedures/openhtf/main.py b/docs_tofupilot/api_v1/procedures/openhtf/main.py similarity index 100% rename from docs_tofupilot/procedures/openhtf/main.py rename to docs_tofupilot/api_v1/procedures/openhtf/main.py diff --git a/docs_tofupilot/stations/client/main.py b/docs_tofupilot/api_v1/stations/client/main.py similarity index 100% rename from docs_tofupilot/stations/client/main.py rename to docs_tofupilot/api_v1/stations/client/main.py diff --git a/docs_tofupilot/stations/openhtf/main.py b/docs_tofupilot/api_v1/stations/openhtf/main.py similarity index 100% rename from docs_tofupilot/stations/openhtf/main.py rename to docs_tofupilot/api_v1/stations/openhtf/main.py diff --git a/docs_tofupilot/sub-units/client/main.py b/docs_tofupilot/api_v1/sub-units/client/main.py similarity index 100% rename from docs_tofupilot/sub-units/client/main.py rename to docs_tofupilot/api_v1/sub-units/client/main.py diff --git a/docs_tofupilot/sub-units/openhtf/main.py b/docs_tofupilot/api_v1/sub-units/openhtf/main.py similarity index 100% rename from docs_tofupilot/sub-units/openhtf/main.py rename to docs_tofupilot/api_v1/sub-units/openhtf/main.py diff --git a/docs_tofupilot/unit-under-test/client/main.py b/docs_tofupilot/api_v1/unit-under-test/client/main.py similarity index 100% rename from docs_tofupilot/unit-under-test/client/main.py rename to docs_tofupilot/api_v1/unit-under-test/client/main.py diff --git a/docs_tofupilot/unit-under-test/openhtf/main.py b/docs_tofupilot/api_v1/unit-under-test/openhtf/main.py similarity index 100% rename from docs_tofupilot/unit-under-test/openhtf/main.py rename to docs_tofupilot/api_v1/unit-under-test/openhtf/main.py diff --git a/testing_examples/client/create_run/basic/main.py b/testing_examples/client/create_run/basic/main.py deleted file mode 100644 index 84fb1bb..0000000 --- a/testing_examples/client/create_run/basic/main.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Basic example showing how to create a test run using the TofuPilotClient. - -This script creates a test run for a unit with the specified serial number and part number, -indicating whether the test passed. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -import random - -from tofupilot import TofuPilotClient - - -def main(): - # Initialize the TofuPilot client. - client = TofuPilotClient() - # Create a test run for the unit with serial number "00102" and part - # number "PCB01" - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220D4K{random_digits}" - client.create_run( - procedure_id="FVT1", - unit_under_test={ - "serial_number": serial_number, - "part_number": "PCB01"}, - run_passed=True, - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/create_run/fpy/main.py b/testing_examples/client/create_run/fpy/main.py deleted file mode 100644 index 2dd951f..0000000 --- a/testing_examples/client/create_run/fpy/main.py +++ /dev/null @@ -1,25 +0,0 @@ -import random -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - -client = TofuPilotClient() - - -def handle_test(): - # Create 2 test for same SN - for testnumber in range(2): - client.create_run( - procedure_id="FVT112", - started_at=datetime.now(), - unit_under_test={ - "part_number": "FPY", - "serial_number": "FPY-0123410", - }, - # First Good, Second KO, to check FPY - run_passed=True if testnumber == 0 else False, - ) - - -if __name__ == "__main__": - handle_test() diff --git a/testing_examples/client/create_run/multiple_sub_units/main.py b/testing_examples/client/create_run/multiple_sub_units/main.py deleted file mode 100644 index 32315d0..0000000 --- a/testing_examples/client/create_run/multiple_sub_units/main.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Example script demonstrating how to create a test run in TofuPilot with multiple sub-units. - -This script creates a test run for a unit with the specified serial number and part number, -and includes multiple sub-units in the run. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -from tofupilot import TofuPilotClient - -# Initialize the TofuPilot client -client = TofuPilotClient() - -# Create a test run for the unit with serial number "00003" and part number "SI002", -# including sub-units with serial numbers "00002" and "00102" -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00003", "part_number": "SI002"}, - run_passed=True, - sub_units=[{"serial_number": "00002"}, {"serial_number": "00102"}], -) diff --git a/testing_examples/client/create_run/phases_string_outcome/main.py b/testing_examples/client/create_run/phases_string_outcome/main.py deleted file mode 100644 index ab964c9..0000000 --- a/testing_examples/client/create_run/phases_string_outcome/main.py +++ /dev/null @@ -1,57 +0,0 @@ -import random -import time - -from tofupilot import TofuPilotClient - -client = TofuPilotClient() - - -def flash_firmware(): - passed = bool(random.randint(0, 1)) - measured_value = "1.2.4" if passed else "1.2.0" - return passed, measured_value, None, None, None - - -def handle_test(): - serial_number = f"SI0364A{random.randint(10000, 99999)}" - - start_time = int(time.time() * 1000) - passed, measured_value, unit, limit_low, limit_high = flash_firmware() - end_time = int(time.time() * 1000) - - outcome = "PASS" if passed else "FAIL" - - phase = { - "name": "flash_firmware", - "outcome": outcome, - "start_time_millis": start_time, - "end_time_millis": end_time, - "measurements": [ - { - "name": "flash_firmware", - "outcome": outcome, - "measured_value": measured_value, - "units": unit, - "lower_limit": limit_low, - "upper_limit": limit_high, - } - ], - } - - client.create_run( - procedure_id="FVT9", - procedure_name="Test_QA", - unit_under_test={ - "part_number": "SI03645A", - "part_name": "test-QA", - "revision": "3.1", - "batch_number": "11-24", - "serial_number": serial_number, - }, - run_passed=passed, - phases=[phase], - ) - - -if __name__ == "__main__": - handle_test() diff --git a/testing_examples/client/create_run/procedure_version/main.py b/testing_examples/client/create_run/procedure_version/main.py deleted file mode 100644 index 9d4ab6e..0000000 --- a/testing_examples/client/create_run/procedure_version/main.py +++ /dev/null @@ -1,53 +0,0 @@ -import random -import time -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - - -def main(): - client = TofuPilotClient() - - # Generate SN - serial_number = f"SI0364A{random.randint(10000, 99999)}" - - # 1 Phase test - start_time_millis = int(time.time() * 1000) - voltage = round(random.uniform(3, 4), 1) - limits = {"limit_low": 3.1, "limit_high": 3.5} - passed = limits["limit_low"] <= voltage <= limits["limit_high"] - outcome = {True: "PASS", False: "FAIL"}[passed] - end_time_millis = int(time.time() * 1000) - - client.create_run( - unit_under_test={ - "part_number": "SI0364", - "serial_number": serial_number, - "revision": "A", - }, - procedure_id="FVT1", # First create procedure in Application - procedure_version="1.2.20", # Create procedure version - phases=[ - { - "name": "test_voltage", - "outcome": outcome, - "start_time_millis": start_time_millis, - "end_time_millis": end_time_millis, - "measurements": [ - { - "name": "voltage_input", - "outcome": outcome, - "measured_value": voltage, - "units": "V", - "lower_limit": limits["limit_low"], - "upper_limit": limits["limit_high"], - }, - ], - }, - ], - run_passed=passed, - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/create_run/single_sub_unit/main.py b/testing_examples/client/create_run/single_sub_unit/main.py deleted file mode 100644 index 5645c7f..0000000 --- a/testing_examples/client/create_run/single_sub_unit/main.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Example script demonstrating how to create a test run in TofuPilot with a single sub-unit. - -This script creates a test run for a unit with the specified serial number and part number, -and includes a single sub-unit in the run. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -from tofupilot import TofuPilotClient - -# Initialize the TofuPilot client -client = TofuPilotClient() - -# Create a test run for the unit with serial number "00002" and part number "SI001", -# including a sub-unit with serial number "00102" -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00002", "part_number": "SI001"}, - run_passed=True, - sub_units=[{"serial_number": "00102"}], -) diff --git a/testing_examples/client/create_run/started_at/main.py b/testing_examples/client/create_run/started_at/main.py deleted file mode 100644 index 9a8e821..0000000 --- a/testing_examples/client/create_run/started_at/main.py +++ /dev/null @@ -1,29 +0,0 @@ -import random -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - - -def main(): - # Initialize the TofuPilot client. - client = TofuPilotClient() - # Create a test run for the unit with serial number "00102" and part - # number "PCB01" - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220D4K{random_digits}" - client.create_run( - procedure_id="FVT1", - unit_under_test={ - "serial_number": serial_number, - "part_number": "PCB01"}, - run_passed=True, - started_at=datetime.now() - - timedelta( - days=1), - duration=timedelta( - seconds=23), - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/create_run/with_all_types_of_phases/main.py b/testing_examples/client/create_run/with_all_types_of_phases/main.py deleted file mode 100644 index 7138be7..0000000 --- a/testing_examples/client/create_run/with_all_types_of_phases/main.py +++ /dev/null @@ -1,89 +0,0 @@ -import random -from datetime import datetime, timedelta -from random import randint - -from tofupilot import TofuPilotClient - -# Reference time to calculate start_time_millis in milliseconds since epoch -epoch = datetime(1970, 1, 1) - - -# Function to calculate milliseconds since epoch -def to_millis(dt): - return int((dt - epoch).total_seconds() * 1000) - - -client = TofuPilotClient() - -client.create_run( - procedure_id="FVT1", - unit_under_test={ - "serial_number": "SN17", - "part_number": "PNrstsrtsr", - "batch_number": "B", - }, - run_passed=True, # Overall run status - phases=[ - { - "name": "phase_connect", # First phase - "outcome": "PASS", - "start_time_millis": to_millis( - datetime.now() - ), # Start time of the step in ms - "end_time_millis": to_millis( - datetime.now() + timedelta(seconds=5, milliseconds=12) - ), # End time in ms - "measurements": [ - { - "name": "numeric_measurement", - "outcome": "PASS", - "measured_value": 12, - "units": "Hertz", - "lower_limit": 1, - "upper_limit": 20, - }, - { - "name": "string_measurement", - "outcome": "PASS", - "measured_value": "Test value", - "units": "Unitless", - "docstring": "This is a string measurement example", - }, - { - "name": "boolean_measurement_true", - "outcome": "PASS", - "measured_value": True, - "units": "BooleanUnit", - "docstring": "This is a boolean measurement example", - }, - { - "name": "boolean_measurement_false", - "outcome": "PASS", - "measured_value": False, - "units": "BooleanUnit", - "docstring": "This is a boolean measurement example", - }, - { - "name": "json_measurement", - "outcome": "PASS", - "measured_value": {"key1": "value1", "key2": 42}, - "units": "JSONUnit", - "docstring": "This is a JSON measurement example", - }, - { - "name": "empty_measurement", - "outcome": "PASS", - "measured_value": None, - "units": "EmptyUnit", - "docstring": "This is a measurement with a null value", - }, - { - "name": "no_value_measurement", - "outcome": "PASS", - "units": "NoValueUnit", - "docstring": "This is a measurement with no value specified", - }, - ], - } - ], -) diff --git a/testing_examples/client/create_run/with_attachments/data/performance-report.pdf b/testing_examples/client/create_run/with_attachments/data/performance-report.pdf deleted file mode 100644 index ce6914b..0000000 Binary files a/testing_examples/client/create_run/with_attachments/data/performance-report.pdf and /dev/null differ diff --git a/testing_examples/client/create_run/with_attachments/data/temperature-map.png b/testing_examples/client/create_run/with_attachments/data/temperature-map.png deleted file mode 100644 index c7eb24b..0000000 Binary files a/testing_examples/client/create_run/with_attachments/data/temperature-map.png and /dev/null differ diff --git a/testing_examples/client/create_run/with_attachments/main.py b/testing_examples/client/create_run/with_attachments/main.py deleted file mode 100644 index 7f9fe21..0000000 --- a/testing_examples/client/create_run/with_attachments/main.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -Example script demonstrating how to create a test run in TofuPilot with attachments. - -This script creates a test run for a unit with the specified serial number and part number, -and includes attachments, such as images and reports, that are related to the test. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -from tofupilot import TofuPilotClient - -# Initialize the TofuPilot client -client = TofuPilotClient() - -# Create a test run for the unit with serial number "00102" and part number "PCB01", -# including attachments such as images and PDF reports -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00102", "part_number": "PCB01"}, - run_passed=True, - attachments=[ - "data/temperature-map.png", # Path to your local files - "data/performance-report.pdf", - ], -) diff --git a/testing_examples/client/create_run/with_duration/main.py b/testing_examples/client/create_run/with_duration/main.py deleted file mode 100644 index d96aaac..0000000 --- a/testing_examples/client/create_run/with_duration/main.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -Example script demonstrating how to create a test run in TofuPilot with the duration of the test. - -This script measures the duration of a test function, then creates a test run for a unit -with the specified serial number and part number, including the duration as part of the run data. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -import time -from datetime import timedelta - -from tofupilot import TofuPilotClient - -# Initialize the TofuPilot client -client = TofuPilotClient() - - -def test_function(): - """ - Simulates a test execution. - """ - # Simulate test execution with a delay - time.sleep(1) # Placeholder for test execution time - return True - - -# Measure the duration of the test_function -start_time = time.time() -run_passed = test_function() -end_time = time.time() -duration = timedelta(seconds=end_time - start_time) # Calculate duration - -# Create a test run for the unit with serial number "00102" and part number "PCB01", -# including the duration of the test -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00102", "part_number": "PCB01"}, - run_passed=run_passed, - duration=duration, # Optional argument to include the duration -) diff --git a/testing_examples/client/create_run/with_phases_and_steps/main.py b/testing_examples/client/create_run/with_phases_and_steps/main.py deleted file mode 100644 index 9c729d6..0000000 --- a/testing_examples/client/create_run/with_phases_and_steps/main.py +++ /dev/null @@ -1,183 +0,0 @@ -import random -from datetime import datetime, timedelta -from random import randint - -from tofupilot import TofuPilotClient - -# Reference time to calculate start_time_millis in milliseconds since epoch -epoch = datetime(1970, 1, 1) - - -# Function to calculate milliseconds since epoch -def to_millis(dt): - return int((dt - epoch).total_seconds() * 1000) - - -client = TofuPilotClient() - -client.create_run( - procedure_id="FVT1", - unit_under_test={ - "serial_number": "SN17", - "part_number": "PNrstsrtsr", - "batch_number": "B", - }, - run_passed=True, # Overall run status - steps=[ - { - "name": "step_connect", # First step - "step_passed": True, # Status of the step - # Duration of the step - "duration": timedelta(seconds=5, milliseconds=12), - "started_at": datetime.now(), # Start time of the step - }, - { - "name": "step_string2", # First step - "step_passed": True, # Status of the step - # Duration of the step - "duration": timedelta(seconds=5, milliseconds=12), - "started_at": datetime.now(), # Start time of the step - "measurement_value": "This is a string", - }, - { - "name": "step_initial_charge_check", # Second step - "step_passed": True, # Status of the step - "duration": timedelta( - seconds=3, milliseconds=100 - ), # Duration of the step (<1s) - "started_at": datetime.now() - + timedelta(seconds=3), # Start time of the second step - "measurement_value": randint(90, 100), # Measured value - }, - { - "name": "step_initial_temp_check", # Third step - "step_passed": True, # Status of the step - "duration": timedelta( - seconds=1, milliseconds=100 - ), # Duration of the step (<1s) - "started_at": datetime.now() - # Start time of the third step - + timedelta(seconds=2, milliseconds=500), - "measurement_value": randint(-5, 20), # Measured temperature value - "measurement_unit": "°C", # Unit of the measurement (temperature) - "limit_low": 0, # Lower limit of acceptable temperature - }, - { - "name": "step_temp_calibration", # Fourth step - "step_passed": False, # Status of the step - "duration": timedelta( - seconds=3, milliseconds=100 - ), # Duration of the step (<1s) - "started_at": datetime.now() - timedelta(days=1, minutes=20), - "measurement_value": randint( - 69, 81 - ), # Measured temperature value after calibration - "measurement_unit": "°C", # Unit of the measurement (temperature) - "limit_low": 70, # Lower limit of acceptable temperature - "limit_high": 80, # Upper limit of acceptable temperature - }, - ], - phases=[ - { - "name": "phase_connect", # First phase - "outcome": "PASS", - "start_time_millis": to_millis( - datetime.now() - ), # Start time of the step in ms - "end_time_millis": to_millis( - datetime.now() + timedelta(seconds=5, milliseconds=12) - ), # End time in ms - "measurements": [ - { - "name": "connectivity_check", - "outcome": "PASS", # Measurement outcome - "measured_value": None, - "units": None, - "lower_limit": None, - "upper_limit": None, - } - ], - }, - { - "name": "phase_initial_charge_check", # Second phase - "outcome": "PASS", - "start_time_millis": to_millis( - datetime.now() + timedelta(seconds=3) - ), # Start time in ms - "end_time_millis": to_millis( - datetime.now() + timedelta(seconds=6, milliseconds=100) - ), # End time in ms - "measurements": [ - { - "name": "initial_charge", - "outcome": "PASS", # Measurement outcome - "measured_value": randint(90, 100), # Measured value - "units": None, - "lower_limit": None, - "upper_limit": None, - }, - { - "name": "initial_temperature", - "outcome": "PASS", # Measurement outcome - # Measured temperature value - "measured_value": randint(-5, 20), - "units": "°C", # Unit of the measurement - "lower_limit": 0, # Lower limit - "upper_limit": None, - }, - { - "name": "initial_temperature_2", - "outcome": "FAIL", # Measurement outcome - # Measured temperature value - "measured_value": randint(-5, 20), - "units": "°C", # Unit of the measurement - "lower_limit": 0, # Lower limit - "upper_limit": 15, # Upper limit - }, - ], - }, - { - "name": "phase_initial_temp_check", # Third phase - "outcome": "PASS", - "start_time_millis": to_millis( - datetime.now() + timedelta(seconds=2, milliseconds=500) - ), # Start time in ms - "end_time_millis": to_millis( - datetime.now() + timedelta(seconds=3, milliseconds=600) - ), # End time in ms - "measurements": [ - { - "name": "initial_temperature", - "outcome": "PASS", # Measurement outcome - # Measured temperature value - "measured_value": randint(-5, 20), - "units": "°C", # Unit of the measurement - "lower_limit": 0, # Lower limit - "upper_limit": None, - } - ], - }, - { - "name": "phase_temp_calibration", # Fourth phase - "outcome": "FAIL", - "start_time_millis": to_millis( - datetime.now() - timedelta(days=1, minutes=20) - ), # Start time in ms - "end_time_millis": to_millis( - datetime.now() - - timedelta(days=1, minutes=20) - + timedelta(seconds=3, milliseconds=100) - ), # End time in ms - "measurements": [ - { - "name": "temperature_calibration", - "outcome": "FAIL", # Measurement outcome - "measured_value": randint(69, 81), # Measured value - "units": "°C", # Unit of the measurement - "lower_limit": 70, # Lower limit - "upper_limit": 80, - } - ], - }, - ], -) diff --git a/testing_examples/client/create_run_from_openhtf_report/basic/main.py b/testing_examples/client/create_run_from_openhtf_report/basic/main.py deleted file mode 100644 index 536f5e9..0000000 --- a/testing_examples/client/create_run_from_openhtf_report/basic/main.py +++ /dev/null @@ -1,36 +0,0 @@ -from openhtf import PhaseResult, Test -from openhtf.output.callbacks import json_factory -from openhtf.plugs import user_input -from tofupilot import TofuPilotClient - -client = TofuPilotClient() - - -# Define a test phase to simulate the power-on procedure -def power_on_test(test): - print("Power on.") - return PhaseResult.CONTINUE - - -# Function to execute the test and save results to a JSON file -def execute_test(file_path): - test = Test(power_on_test, serial_number="PCB01") - - # Set output callback to save the test results as a JSON file - test.add_output_callbacks(json_factory.OutputToJSON(file_path)) - - # Execute the test with a specific device identifier - test.execute(lambda: "0001") - - -def main(): - # Specify the file path for saving test results - file_path = "./test_result.json" - execute_test(file_path) - - # Upload the test results to TofuPilot, specifying the importer type - client.create_run_from_openhtf_report(file_path) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/oscilloscope.jpeg b/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/oscilloscope.jpeg deleted file mode 100644 index d49014b..0000000 Binary files a/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/oscilloscope.jpeg and /dev/null differ diff --git a/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/sample_file.txt b/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/sample_file.txt deleted file mode 100644 index 0089758..0000000 --- a/testing_examples/client/create_run_from_openhtf_report/with_attachments/data/sample_file.txt +++ /dev/null @@ -1 +0,0 @@ -OpenHTF + TofuPilot = <3 \ No newline at end of file diff --git a/testing_examples/client/create_run_from_openhtf_report/with_attachments/main.py b/testing_examples/client/create_run_from_openhtf_report/with_attachments/main.py deleted file mode 100644 index a0189e0..0000000 --- a/testing_examples/client/create_run_from_openhtf_report/with_attachments/main.py +++ /dev/null @@ -1,49 +0,0 @@ -import openhtf as htf -from openhtf import PhaseResult, Test -from openhtf.output.callbacks import json_factory -from openhtf.plugs import user_input -from tofupilot import TofuPilotClient -from tofupilot.openhtf import TofuPilot - -client = TofuPilotClient() - - -# Define a test phase to simulate the power-on procedure -def power_on_test(test): - print("Power on.") - return PhaseResult.CONTINUE - - -# Define a phase that attaches a file -def phase_file_attachment(test): - test.attach_from_file("data/sample_file.txt") - test.attach_from_file("data/oscilloscope.jpeg") - return htf.PhaseResult.CONTINUE - - -# Function to execute the test and save results to a JSON file -def execute_test(file_path): - test = Test( - power_on_test, - phase_file_attachment, - procedure_id="FVT7", - serial_number="PCB01") - - # Set output callback to save the test results as a JSON file - test.add_output_callbacks(json_factory.OutputToJSON(file_path)) - - # Execute the test with a specific device identifier - test.execute(lambda: "0001") - - -def main(): - # Specify the file path for saving test results - file_path = "./test_result.json" - execute_test(file_path) - - # Upload the test results to TofuPilot, specifying the importer type - client.create_run_from_openhtf_report(file_path) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/delete_run/basic/main.py b/testing_examples/client/delete_run/basic/main.py deleted file mode 100644 index e62f1eb..0000000 --- a/testing_examples/client/delete_run/basic/main.py +++ /dev/null @@ -1,13 +0,0 @@ -from tofupilot import TofuPilotClient - -client = TofuPilotClient() - -response = client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00102", "part_number": "PCB01"}, - run_passed=True, -) - -run_id = response.get("id") - -client.delete_run(run_id=run_id) diff --git a/testing_examples/client/delete_unit/basic/main.py b/testing_examples/client/delete_unit/basic/main.py deleted file mode 100644 index 11343f0..0000000 --- a/testing_examples/client/delete_unit/basic/main.py +++ /dev/null @@ -1,15 +0,0 @@ -from tofupilot import TofuPilotClient - -client = TofuPilotClient() - -response = client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "NEW_UNIT", "part_number": "PCB01"}, - run_passed=True, -) - -run_id = response.get("id") - -client.delete_run(run_id=run_id) - -client.delete_unit(serial_number="NEW_UNIT") diff --git a/testing_examples/client/get_runs/basic/data/temperature-map.png b/testing_examples/client/get_runs/basic/data/temperature-map.png deleted file mode 100644 index c7eb24b..0000000 Binary files a/testing_examples/client/get_runs/basic/data/temperature-map.png and /dev/null differ diff --git a/testing_examples/client/get_runs/basic/main.py b/testing_examples/client/get_runs/basic/main.py deleted file mode 100644 index ba6e286..0000000 --- a/testing_examples/client/get_runs/basic/main.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -Example script demonstrating how to create and then fetch a test run in TofuPilot. - -This script first creates a test run for a unit with a specified serial number and part number, -then retrieves the run data using the serial number. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -from tofupilot import TofuPilotClient -import json - -# Initialize the TofuPilot client -client = TofuPilotClient() - -# Define the serial number of the unit under test -serial_number = "SN00106" - -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": serial_number, "part_number": "PCB01"}, - run_passed=True, -) - -# Fetch the created run using the serial number -response = client.get_runs(serial_number=serial_number) - - -# Save JSON response locally -with open("response_saved.json", "w") as f: - json.dump(response, f, indent=2) - -print("Response saved to response_saved.json") diff --git a/testing_examples/client/get_runs/with_attachments/data/temperature-map.png b/testing_examples/client/get_runs/with_attachments/data/temperature-map.png deleted file mode 100644 index c7eb24b..0000000 Binary files a/testing_examples/client/get_runs/with_attachments/data/temperature-map.png and /dev/null differ diff --git a/testing_examples/client/get_runs/with_attachments/main.py b/testing_examples/client/get_runs/with_attachments/main.py deleted file mode 100644 index 516b176..0000000 --- a/testing_examples/client/get_runs/with_attachments/main.py +++ /dev/null @@ -1,37 +0,0 @@ -from tofupilot import TofuPilotClient -import requests -from pathlib import Path - - -def main(): - # First create a run - client = TofuPilotClient() - - serial_number = "SN00106" - - client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": serial_number, "part_number": "PCB01"}, - run_passed=True, - attachments=[ - "qa/client/get_runs/basic/data/temperature-map.png" - ], # Update with your file path - ) - - # Then fetch the created run using the serial number - res = client.get_runs(serial_number=serial_number) - attachments = res["data"][0]["attachments"] - - # Download and save each attachment next to the script - for attachment in attachments: - response = requests.get(attachment["url"]) - response.raise_for_status() - - file_path = Path(__file__).parent / attachment["name"] - - with open(file_path, "wb+") as f: - f.write(response.content) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/legacy/steps/advanced/main.py b/testing_examples/client/legacy/steps/advanced/main.py deleted file mode 100644 index 8ae17fe..0000000 --- a/testing_examples/client/legacy/steps/advanced/main.py +++ /dev/null @@ -1,45 +0,0 @@ -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - - -def main(): - client = TofuPilotClient() - - client.create_run( - procedure_id="FVT1", - unit_under_test={ - "serial_number": "PCB1A002", - "part_number": "PCB1", - }, - run_passed=True, - steps=[ - { - "name": "step_connect", - "step_passed": True, - "duration": timedelta(seconds=3), - "started_at": datetime.now(), - }, - { - "name": "test_firmware_version_check", - "step_passed": True, - "duration": timedelta(minutes=1, seconds=42), - "started_at": datetime.now() + timedelta(seconds=3), - "measurement_value": "v2.5.1", - }, - { - "name": "step_temp_calibration", - "step_passed": True, - "duration": timedelta(milliseconds=500), - "started_at": datetime.now() + timedelta(seconds=4), - "measurement_value": 75, - "measurement_unit": "°C", - "limit_low": 70, - "limit_high": 80, - }, - ], - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/legacy/steps/optional/main.py b/testing_examples/client/legacy/steps/optional/main.py deleted file mode 100644 index 04b2cfa..0000000 --- a/testing_examples/client/legacy/steps/optional/main.py +++ /dev/null @@ -1,37 +0,0 @@ -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - - -def step_one(): - step = [ - { - "name": "step_one", - "step_passed": True, - "started_at": datetime.now(), - "duration": timedelta(seconds=30), - # Add a measurement with value, units and limits - "measurement_unit": "V", - "measurement_value": 3.3, - "limit_low": 3.1, - "limit_high": 3.5, - } - ] - return step - - -def main(): - steps = step_one() - - client = TofuPilotClient() - - client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"}, - steps=steps, - run_passed=all(step["step_passed"] for step in steps), - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/legacy/steps/required/main.py b/testing_examples/client/legacy/steps/required/main.py deleted file mode 100644 index 54524d3..0000000 --- a/testing_examples/client/legacy/steps/required/main.py +++ /dev/null @@ -1,32 +0,0 @@ -from datetime import datetime, timedelta - -from tofupilot import TofuPilotClient - - -def step_one(): - step = [ - { - "name": "step_one", - "step_passed": True, - "duration": timedelta(seconds=30), - "started_at": datetime.now(), - } - ] - return step - - -def main(): - steps = step_one() - - client = TofuPilotClient() - - client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"}, - steps=steps, - run_passed=all(step["step_passed"] for step in steps), - ) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/client/update_unit/basic/main.py b/testing_examples/client/update_unit/basic/main.py deleted file mode 100644 index 9385262..0000000 --- a/testing_examples/client/update_unit/basic/main.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -Simple example showing how to add a sub-unit to an existing unit using the TofuPilotClient. - -This script assumes you already have two units with the respective serial numbers "00102" and "00103". -If the units do not exist, you can uncomment the lines to create them first. - -Ensure your API key is stored in the environment variables as per the documentation: -https://tofupilot.com/docs/user-management#api-key -""" - -from tofupilot import TofuPilotClient - -# Initialize the TofuPilot client -client = TofuPilotClient() - -# Creating units -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00102", "part_number": "PCB01"}, - run_passed=True, -) -client.create_run( - procedure_id="FVT1", - unit_under_test={"serial_number": "00103", "part_number": "PSU01"}, - run_passed=True, -) - -# Update unit "00102" by adding unit "00103" as a sub-unit -client.update_unit(serial_number="00102", - sub_units=[{"serial_number": "00103"}]) diff --git a/testing_examples/openhtf/all_the_things/data/oscilloscope.jpeg b/testing_examples/openhtf/all_the_things/data/oscilloscope.jpeg deleted file mode 100644 index d49014b..0000000 Binary files a/testing_examples/openhtf/all_the_things/data/oscilloscope.jpeg and /dev/null differ diff --git a/testing_examples/openhtf/all_the_things/main.py b/testing_examples/openhtf/all_the_things/main.py deleted file mode 100644 index 0cefc39..0000000 --- a/testing_examples/openhtf/all_the_things/main.py +++ /dev/null @@ -1,183 +0,0 @@ -import os.path -import time - -import openhtf as htf -from openhtf import util -from openhtf.output import callbacks -from openhtf.output.callbacks import console_summary, json_factory -from openhtf.util import units -from tofupilot.openhtf import TofuPilot - - -@htf.measures( - htf.Measurement("widget_type") - .matches_regex(r".*Widget$") - .doc("""This measurement tracks the type of widgets."""), - htf.Measurement("widget_color").doc("Color of the widget"), - htf.Measurement("widget_size").in_range(1, 4).doc("Size of widget"), -) -@htf.measures( - "specified_as_args", - docstring="Helpful docstring", - units=units.HERTZ, - validators=[util.validators.matches_regex("Measurement")], -) -def hello_world(test): - """A hello world test phase.""" - test.logger.info("Hello World!") - test.measurements.widget_type = "MyWidget" - test.measurements.widget_color = "Black" - test.measurements.widget_size = 3 - test.measurements.specified_as_args = "Measurement args specified directly" - - -# Timeout if this phase takes longer than 10 seconds. -@htf.PhaseOptions(timeout_s=10) -@htf.measures(*(htf.Measurement("level_%s" % i) - for i in ["none", "some", "all"])) -def set_measurements(test): - """Test phase that sets a measurement.""" - test.measurements.level_none = 0 - time.sleep(1) - test.measurements.level_some = 8 - time.sleep(1) - test.measurements.level_all = 9 - time.sleep(1) - level_all = test.get_measurement("level_all") - assert level_all.value == 9 - - -@htf.measures( - htf.Measurement("dimensions").with_dimensions(units.HERTZ), - htf.Measurement("lots_of_dims").with_dimensions( - units.HERTZ, - units.SECOND, - htf.Dimension(description="my_angle", unit=units.RADIAN), - ), -) -def dimensions(test): - """Phase with dimensioned measurements.""" - for dim in range(5): - test.measurements.dimensions[dim] = 1 << dim - for x, y, z in zip( - list( - range( - 1, 5)), list( - range( - 21, 25)), list( - range( - 101, 105))): - test.measurements.lots_of_dims[x, y, z] = x + y + z - - -@htf.measures( - htf.Measurement("replaced_min_only").in_range( - "{minimum}", 5, type=int), htf.Measurement("replaced_max_only").in_range( - 0, "{maximum}", type=int), htf.Measurement("replaced_min_max").in_range( - "{minimum}", "{maximum}", type=int), ) -def measures_with_args(test, minimum, maximum): - """Phase with measurement with arguments.""" - del minimum # Unused. - del maximum # Unused. - test.measurements.replaced_min_only = 1 - test.measurements.replaced_max_only = 1 - test.measurements.replaced_min_max = 1 - - -@htf.measures( - htf.Measurement("replaced_marginal_min_only").in_range( - 0, 10, "{marginal_minimum}", 8, type=int - ), - htf.Measurement("replaced_marginal_max_only").in_range( - 0, 10, 2, "{marginal_maximum}", type=int - ), - htf.Measurement("replaced_marginal_min_max").in_range( - 0, 10, "{marginal_minimum}", "{marginal_maximum}", type=int - ), -) -def measures_with_marginal_args(test, marginal_minimum, marginal_maximum): - """Phase with measurement with marginal arguments.""" - del marginal_minimum # Unused. - del marginal_maximum # Unused. - test.measurements.replaced_marginal_min_only = 3 - test.measurements.replaced_marginal_max_only = 3 - test.measurements.replaced_marginal_min_max = 3 - - -def attachments(test): - test.attach( - "test_attachment", - "This is test attachment data.".encode("utf-8")) - test.attach_from_file("data/oscilloscope.jpeg") - - test_attachment = test.get_attachment("test_attachment") - assert test_attachment.data == b"This is test attachment data." - - -@htf.PhaseOptions(run_if=lambda: False) -def skip_phase(): - """Don't run this phase.""" - - -def analysis(test): # pylint: disable=missing-function-docstring - level_all = test.get_measurement("level_all") - assert level_all.value == 9 - test_attachment = test.get_attachment("test_attachment") - assert test_attachment.data == b"This is test attachment data." - lots_of_dims = test.get_measurement("lots_of_dims") - assert lots_of_dims.value.value == [ - (1, 21, 101, 123), - (2, 22, 102, 126), - (3, 23, 103, 129), - (4, 24, 104, 132), - ] - test.logger.info( - "Pandas datafram of lots_of_dims \n:%s", - lots_of_dims.value.to_dataframe()) - - -def teardown(test): - test.logger.info("Running teardown") - - -def make_test(): - return htf.Test( - htf.PhaseGroup.with_teardown(teardown)( - hello_world, - set_measurements, - dimensions, - attachments, - skip_phase, - measures_with_args.with_args(minimum=1, maximum=4), - measures_with_marginal_args.with_args( - marginal_minimum=4, marginal_maximum=6 - ), - analysis, - ), - test_name="MyTest", - test_description="OpenHTF Example Test", - test_version="1.0.0", - part_number="PCB01", - procedure_id="FVT1", - ) - - -def main(): - test = make_test() - test.add_output_callbacks( - callbacks.OutputToFile( - "./{dut_id}.{metadata[test_name]}.{start_time_millis}.pickle" - ) - ) - test.add_output_callbacks( - json_factory.OutputToJSON( - "./{dut_id}.{metadata[test_name]}.{start_time_millis}.json", - indent=4)) - test.add_output_callbacks(console_summary.ConsoleSummary()) - - with TofuPilot(test): - test.execute(lambda: "00220D4K") - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/generic/data/oscilloscope.jpeg b/testing_examples/openhtf/generic/data/oscilloscope.jpeg deleted file mode 100644 index d49014b..0000000 Binary files a/testing_examples/openhtf/generic/data/oscilloscope.jpeg and /dev/null differ diff --git a/testing_examples/openhtf/generic/main.py b/testing_examples/openhtf/generic/main.py deleted file mode 100644 index d932c0e..0000000 --- a/testing_examples/openhtf/generic/main.py +++ /dev/null @@ -1,99 +0,0 @@ -import random -import time -from datetime import datetime, timedelta - -import openhtf as htf -from openhtf.util import units -from tofupilot.openhtf import TofuPilot - - -@htf.measures(htf.Measurement("firmware_version").equals("1.4.3")) -def pcba_firmware_version(test): - test.measurements.firmware_version = "1.4.3" if random.random() < 0.99 else "1.4.2" - - -@htf.measures(htf.Measurement("button_status").equals(True)) -def check_button(test): - test.measurements.button_status = random.choice([True, False]) - time.sleep(1) - - -@htf.measures(htf.Measurement("input_voltage").in_range(4.5, - 5).with_units(units.VOLT)) -def test_voltage_input(test): - test.measurements.input_voltage = round(random.uniform(3.7, 4.9), 2) - - -@htf.measures( - htf.Measurement("output_voltage").in_range(3.2, 3.4).with_units(units.VOLT) -) -def test_voltage_output(test): - test.measurements.output_voltage = round(random.uniform(2.95, 3.35), 2) - - -@htf.measures( - htf.Measurement("current_protection_triggered") - .in_range(maximum=1.5) - .with_units(units.AMPERE) -) -def test_overcurrent_protection(test): - test.measurements.current_protection_triggered = round( - random.uniform(1.0, 1.7), 3) - time.sleep(1) - - -def test_battery_switch(): - if random.random() < 0.9: - return htf.PhaseResult.CONTINUE - else: - return htf.PhaseResult.STOP - - -@htf.measures( - htf.Measurement("efficiency").in_range(85, 98).with_units(units.Unit("%")) -) -def test_converter_efficiency(test): - input_power = 500 - output_power = round(random.uniform(425, 480)) - test.measurements.efficiency = round( - ((output_power / input_power) * 100), 1) - time.sleep(1) - - -def visual_control_pcb_coating(test): - if random.random() < 0.98: - test.attach_from_file("qa/openhtf/generic/data/oscilloscope.jpeg") - return htf.PhaseResult.CONTINUE - else: - return htf.PhaseResult.STOP - - -def main(): - # Define the test plan with all steps - test = htf.Test( - pcba_firmware_version, - check_button, - test_voltage_input, - test_voltage_output, - test_overcurrent_protection, - test_battery_switch, - test_converter_efficiency, - visual_control_pcb_coating, - procedure_id="FVT1", - part_number="00220", - revision="A", - # batch_number="1024-0001", - # sub_units=[{"serial_number": "00102"}], - ) - - # Generate random Serial Number - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220B4K{random_digits}" - - # Execute the test - with TofuPilot(test): - test.execute(lambda: serial_number) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/logger/main.py b/testing_examples/openhtf/logger/main.py deleted file mode 100644 index cc6c53f..0000000 --- a/testing_examples/openhtf/logger/main.py +++ /dev/null @@ -1,54 +0,0 @@ -import random - -import openhtf as htf -from openhtf.output.callbacks import json_factory -from tofupilot.openhtf import TofuPilot - - -@htf.measures(htf.Measurement("button_status").equals(True)) -def phase_info_logger(test): - test.measurements.button_status = True - test.logger.info("Logging an info in the logger") - - -def phase_error_logger(test): - test.logger.error("Logging error in the logger") - return htf.PhaseResult.CONTINUE - - -def phase_warning_logger(test): - test.logger.warning("Logging a warning in the logger") - return htf.PhaseResult.CONTINUE - - -def phase_critical_logger(test): - test.logger.critical("Logging a critical in the logger") - return htf.PhaseResult.CONTINUE - - -def main(): - # Define the test plan with all steps - test = htf.Test( - phase_info_logger, - phase_error_logger, - phase_warning_logger, - phase_critical_logger, - procedure_id="FVT9", - part_number="00220D", - ) - - # Generate random Serial Number - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220D4K{random_digits}" - - test.add_output_callbacks( - json_factory.OutputToJSON( - "test_result.json", indent=2)) - - # Execute the test - with TofuPilot(test): - test.execute(lambda: serial_number) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/multi_dimensions/main.py b/testing_examples/openhtf/multi_dimensions/main.py deleted file mode 100644 index 5f2cfdd..0000000 --- a/testing_examples/openhtf/multi_dimensions/main.py +++ /dev/null @@ -1,104 +0,0 @@ -import random -import time - -import numpy as np -import openhtf as htf -from openhtf.output.callbacks import json_factory -from openhtf.util import units -from tofupilot.openhtf import TofuPilot - - -@htf.measures( - htf.Measurement("voltage").with_dimensions(units.SECOND).with_units(units.VOLT), - htf.Measurement("mean_voltage").with_units(units.VOLT).in_range(3.3, 3.5), - htf.Measurement("sinus").with_dimensions(units.SECOND).with_units(units.AMPERE), - htf.Measurement("neg_x_axis").with_dimensions(units.SECOND).with_units(units.VOLT), - htf.Measurement("neg_y_axis").with_dimensions(units.SECOND).with_units(units.VOLT), - htf.Measurement("parameters"), -) -def multi_dimension_phase(test): - len = 50 - sum_voltage = 0.0 - min_voltage = float("inf") - max_voltage = float("-inf") - for t in range(len): - voltage = round(random.uniform(3.3, 3.5), 2) - test.measurements.voltage[t] = voltage - sum_voltage += voltage - - if voltage < min_voltage: - min_voltage = voltage - if voltage > max_voltage: - max_voltage = voltage - - negative_timestamp = -t - test.measurements.neg_x_axis[negative_timestamp] = voltage - test.measurements.neg_y_axis[t] = -voltage - - test.measurements.mean_voltage = sum_voltage / len - - # metadata array - test.measurements.parameters = { - "mean_voltage": test.measurements.mean_voltage, - "min_voltage": min_voltage, - "max_voltage": max_voltage, - "duration": 345, - } - - # Sinus - x = np.linspace(0, 2 * np.pi, 100) - y = np.sin(x) - for i, amp in enumerate(y): - test.measurements.sinus[i] = amp - - -@htf.measures( - htf.Measurement("current_and_voltage_over_time") - .with_dimensions(units.SECOND, units.VOLT) - .with_units(units.AMPERE), - htf.Measurement("current_voltage_resistence_over_time") - .with_dimensions(units.SECOND, units.VOLT, units.AMPERE) - .with_units(units.OHM), -) -def power_phase(test): - for t in range(100): - timestamp = t / 100 - voltage = round(random.uniform(3.3, 3.5), 2) - current = round(random.uniform(0.3, 0.8), 3) - resistance = voltage / current - test.measurements.current_and_voltage_over_time[timestamp, - voltage] = current - test.measurements.current_voltage_resistence_over_time[ - timestamp, voltage, current - ] = resistance - - -def main(): - test = htf.Test( - multi_dimension_phase, - power_phase, - procedure_id="FVT2", - part_number="00220S", - revision="B", - batch_number="1124-0001", - ) - - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220D4K{random_digits}" - - test.add_output_callbacks( - json_factory.OutputToJSON( - "test_result.json", indent=2)) - - start = time.time() - # Execute the test - with TofuPilot(test): - test.execute(lambda: serial_number) - - end = time.time() - duration = end - start - print(f"Durée : {duration:.2f} secondes") - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/multi_measurements/main.py b/testing_examples/openhtf/multi_measurements/main.py deleted file mode 100644 index 7157e23..0000000 --- a/testing_examples/openhtf/multi_measurements/main.py +++ /dev/null @@ -1,116 +0,0 @@ -import random - -import openhtf as htf -from openhtf.util import units -from tofupilot.openhtf import TofuPilot - - -@htf.measures( - htf.Measurement("firmware_version").equals("1.4.3"), - htf.Measurement("power_mode_functional").equals("on"), -) -def string_test(test): - test.measurements.firmware_version = "1.4.3" if random.random() < 0.99 else "1.4.2" - test.measurements.power_mode_functional = "on" - - -@htf.measures(htf.Measurement("button_status").equals(True)) -def boolean_test(test): - test.measurements.button_status = True - - -def phaseresult_test(): - return htf.PhaseResult.CONTINUE - - -@htf.measures( - htf.Measurement("two_limits").in_range( - 4.5, 5).with_units( - units.VOLT), htf.Measurement("one_limit").in_range( - maximum=1.5).with_units( - units.AMPERE), htf.Measurement("percentage").in_range( - 85, 98).with_units( - units.Unit("%")), ) -def measure_test_with_limits(test): - test.measurements.two_limits = round(random.uniform(3.8, 4.9), 2) - test.measurements.one_limit = round(random.uniform(1.0, 1.6), 3) - input_power = 500 - output_power = round(random.uniform(425, 480)) - test.measurements.percentage = round( - ((output_power / input_power) * 100), 1) - - -@htf.measures(htf.Measurement("is_connected").equals(True), - htf.Measurement("firmware_version").equals("1.2.7"), - htf.Measurement("temperature").in_range(20, - 25).with_units(units.DEGREE_CELSIUS), - ) -def phase_multi_measurements(test): - test.measurements.is_connected = True - test.measurements.firmware_version = ( - "1.2.7" if test.measurements.is_connected else "N/A" - ) - test.measurements.temperature = round(random.uniform(22.5, 23), 2) - - -@htf.measures( - htf.Measurement("dimensions").with_dimensions(units.HERTZ), - htf.Measurement("lots_of_dims").with_dimensions( - units.HERTZ, - units.SECOND, - htf.Dimension(description="my_angle", unit=units.RADIAN), - ), -) -def dimensions(test): - """Phase with dimensioned measurements.""" - for dim in range(5): - test.measurements.dimensions[dim] = 1 << dim - for x, y, z in zip( - list( - range( - 1, 5)), list( - range( - 21, 25)), list( - range( - 101, 105))): - test.measurements.lots_of_dims[x, y, z] = x + y + z - - -@htf.measures( - htf.Measurement("binary_measure").equals(True), - htf.Measurement("string_measure").equals("1.2.7"), - htf.Measurement("numerical_measure") - .in_range(20, 25) - .with_units(units.DEGREE_CELSIUS), -) -def not_working_multi_measurements(test): - test.measurements.binary_measure = 42 - test.measurements.string_measure = 123 - test.measurements.numerical_measure = 35 - - -def main(): - # Define the test plan with all steps - test = htf.Test( - phase_multi_measurements, - dimensions, - string_test, - boolean_test, - phaseresult_test, - measure_test_with_limits, - not_working_multi_measurements, - procedure_id="FVT9", - part_number="00220D", - ) - - # Generate random Serial Number - random_digits = "".join([str(random.randint(0, 9)) for _ in range(5)]) - serial_number = f"00220D4K{random_digits}" - - # Execute the test - with TofuPilot(test): - test.execute(lambda: serial_number) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/procedure_version/main.py b/testing_examples/openhtf/procedure_version/main.py deleted file mode 100644 index 7157b78..0000000 --- a/testing_examples/openhtf/procedure_version/main.py +++ /dev/null @@ -1,30 +0,0 @@ -import random - -import openhtf as htf -from tofupilot.openhtf import TofuPilot - - -@htf.measures(htf.Measurement("button_status").equals(True)) -def check_button(test): - test.measurements.button_status = bool(random.randint(0, 1)) - - -def main(): - test = htf.Test( - check_button, - procedure_id="FVT1", # No need to specify the ID - procedure_version="1.2.20", # Create procedure version - part_number="00220", - revision="B", - ) - - # Generate random Serial Number - serial_number = f"00220B4K{random.randint(10000, 99999)}" - - # Execute the test - with TofuPilot(test, stream=False): - test.execute(lambda: serial_number) - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/regex_serial_number/main.py b/testing_examples/openhtf/regex_serial_number/main.py deleted file mode 100644 index f7344b4..0000000 --- a/testing_examples/openhtf/regex_serial_number/main.py +++ /dev/null @@ -1,25 +0,0 @@ -import random - -import openhtf as htf -from tofupilot.openhtf import TofuPilot - - -@htf.measures(htf.Measurement("button_status").equals(True)) -def check_button(test): - test.measurements.button_status = bool(random.randint(0, 1)) - - -def main(): - test = htf.Test( - check_button, - procedure_id="FVT1", - # REGEX is defined in the Settings from Serial Number for: - # part_number="PCB01", - ) - - with TofuPilot(test): - test.execute(lambda: "PCB01A123") - - -if __name__ == "__main__": - main() diff --git a/testing_examples/openhtf/without_streaming/data/oscilloscope.jpeg b/testing_examples/openhtf/without_streaming/data/oscilloscope.jpeg deleted file mode 100644 index d49014b..0000000 Binary files a/testing_examples/openhtf/without_streaming/data/oscilloscope.jpeg and /dev/null differ diff --git a/testing_examples/openhtf/without_streaming/main.py b/testing_examples/openhtf/without_streaming/main.py deleted file mode 100644 index f89d527..0000000 --- a/testing_examples/openhtf/without_streaming/main.py +++ /dev/null @@ -1,183 +0,0 @@ -import os.path -import time - -import openhtf as htf -from openhtf import util -from openhtf.output import callbacks -from openhtf.output.callbacks import console_summary, json_factory -from openhtf.util import units -from tofupilot.openhtf import TofuPilot - - -@htf.measures( - htf.Measurement("widget_type") - .matches_regex(r".*Widget$") - .doc("""This measurement tracks the type of widgets."""), - htf.Measurement("widget_color").doc("Color of the widget"), - htf.Measurement("widget_size").in_range(1, 4).doc("Size of widget"), -) -@htf.measures( - "specified_as_args", - docstring="Helpful docstring", - units=units.HERTZ, - validators=[util.validators.matches_regex("Measurement")], -) -def hello_world(test): - """A hello world test phase.""" - test.logger.info("Hello World!") - test.measurements.widget_type = "MyWidget" - test.measurements.widget_color = "Black" - test.measurements.widget_size = 3 - test.measurements.specified_as_args = "Measurement args specified directly" - - -# Timeout if this phase takes longer than 10 seconds. -@htf.PhaseOptions(timeout_s=10) -@htf.measures(*(htf.Measurement("level_%s" % i) - for i in ["none", "some", "all"])) -def set_measurements(test): - """Test phase that sets a measurement.""" - test.measurements.level_none = 0 - time.sleep(1) - test.measurements.level_some = 8 - time.sleep(1) - test.measurements.level_all = 9 - time.sleep(1) - level_all = test.get_measurement("level_all") - assert level_all.value == 9 - - -@htf.measures( - htf.Measurement("dimensions").with_dimensions(units.HERTZ), - htf.Measurement("lots_of_dims").with_dimensions( - units.HERTZ, - units.SECOND, - htf.Dimension(description="my_angle", unit=units.RADIAN), - ), -) -def dimensions(test): - """Phase with dimensioned measurements.""" - for dim in range(5): - test.measurements.dimensions[dim] = 1 << dim - for x, y, z in zip( - list( - range( - 1, 5)), list( - range( - 21, 25)), list( - range( - 101, 105))): - test.measurements.lots_of_dims[x, y, z] = x + y + z - - -@htf.measures( - htf.Measurement("replaced_min_only").in_range( - "{minimum}", 5, type=int), htf.Measurement("replaced_max_only").in_range( - 0, "{maximum}", type=int), htf.Measurement("replaced_min_max").in_range( - "{minimum}", "{maximum}", type=int), ) -def measures_with_args(test, minimum, maximum): - """Phase with measurement with arguments.""" - del minimum # Unused. - del maximum # Unused. - test.measurements.replaced_min_only = 1 - test.measurements.replaced_max_only = 1 - test.measurements.replaced_min_max = 1 - - -@htf.measures( - htf.Measurement("replaced_marginal_min_only").in_range( - 0, 10, "{marginal_minimum}", 8, type=int - ), - htf.Measurement("replaced_marginal_max_only").in_range( - 0, 10, 2, "{marginal_maximum}", type=int - ), - htf.Measurement("replaced_marginal_min_max").in_range( - 0, 10, "{marginal_minimum}", "{marginal_maximum}", type=int - ), -) -def measures_with_marginal_args(test, marginal_minimum, marginal_maximum): - """Phase with measurement with marginal arguments.""" - del marginal_minimum # Unused. - del marginal_maximum # Unused. - test.measurements.replaced_marginal_min_only = 3 - test.measurements.replaced_marginal_max_only = 3 - test.measurements.replaced_marginal_min_max = 3 - - -def attachments(test): - test.attach( - "test_attachment", - "This is test attachment data.".encode("utf-8")) - test.attach_from_file("data/oscilloscope.jpeg") - - test_attachment = test.get_attachment("test_attachment") - assert test_attachment.data == b"This is test attachment data." - - -@htf.PhaseOptions(run_if=lambda: False) -def skip_phase(): - """Don't run this phase.""" - - -def analysis(test): # pylint: disable=missing-function-docstring - level_all = test.get_measurement("level_all") - assert level_all.value == 9 - test_attachment = test.get_attachment("test_attachment") - assert test_attachment.data == b"This is test attachment data." - lots_of_dims = test.get_measurement("lots_of_dims") - assert lots_of_dims.value.value == [ - (1, 21, 101, 123), - (2, 22, 102, 126), - (3, 23, 103, 129), - (4, 24, 104, 132), - ] - test.logger.info( - "Pandas datafram of lots_of_dims \n:%s", - lots_of_dims.value.to_dataframe()) - - -def teardown(test): - test.logger.info("Running teardown") - - -def make_test(): - return htf.Test( - htf.PhaseGroup.with_teardown(teardown)( - hello_world, - set_measurements, - dimensions, - attachments, - skip_phase, - measures_with_args.with_args(minimum=1, maximum=4), - measures_with_marginal_args.with_args( - marginal_minimum=4, marginal_maximum=6 - ), - analysis, - ), - test_name="MyTest", - test_description="OpenHTF Example Test", - test_version="1.0.0", - part_number="PCB01", - procedure_id="FVT1", - ) - - -def main(): - test = make_test() - test.add_output_callbacks( - callbacks.OutputToFile( - "./{dut_id}.{metadata[test_name]}.{start_time_millis}.pickle" - ) - ) - test.add_output_callbacks( - json_factory.OutputToJSON( - "./{dut_id}.{metadata[test_name]}.{start_time_millis}.json", - indent=4)) - test.add_output_callbacks(console_summary.ConsoleSummary()) - - with TofuPilot(test, stream=False): - test.execute(lambda: "00220D4K") - - -if __name__ == "__main__": - main()