Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs_tofupilot/integrations/openhtf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def phase_one():


def main():
test = htf.Test(phase_one, procedure_id="FVT1", part_number="PCB01") # Specify procedure and part_number
test = htf.Test(
phase_one, procedure_id="FVT1", part_number="PCB01"
) # Specify procedure and part_number

with TofuPilot(test): # One-line integration
test.execute(lambda: "PCB1A001")
Expand Down
34 changes: 22 additions & 12 deletions docs_tofupilot/logger/client/main.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
import logging
import sys
from datetime import datetime

from tofupilot import TofuPilotClient


class JsonCaptureHandler(logging.Handler):
class TofuPilotLogHandler(logging.Handler):
"""Handler that captures logs in a format compatible with TofuPilot API."""

def __init__(self):
super().__init__()
self.logs = []

def emit(self, record):
# Format log with ISO-8601 timestamp (millisecond precision) for
# TofuPilot API
log_entry = {
"level": record.levelname,
"timestamp": int(record.created * 1000),
"timestamp": f"{datetime.fromtimestamp(record.created).isoformat(timespec='milliseconds')}Z",
"message": record.getMessage(),
"source_file": record.filename,
"line_number": record.lineno,
}
self.logs.append(log_entry)


# Initialize the TofuPilot client.
# Initialize the TofuPilot client to report test results
client = TofuPilotClient()

# Set up local logger
# Set up local logger with custom name and prevent propagation to parent
# loggers
local_logger = logging.getLogger("test_logger")
local_logger.setLevel(logging.DEBUG)
local_logger.propagate = (
False # if we don't want to propagate to the parent/root logger
)
local_logger.propagate = False

capture_handler = JsonCaptureHandler()
output_handler = logging.StreamHandler(sys.stdout)
# Add handlers: one for TofuPilot API capture and one for console output
capture_handler = TofuPilotLogHandler()
local_logger.addHandler(capture_handler)
local_logger.addHandler(output_handler)
local_logger.addHandler(logging.StreamHandler(sys.stdout))


local_logger.warning("This is a log we want to keep.")
# Log examples at different severity levels
local_logger.debug("Debug message: Detailed information for troubleshooting")
local_logger.info("Info message: Normal operation information")
local_logger.warning("Warning: Something unexpected but not critical")
local_logger.error("Error: A significant problem that needs attention")
local_logger.critical("Critical: System unstable, immediate action required")

# Create a run and send logs
# Create a run and send captured logs to TofuPilot
try:
client.create_run(
procedure_id="FVT1",
Expand Down
6 changes: 4 additions & 2 deletions docs_tofupilot/measurements/boolean/client/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
from datetime import datetime

from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient
import random

client = TofuPilotClient()

Expand Down Expand Up @@ -34,7 +35,8 @@ def main():
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(phase["outcome"] == PhaseOutcome.PASS for phase in phases),
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
)


Expand Down
9 changes: 6 additions & 3 deletions docs_tofupilot/measurements/dimensional/client/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
from datetime import datetime

from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient
import random

client = TofuPilotClient()

Expand All @@ -14,7 +15,8 @@ def phase_voltage_measure():
voltage = round(random.uniform(3.3, 3.5), 2)
current = round(random.uniform(0.3, 0.8), 3)
resistance = voltage / current
structured_measurements.append((timestamp, voltage, current, resistance))
structured_measurements.append(
(timestamp, voltage, current, resistance))

phase = [
{
Expand Down Expand Up @@ -43,7 +45,8 @@ def main():
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(phase["outcome"] == PhaseOutcome.PASS for phase in phases),
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
)


Expand Down
3 changes: 2 additions & 1 deletion docs_tofupilot/measurements/dimensional/openhtf/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import random

import openhtf as htf
from openhtf.util import units
from tofupilot.openhtf import TofuPilot
import random


@htf.measures(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
from datetime import datetime
from tofupilot import TofuPilotClient, PhaseOutcome, MeasurementOutcome

from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient

client = TofuPilotClient()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import random

import openhtf as htf
from openhtf.util import units
from tofupilot.openhtf import TofuPilot
import random


@htf.measures(
htf.Measurement("is_connected").equals(True), # Boolean measure
htf.Measurement("firmware_version").equals("1.2.7"), # String measure
htf.Measurement("input_voltage").in_range(3.2, 3.4).with_units(units.VOLT),
htf.Measurement("input_current").in_range(maximum=1.5).with_units(units.AMPERE),
htf.Measurement("input_current").in_range(
maximum=1.5).with_units(units.AMPERE),
)
def phase_multi_measurements(test):
test.measurements.is_connected = True
Expand Down
4 changes: 3 additions & 1 deletion docs_tofupilot/measurements/numerical/client/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime

from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient

client = TofuPilotClient()
Expand Down Expand Up @@ -36,7 +37,8 @@ def main():
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(phase["outcome"] == PhaseOutcome.PASS for phase in phases),
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
)


Expand Down
4 changes: 3 additions & 1 deletion docs_tofupilot/measurements/string/client/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime

from tofupilot import MeasurementOutcome, PhaseOutcome, TofuPilotClient

client = TofuPilotClient()
Expand Down Expand Up @@ -33,7 +34,8 @@ def main():
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(phase["outcome"] == PhaseOutcome.PASS for phase in phases),
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
)


Expand Down
8 changes: 5 additions & 3 deletions docs_tofupilot/phases/advanced/openhtf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def phase_firmware_version_check(test):

# Phase with multiple measurements
@htf.measures(
htf.Measurement("input_voltage").in_range(3.1, 3.5).with_units(units.VOLT),
htf.Measurement("output_voltage").in_range(1.1, 1.3).with_units(units.VOLT),
)
htf.Measurement("input_voltage").in_range(
3.1, 3.5).with_units(
units.VOLT), htf.Measurement("output_voltage").in_range(
1.1, 1.3).with_units(
units.VOLT), )
def phase_voltage_measurements(test):
test.measurements.input_voltage = 3.3
test.measurements.output_voltage = 1.2
Expand Down
4 changes: 1 addition & 3 deletions docs_tofupilot/phases/optional/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def main():

client.create_run(
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={
"serial_number": "PCB1A001",
"part_number": "PCB1"},
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
Expand Down
4 changes: 1 addition & 3 deletions docs_tofupilot/phases/required/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def main():

client.create_run(
procedure_id="FVT1", # Create the procedure first in the Application
unit_under_test={
"serial_number": "PCB1A001",
"part_number": "PCB1"},
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCB1"},
phases=phases,
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
Expand Down
1 change: 1 addition & 0 deletions docs_tofupilot/procedures/client/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta

from tofupilot import TofuPilotClient


Expand Down
11 changes: 7 additions & 4 deletions docs_tofupilot/stations/client/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Before running the script, ensure you have created a station in the TofuPilot interface
# and linked it to the specified procedure ID ("FVT1" in this example).
# You also need to save your API key in an environment variable named "STATION_API_KEY"
# or pass it directly as an argument like this: TofuPilotClient(api_key="STATION_API_KEY")
# or pass it directly as an argument like this:
# TofuPilotClient(api_key="STATION_API_KEY")

from datetime import timedelta, datetime
from tofupilot import TofuPilotClient, PhaseOutcome
from datetime import datetime, timedelta

from tofupilot import PhaseOutcome, TofuPilotClient


def phase_one():
Expand All @@ -26,7 +28,8 @@ def main():

client.create_run(
procedure_id="FVT1", # Create a station in TofuPilot linked to this procedure ID
run_passed=all(phase["outcome"] == PhaseOutcome.PASS for phase in phases),
run_passed=all(
phase["outcome"] == PhaseOutcome.PASS for phase in phases),
unit_under_test={"serial_number": "PCB1A001", "part_number": "PCBA01"},
phases=phases,
duration=timedelta(minutes=1, seconds=45),
Expand Down
3 changes: 2 additions & 1 deletion docs_tofupilot/stations/openhtf/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Before running the script, ensure you have created a station in the TofuPilot interface
# and linked it to the specified procedure ID ("FVT1" in this example).
# You also need to save your API key in an environment variable named "STATION_API_KEY"
# or pass it directly as an argument like this: TofuPilot(test, api_key="STATION_API_KEY")
# or pass it directly as an argument like this: TofuPilot(test,
# api_key="STATION_API_KEY")


import openhtf as htf
Expand Down
3 changes: 2 additions & 1 deletion docs_tofupilot/sub-units/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def main():
procedure_id="FVT2", # Create the procedure first in the Application
unit_under_test={"serial_number": "CAM1A001", "part_number": "CAM1"},
run_passed=True,
sub_units=[{"serial_number": "PCB1A001"}, {"serial_number": "LEN1A001"}],
sub_units=[{"serial_number": "PCB1A001"},
{"serial_number": "LEN1A001"}],
)


Expand Down
3 changes: 2 additions & 1 deletion docs_tofupilot/sub-units/openhtf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def main():
test = Test(
procedure_id="FVT2", # Create the procedure first in the Application
part_number="CAM1",
sub_units=[{"serial_number": "PCB1A001"}, {"serial_number": "LEN1A001"}],
sub_units=[{"serial_number": "PCB1A001"},
{"serial_number": "LEN1A001"}],
)
with TofuPilot(test):
test.execute(lambda: "CAM1A001")
Expand Down
7 changes: 5 additions & 2 deletions qa/client/create_run/basic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
https://tofupilot.com/docs/user-management#api-key
"""

from tofupilot import TofuPilotClient
import random

from tofupilot import TofuPilotClient


def main():
# Initialize the TofuPilot client.
Expand All @@ -21,7 +22,9 @@ def main():
serial_number = f"00220D4K{random_digits}"
client.create_run(
procedure_id="FVT1",
unit_under_test={"serial_number": serial_number, "part_number": "PCB01"},
unit_under_test={
"serial_number": serial_number,
"part_number": "PCB01"},
run_passed=True,
)

Expand Down
1 change: 1 addition & 0 deletions qa/client/create_run/phases_string_outcome/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import time

from tofupilot import TofuPilotClient

client = TofuPilotClient()
Expand Down
1 change: 1 addition & 0 deletions qa/client/create_run/procedure_version/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import time
from datetime import datetime, timedelta

from tofupilot import TofuPilotClient


Expand Down
14 changes: 10 additions & 4 deletions qa/client/create_run/started_at/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from tofupilot import TofuPilotClient
import random
from datetime import datetime, timedelta

from tofupilot import TofuPilotClient


def main():
# Initialize the TofuPilot client.
Expand All @@ -12,10 +13,15 @@ def main():
serial_number = f"00220D4K{random_digits}"
client.create_run(
procedure_id="FVT1",
unit_under_test={"serial_number": serial_number, "part_number": "PCB01"},
unit_under_test={
"serial_number": serial_number,
"part_number": "PCB01"},
run_passed=True,
started_at=datetime.now() - timedelta(days=1),
duration=timedelta(seconds=23),
started_at=datetime.now() -
timedelta(
days=1),
duration=timedelta(
seconds=23),
)


Expand Down
10 changes: 7 additions & 3 deletions qa/openhtf/generic/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import time
from datetime import datetime, timedelta

import openhtf as htf
from openhtf.util import units
from tofupilot.openhtf import TofuPilot
Expand All @@ -17,7 +18,8 @@ def check_button(test):
time.sleep(1)


@htf.measures(htf.Measurement("input_voltage").in_range(4.5, 5).with_units(units.VOLT))
@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)

Expand All @@ -35,7 +37,8 @@ def test_voltage_output(test):
.with_units(units.AMPERE)
)
def test_overcurrent_protection(test):
test.measurements.current_protection_triggered = round(random.uniform(1.0, 1.7), 3)
test.measurements.current_protection_triggered = round(
random.uniform(1.0, 1.7), 3)
time.sleep(1)


Expand All @@ -52,7 +55,8 @@ def test_battery_switch():
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)
test.measurements.efficiency = round(
((output_power / input_power) * 100), 1)
time.sleep(1)


Expand Down
Loading
Loading