Auto-format via black

This commit is contained in:
xross
2022-07-21 13:10:47 +01:00
parent 36dedc494c
commit a0f5591e0b
2 changed files with 88 additions and 60 deletions

View File

@@ -6,16 +6,17 @@ import os.path
import pytest
import subprocess
target = os.environ.get('TARGET', 'all_possible')
target = os.environ.get("TARGET", "all_possible")
print("target = ", target)
def pytest_collect_file(parent, path):
if(path.ext == ".xe"):
if(target == 'all_possible'):
if path.ext == ".xe":
if target == "all_possible":
return UnityTestSource.from_parent(parent, fspath=path)
if(target == 'XCOREAI' and ('xcoreai' in path.basename)):
if target == "XCOREAI" and ("xcoreai" in path.basename):
return UnityTestSource.from_parent(parent, fspath=path)
if(target == 'XCORE200' and ('xcore200' in path.basename)):
if target == "XCORE200" and ("xcore200" in path.basename):
return UnityTestSource.from_parent(parent, fspath=path)
@@ -31,7 +32,7 @@ class UnityTestSource(pytest.File):
# |-- src/ <- Unity test functions
# `-- wscript <- Build system file used to generate/build runners
xe_name = ((os.path.basename(self.name)).split("."))[0] + ".xe"
test_bin_path = os.path.join('bin', xe_name)
test_bin_path = os.path.join("bin", xe_name)
yield UnityTestExecutable.from_parent(self, name=self.name)
@@ -46,12 +47,16 @@ class UnityTestExecutable(pytest.Item):
simulator_fail = False
test_output = None
try:
if('xcore200' in self.name):
if "xcore200" in self.name:
print("run axe for executable ", self.name)
test_output = subprocess.check_output(['axe', self.name], text=True)
test_output = subprocess.check_output(["axe", self.name], text=True)
else:
print("run xrun for executable ", self.name)
test_output = subprocess.check_output(['xrun', '--io', '--id', '0', self.name], text=True, stderr=subprocess.STDOUT)
test_output = subprocess.check_output(
["xrun", "--io", "--id", "0", self.name],
text=True,
stderr=subprocess.STDOUT,
)
except subprocess.CalledProcessError as e:
# Unity exits non-zero if an assertion fails
simulator_fail = True
@@ -59,10 +64,10 @@ class UnityTestExecutable(pytest.Item):
# Parse the Unity output
unity_pass = False
test_output = test_output.split('\n')
test_output = test_output.split("\n")
for line in test_output:
if 'test' in line:
test_report = line.split(':')
if "test" in line:
test_report = line.split(":")
# Unity output is as follows:
# <test_source>:<line_number>:<test_case>:PASS
# <test_source>:<line_number>:<test_case>:FAIL:<failure_reason>
@@ -71,34 +76,43 @@ class UnityTestExecutable(pytest.Item):
test_case = test_report[2]
result = test_report[3]
failure_reason = None
print(('\n {}()'.format(test_case)), end=' ')
if result == 'PASS':
print(("\n {}()".format(test_case)), end=" ")
if result == "PASS":
unity_pass = True
continue
if result == 'FAIL':
if result == "FAIL":
failure_reason = test_report[4]
print('') # Insert line break after test_case print
raise UnityTestException(self, {'test_source': test_source,
'line_number': line_number,
'test_case': test_case,
'failure_reason':
failure_reason})
print("") # Insert line break after test_case print
raise UnityTestException(
self,
{
"test_source": test_source,
"line_number": line_number,
"test_case": test_case,
"failure_reason": failure_reason,
},
)
if simulator_fail:
raise Exception(self, "Simulation failed.")
if not unity_pass:
raise Exception(self, "Unity test output not found.")
print('') # Insert line break after final test_case which passed
print("") # Insert line break after final test_case which passed
def repr_failure(self, excinfo):
if isinstance(excinfo.value, UnityTestException):
return '\n'.join([str(self.parent).strip('<>'),
'{}:{}:{}()'.format(
excinfo.value[1]['test_source'],
excinfo.value[1]['line_number'],
excinfo.value[1]['test_case']),
'Failure reason:',
excinfo.value[1]['failure_reason']])
return "\n".join(
[
str(self.parent).strip("<>"),
"{}:{}:{}()".format(
excinfo.value[1]["test_source"],
excinfo.value[1]["line_number"],
excinfo.value[1]["test_case"],
),
"Failure reason:",
excinfo.value[1]["failure_reason"],
]
)
else:
return str(excinfo.value)