Testreport
Overview
This Class contains all functions related to the Testreport.
Each call will generate an entry in the Testreport.
An object of Testreport is available in the Testframework. Its name is report
Group |
Available functions |
---|---|
Value Checks |
|
Information |
|
Other |
Functions
- class testreport.ClassTestreport
Bases:
object
- projectName = ''
- lastResult = None
Contains the last result of the test. You can also use provided constants to check this variable:
True
corresponds toPASSED
False
corresponds toFAILED
Example usage:
This example will abort the test if the last result was failed.
from testframework import * report.checkBool("Is sensor damped?", getInput(IN4) == HIGH) if report.lastResult == FAILED: abortTest()
Note
This behavior can also reached when the
abortTestOnFailure
is set to True. SeeabortTestOnFailure()
- setTestframeworkCoreReference(ref)
- checkBool(description: str, value: bool, expected: bool = True)
Checks for a boolean result.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (bool) – The result value which should be checked
expected (bool) – The expected value
Example usage:
from testframework import * sensorSignal = getInput(IN3) report.checkBool("Is sensor damped?", sensorSignal == HIGH)
- checkValueMinMax(description, value, min, max, unit='', digits=3)
Checks if a value is within given value range.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
min (int | float) – Lower limit which is allowed (inclusive this value)
max (int | float) – Upper limit which is allowed (inclusive this value)
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
digits (int) – number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
This code checks if the supply voltage, measured at analog input 6, is between 3,25V and 3,35V
from testframework import * supplyVoltage = getInputVoltage(AIN6) report.checkValueMinMax("Check supply voltage", supplyVoltage, 3.25, 3.35, "V")
- checkValueMin(description, value, min, unit='', digits=3)
Checks if a value is higher or equal of the given min value.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
min (int | float) – Lower limit which should the value have minimum (inclusive this value)
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
digits (int) – number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
This code checks if the supply voltage, measured at analog input 6, is between 3,25V and 3,35V
from testframework import * supplyVoltage = getInputVoltage(AIN6) report.checkValueMin("Check supply voltage", supplyVoltage, 3.25, "V")
- checkValueMax(description, value, max, unit='', digits=3)
Checks if a value is lower or equal of the given max value.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
max (int | float) – Upper limit which should the value have maximum (inclusive this value)
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
digits (int) – number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
This code checks if the supply voltage, measured at analog input 6, is between 3,25V and 3,35V
from testframework import * supplyVoltage = getInputVoltage(AIN6) report.checkValueMax("Check supply voltage", supplyVoltage, 3.5, "V")
- checkValueTollerance(description, value, expected, tol, unit='', digits=3)
Checks if a value is within given value range.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
expected (int | float) – This is the expected value
tol (int | float) – Accepted tolerance for the value (+/-)
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
digits (int) – number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
This code checks if the supply voltage, measured at analog input 6, is in the tolerance 3,3V +/- 0,05V
from testframework import * supplyVoltage = getInputVoltage(AIN6) report.checkValueTollerance("Check supply voltage", supplyVoltage, 3.3, 0.05, "V")
- checkValueTolleranceCircular(description, value, expected, tol, endValue, unit='', digits=3)
Checks if a value is within given tollerance on a circular value range (0 -
endValue
). For example: If you have an angle which is between 0° and 360° and you expect a target angle of 350° with a tollerance of 20°. With this function you can set the expected value to 350, tollerance to 20 and theendValue
to 360. The tollerance range will than automatically wrap around 360°. So all values below or equal 10° will lead to a passed result and all values above or equal 330° will lead to a passed result. All values outside the given circular range of 0 -endValue
will lead into a failed result.- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
expected (int | float) – This is the expected value
tol (int | float) – Accepted tolerance for the value (+/-)
maxValue (int | float) – The value on which the range wrapes around.
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
digits (int) – number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
This code checks if the supply voltage, measured at analog input 6, is in the tolerance 3,3V +/- 0,05V
from testframework import * #ext.init() #only neccessary if you run this code in debug console, outside of a testrun rs485 = ext.getRS485(0) modbus = ModbusMaster(rs485) values = await modbus.readInputRegisters(1, 9, 1) #read the arm-position from slave-ID 1, modbus register 9 angle = values[0] report.checkValueTolleranceCircular("Check if arm is on correct position.", angle, 350, 20, 360)
- checkValue(description, value, expected, unit='')
Checks whether the value corresponds exactly to the expected value
- Parameters:
description (string) – Testdescription which will be placed in the report
value (int | float) – Value which should be checked
expected (int | float) – This is the expected value
unit (string) – Unit of the value. This is just for the report. An empty string is allowed.
Example usage:
This code checks if the checkbox has Hardware Version 1.
from testframework import * hwVersion = getHWVersion() report.checkValue("Check Hardware Version", hwVersion, 1)
- checkString(description, value, expected)
Checks if the given string equates to the given string.
- Parameters:
description (string) – Testdescription which will be placed in the report
value (string) – String which should be checked
expected (string) – This is the expected string
Example usage:
from testframework import * uart1.init(9600) uart1.send("Wakeup") answer = uart1.readline() report.checkString("Acknowledge received", answer, "ACK") #Hint: You can do the same check with the following function too: report.checkBool("Acknowledge received", answer == "ACK")
- putInfoValue(description, value, unit='', digits=3)
Enters an ‘info only’ value to the testreport.
- Parameters:
description (string) – Description which will be placed in the report
value (int | float | string) – value for the report
unit (int) – Unit of the value (only for int and float values). This is just for the report. An empty string is allowed.
digits – Number of digits for the value if the value has type float (digits has no effect in case of integer value).
Example usage:
from testframework import * devTemp = getDeviceTemperature() report.infoValue("Device temperature", "%.1f" %devTemp)
Warning
Unfortunately at the moment the Checkbox does not support special characters. So it is not possible to use “°C” as unit in the report.
- putInfo(description)
Enters an ‘info only’ entry to the testreport.
- Parameters:
description (string) – Description which will be placed in the report
Example usage:
from testframework import * devTemp = getDeviceTemperature() report.info("All answers received")
- putPassed(description)
Inserts a passed result without any values into the testreport.
With both functions
putPassed()
andputFailed()
you can do your own test inspection.- Parameters:
description (string) – Description which will be placed in the report
Example usage:
from testframework import * report.putPassed("Answer received")
- putFailed(description)
See
putPassed()
- putPassedFailed(description, result)
Inserts a passed or failed result without any values into the testreport.
With this function you can do a quick check if somethin went wrong.
- Parameters:
description (bool) – Description which will be placed in the report
result –
True
a PASSED result will put into the testreport.False
a FAILED result will put into the testreport.
Example usage:
from testframework import * val = await modbus.readDiscreteInputs(1,0,6) report.putPassedFailed("Answer received", val!=None)
- appendTrace(description, trace)
Inserts a trace at the end of the report.
- Parameters:
description (string) – Description which will be used as title of the diagram.
trace (Trace) – trace object which should be printed
Example usage:
from testframework import * data = trace.TraceData(IN1,1000) trace.start(data,1000) report.appendTrace("Analog Signal", data)