mirror of
https://github.com/eledio-manufacturing/spintop-openhtf-tester-template.git
synced 2025-11-01 16:16:28 +01:00
Add callback: UploadTestResult
This commit is contained in:
35
main.py
35
main.py
@@ -9,6 +9,7 @@ from openhtf.util import conf, format_string, data
|
|||||||
from openhtf.output.callbacks import json_factory
|
from openhtf.output.callbacks import json_factory
|
||||||
from openhtf.core.test_record import PhaseOutcome
|
from openhtf.core.test_record import PhaseOutcome
|
||||||
|
|
||||||
|
LOG_FILENAME_PATTERN = 'cache/test_results/{dut_id}_{start_time_millis}.test.json'
|
||||||
|
|
||||||
conf.declare('label_printer', default_value='eledio', description='Label printer')
|
conf.declare('label_printer', default_value='eledio', description='Label printer')
|
||||||
|
|
||||||
@@ -45,7 +46,41 @@ def trigger(test, prompts):
|
|||||||
test.dut_id = response['dutID']
|
test.dut_id = response['dutID']
|
||||||
|
|
||||||
|
|
||||||
|
class UploadTestResult(json_factory.OutputToJSON):
|
||||||
|
def __init__(self, folder_pattern, indent=4):
|
||||||
|
self.folder_pattern = folder_pattern
|
||||||
|
super().__init__(indent=indent)
|
||||||
|
|
||||||
|
def __call__(self, test_record):
|
||||||
|
if test_record.is_started():
|
||||||
|
record_dict = data.convert_to_base_types(
|
||||||
|
test_record, ignore_keys=('code_info', 'phases', 'log_records'))
|
||||||
|
|
||||||
|
output_folder = format_string(self.folder_pattern, record_dict)
|
||||||
|
|
||||||
|
_record = self.serialize_test_record(test_record)
|
||||||
|
with open(output_folder, 'w') as f:
|
||||||
|
f.write(_record)
|
||||||
|
|
||||||
|
# Upload test results here to the ERP
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
from test_tools.tester_core.plugs.erp import ErpPlug
|
||||||
|
|
||||||
|
erp = ErpPlug()
|
||||||
|
erp.graphql('test_tools/tester_core/graphql/upload_device_files.graphql', files=[output_folder],
|
||||||
|
sn=json.loads(_record)["dut_id"])
|
||||||
|
if record_dict['outcome'] == 'PASS':
|
||||||
|
erp.graphql('test_tools/tester_core/graphql/set_device_state.graphql', state='ok',
|
||||||
|
sn=json.loads(_record)["dut_id"])
|
||||||
|
else:
|
||||||
|
erp.graphql('test_tools/tester_core/graphql/set_device_state.graphql', state='defective',
|
||||||
|
sn=json.loads(_record)["dut_id"])
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with open('station_config/config.yaml') as f:
|
with open('station_config/config.yaml') as f:
|
||||||
conf.load_from_file(f)
|
conf.load_from_file(f)
|
||||||
|
plan.add_callbacks(UploadTestResult(LOG_FILENAME_PATTERN, indent=2))
|
||||||
plan.run(launch_browser=False)
|
plan.run(launch_browser=False)
|
||||||
Reference in New Issue
Block a user