tests package¶
Submodules¶
tests.pigpio_mocks module¶
Classes
|
A simple mock device with registers defined by kwargs. |
Functions
|
|
Factory fixture for creating MockHardwareDevice objects |
|
|
|
|
|
|
Monkeypatches socket.create_connection() to always throw an Exception as if things had gone poorly (instead of |
|
monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the |
|
monkeypatches pigpio.pi with a mock GPIO interface. |
|
monkeypatches pigpio.pi() with a mock I2C interface that does not depend on the pigpio daemon |
-
tests.pigpio_mocks.
getrandbits
(k) → x. Generates an int with k random bits.¶
-
tests.pigpio_mocks.
patch_pigpio_base
(monkeypatch)[source]¶ monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)
-
tests.pigpio_mocks.
patch_bad_socket
(monkeypatch)[source]¶ Monkeypatches socket.create_connection() to always throw an Exception as if things had gone poorly (instead of doing anything else)
-
tests.pigpio_mocks.
patch_pigpio_i2c
(patch_pigpio_base, monkeypatch)[source]¶ monkeypatches pigpio.pi() with a mock I2C interface that does not depend on the pigpio daemon
-
tests.pigpio_mocks.
patch_pigpio_gpio
(patch_pigpio_base, monkeypatch)[source]¶ monkeypatches pigpio.pi with a mock GPIO interface. - Creates a new list “pigpio.pi.mock_pins” of MockPigpioPin objects, one for each RPi GPIO pin. - monkeypatches pigpio.pi.get_mode() to look at pigpio.pi.mock_pins for the mode of each pin instead of
communicating with the pigpiod daemon.
monkeypatches pigpio.pi.set_mode() in a similar manner
-
tests.pigpio_mocks.
mock_i2c_hardware
()[source]¶ Factory fixture for creating MockHardwareDevice objects
-
class
tests.pigpio_mocks.
MockHardwareDevice
(*args)[source]¶ Bases:
object
A simple mock device with registers defined by kwargs. If only one register value is passed, device emulates a single register device that responds to read_device commands (such as the SFM3200). Retains past register values upon writing to a register for logging/assertion convenience.
- Register values are stored as raw bytes. Reading and writing to/from the registers simulates network-endian
transactions by byteswapping.
Methods
__init__
(*args)A simple mock device with registers defined by kwargs.
read_mock_hardware_device
([count])Alias for read_mock_hardware_register(reg_num=None, count)
read_mock_hardware_register
([reg_num, count])Reads count bytes from a specific register
write_mock_hardware_device
(value)Alias for write_mock_hardware_register(reg_num=None, value)
write_mock_hardware_register
(reg_num, value)Writes value to register specified by reg_num
- Parameters
*args – register_values of type bytes; one, per, register
-
__init__
(*args)[source]¶ A simple mock device with registers defined by kwargs. If only one register value is passed, device emulates a single register device that responds to read_device commands (such as the SFM3200). Retains past register values upon writing to a register for logging/assertion convenience.
- Register values are stored as raw bytes. Reading and writing to/from the registers simulates network-endian
transactions by byteswapping.
- Parameters
*args – register_values of type bytes; one, per, register
-
read_mock_hardware_device
(count=None)[source]¶ Alias for read_mock_hardware_register(reg_num=None, count)
-
write_mock_hardware_device
(value)[source]¶ Alias for write_mock_hardware_register(reg_num=None, value)
tests.test_alarms module¶
Functions
|
|
|
For unlatched alarms, test that alarms are: |
|
|
|
Test that the alarm manager raises a single alarm |
|
test the alarm rule class itself |
|
|
|
-
tests.test_alarms.
test_alarm_rule
(fake_sensors)[source]¶ test the alarm rule class itself
assume the individual conditions have been tested
-
tests.test_alarms.
test_alarm_manager_raise
(fake_sensors)[source]¶ Test that the alarm manager raises a single alarm
- Parameters
fake_sensors –
Returns:
-
tests.test_alarms.
test_alarm_manager_escalation
(fake_sensors, fake_rule)[source]¶ For unlatched alarms, test that alarms are:
emitted when alarm severity is raised
decremented when alarm severity is decreased and alarm is not latched
deactivated and deleted
-
tests.test_alarms.
test_alarm_manager_latch
(fake_sensors, fake_rule)[source]¶ not decremented when alarm severity is decreased and alarm is latched
dismissed when latched only when alarm condition is OFF AND has been dismissed
- Parameters
fake_sensors –
fake_rule –
Returns:
tests.test_controller module¶
Functions
This tests whether the controller is controlling pressure as intended. |
|
|
This test set_controls and get_controls Set and read a all five variables, make sure that they are identical. |
This is a function to test whether the controller works with random update times |
|
This tests whether the controller can be started and stopped 10 times without problems |
-
tests.test_controller.
test_control_settings
(control_setting_name)[source]¶ This test set_controls and get_controls Set and read a all five variables, make sure that they are identical.
-
tests.test_controller.
test_restart_controller
()[source]¶ This tests whether the controller can be started and stopped 10 times without problems
tests.test_coordinator module¶
Classes
Initializes the ControlModuleBase class. |
Functions
|
|
|
|
|
|
|
|
-
class
tests.test_coordinator.
ControlModuleMock
[source]¶ Bases:
pvp.controller.control_module.ControlModuleBase
Initializes the ControlModuleBase class.
- Parameters
save_logs (bool, optional) – Should sensor data and controls should be saved with the
DataLogger
? Defaults to False.flush_every (int, optional) – Flush and rotate logs every n breath cycles. Defaults to 10.
- Raises
alert – [description]
Methods
get_control
(control_setting_name)A method callable from the outside to get current control settings.
A method callable from the outside to get a copy of sensorValues
Public Method to assess whether the main loop thread is running.
set_control
(control_setting)A method callable from the outside to set alarms.
start
()Method to start _start_mainloop as a thread.
-
is_running
()[source]¶ Public Method to assess whether the main loop thread is running.
- Returns
Return true if and only if the main thread of controller is running.
- Return type
-
get_sensors
()[source]¶ A method callable from the outside to get a copy of sensorValues
- Returns
A set of current sensorvalues, handeled by the controller.
- Return type
-
get_control
(control_setting_name: pvp.common.values.ValueName) → pvp.common.message.ControlSetting[source]¶ A method callable from the outside to get current control settings. This returns values of COPY to the outside world.
- Parameters
control_setting_name (ValueName) – The specific control asked for
- Returns
ControlSettings-Object that contains relevant data
- Return type
-
set_control
(control_setting: pvp.common.message.ControlSetting)[source]¶ A method callable from the outside to set alarms. This updates the entries of COPY with new control values.
- Parameters
control_setting (ControlSetting) – [description]
tests.test_gui module¶
test objects * main * components * control * monitor * plot * control_panel
test types * user interaction * flooding
Functions
Make a (min, max) range of values that has some safe space in between. |
|
Make a (min, max) range of values that has some safe space in between. |
|
|
|
|
|
|
|
|
|
|
test that the doubleslider accurately represents floats |
|
|
|
test setting controls in all the ways available to the GUI |
|
|
|
|
|
|
|
|
|
|
-
tests.test_gui.
generic_minmax
()[source]¶ Make a (min, max) range of values that has some safe space in between.
ie. min can be between 0 and 0.25*(minmax_range[1]-minmax_range[0]) and max can similarly be above the 75% mark of the range Returns:
-
tests.test_gui.
generic_saferange
()[source]¶ Make a (min, max) range of values that has some safe space in between.
ie. min can be between 0 and 0.25*(minmax_range[1]-minmax_range[0]) and max can similarly be above the 75% mark of the range Returns:
-
tests.test_gui.
test_gui_controls
(qtbot, spawn_gui, test_value)[source]¶ test setting controls in all the ways available to the GUI
from the
Control
widget:EditableLabel
- setting label textsetting slider value
using
set_value()
- Parameters
qtbot –
spawn_gui –
test_value –
tests.test_io_devices module¶
Functions
|
__________________________________________________________________________________________________________TEST #5 |
__________________________________________________________________________________________________________TEST #3 |
|
|
__________________________________________________________________________________________________________TEST #1 |
|
__________________________________________________________________________________________________________TEST #4 |
__________________________________________________________________________________________________________TEST #2 |
|
|
_________________________________________________________________________________________________________TEST #10 |
__________________________________________________________________________________________________________TEST #6 |
|
|
__________________________________________________________________________________________________________TEST #9 |
__________________________________________________________________________________________________________TEST #8 |
|
__________________________________________________________________________________________________________TEST #7 |
-
tests.test_io_devices.
test_mock_pigpio_base
(patch_pigpio_base)[source]¶ __________________________________________________________________________________________________________TEST #1 Tests that the base fixture of pigpio mocks is indeed enough to instantiate pigpio.pi()
-
tests.test_io_devices.
test_pigpio_connection_exception
(patch_pigpio_base, patch_bad_socket)[source]¶ __________________________________________________________________________________________________________TEST #2 Tests to make sure an exception is thrown if, upon init, a PigpioConnection finds it is not connected.
-
tests.test_io_devices.
test_io_device_base_no_handles_to_close
(patch_pigpio_base, monkeypatch)[source]¶ __________________________________________________________________________________________________________TEST #3 Tests that IODeviceBase._close() returns cleanly when it has no handles
-
tests.test_io_devices.
test_mock_pigpio_i2c
(patch_pigpio_i2c, mock_i2c_hardware, seed)[source]¶ __________________________________________________________________________________________________________TEST #4 Tests the functionality of the mock pigpio i2c device interface. More specifically, tests that: - mock hardware devices are initialized correctly - mock handles, i2c_open(), and i2c_close() can be used to add, interact with, and remove mock hardware devices
correct functioning of i2c_open is implied by the read/write tests
the correct functioning of i2c_close() is ascertained from the assertion that pig.mock_i2c[i2c_bus] is empty
- mock i2c read and write functions work as intended:
- This is three tests in one. For each register of each mock hardware device:
1) Read the register with i2c_read and store the result in results[‘init’]. We expect it to be the value from the correct register of the matching mock_device (expected[‘init’]) 2) Write two random bytes to the register with i2c_write. Look at the actual contents of the target register
and put them in results[‘write’]. We expect them to be the same as the two random bytes we generated.
- Read the register with i2c_read again and put the results in expected[‘read’]. These should also match
the two random bytes from the ‘write’ test.
-> Assert that the results match what we expect
- if there is only one register on the device, test read_device() and write_device() instead of read_register()
and write_register() -> this matches how such a device would be interacted with in practice.
-
tests.test_io_devices.
test_i2c_device
(patch_pigpio_i2c, mock_i2c_hardware, seed)[source]¶ __________________________________________________________________________________________________________TEST #5 Tests the various basic I2CDevice methods, open, close, read, write, etc.
Note: i2c_device.read_device() returns raw bytes (assumed to have big-endian ordering.) read_register, on the
other hand, returns the integer representation of those bytes. write_device and write_register take an integer argument which is the written to the device register as a big-endian two’s complement. - The RPi is native little endian, so to simulate/test the byte-swapping that occurs over I2C we generate a random 16-bit integer (data), write it to the register, and read it back. - If the int->byte-> int conversions in i2c_device are working correctly, we should expect one of two possible
- values to be returned (depending on whether read_device() or read_register() is called)
read_device() should return the big-endian two’s complement of data
read_register() should just return data
-
tests.test_io_devices.
test_register_arg_exception
()[source]¶ __________________________________________________________________________________________________________TEST #6 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments
-
tests.test_io_devices.
test_value_field_pack_unknown_value_exception
()[source]¶ __________________________________________________________________________________________________________TEST #7 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments
-
tests.test_io_devices.
test_value_field_insert_unknown_value_exception
()[source]¶ __________________________________________________________________________________________________________TEST #8 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments
-
tests.test_io_devices.
test_spi_device
(patch_pigpio_i2c)[source]¶ __________________________________________________________________________________________________________TEST #9 Tests that an SPI device can be created without issue. That’s about all you can do with one of these anyway.
-
tests.test_io_devices.
test_read_conversion
(patch_pigpio_i2c, mock_i2c_hardware, ads1x15, seed)[source]¶ _________________________________________________________________________________________________________TEST #10 Tests that the proper cfg is generated and written to the config register given kwargs, and tests that the
conversion register is properly read & converted to signed int
tests.test_io_hal module¶
Functions
|
|
|
__________________________________________________________________________________________________________TEST #1 |
-
tests.test_io_hal.
getrandbits
(k) → x. Generates an int with k random bits.¶
-
tests.test_io_hal.
test_functions
(patch_pigpio_base)[source]¶ __________________________________________________________________________________________________________TEST #1 Using simulated sensors, tests that hal initializes correctly, that sensors can be read, and that all valves
can be open, closed, and/or controlled using the setpoint properties of Hal. - Checks to make sure that valves report as being open if they are not fully closed (i.e. if they have a
nonzero setpoint)
tests.test_io_pins module¶
Functions
|
__________________________________________________________________________________________________________TEST #2 |
|
__________________________________________________________________________________________________________TEST #5 |
|
__________________________________________________________________________________________________________TEST #4 |
|
__________________________________________________________________________________________________________TEST #1 |
|
__________________________________________________________________________________________________________TEST #3 |
-
tests.test_io_pins.
test_mode
(patch_pigpio_gpio, seed, gpio)[source]¶ __________________________________________________________________________________________________________TEST #1 Tests the mode setting & getting methods of Pin
Initializes a Pin
Reads mode off pin (should be random)
Writes a mode to Pin
Reads the mode back from the Pin
Asserts that the first (random) mode read is a valid mode
Asserts that the second mode is the mode we set
-
tests.test_io_pins.
test_bad_mode_exception
(patch_pigpio_gpio)[source]¶ __________________________________________________________________________________________________________TEST #2 Tests that an exception is thrown if an attempt is made to set an unrecognized mode
-
tests.test_io_pins.
test_read_write_toggle
(patch_pigpio_gpio, gpio, level)[source]¶ __________________________________________________________________________________________________________TEST #3 Tests the toggle feature of a Pin
Initializes a random Pin (in User_GPIO)
Sets mode to ‘OUTPUT’
Writes a random level to Pin
Reads the pin and stores in results
Writes the level to Pin again
Toggles the Pin
Reads the Pin and stores in results
Asserts that the result is [level, not level]
Checks that an exception is thrown if you try to write a bad value
-
tests.test_io_pins.
test_frequency
(patch_pigpio_gpio, seed)[source]¶ __________________________________________________________________________________________________________TEST #4 Tests the frequency setter & getter properties, and checks that duty is not changed or something weird like that
Initializes a PWMOutput
Sets frequency
reads frequency and appends to results
reads duty and appends to results
set up a condition that should never happen and check that the driver recovers (lie: hardware_enabled = True)
-
tests.test_io_pins.
test_duty
(patch_pigpio_gpio, gpio, duty)[source]¶ __________________________________________________________________________________________________________TEST #5 Tests the duty setter & getter properties (and synonym write())
Initializes a PWMOutput
Reads frequency and appends to results
Writes duty
Reads duty and appends to results
Reads freqency and appends to results
Asserts frequency was not changed
Asserts duty read from pin matches input
tests.test_io_sensors module¶
Functions
__________________________________________________________________________________________________________TEST #6 |
|
__________________________________________________________________________________________________________TEST #5 |
|
__________________________________________________________________________________________________________TEST #3 |
|
__________________________________________________________________________________________________________TEST #4 |
|
__________________________________________________________________________________________________________TEST #1 |
|
|
__________________________________________________________________________________________________________TEST #7 |
|
__________________________________________________________________________________________________________TEST #2 |
-
tests.test_io_sensors.
test_sensor
()[source]¶ __________________________________________________________________________________________________________TEST #1 Tests errors are thrown when you try to do stuff with the abstract base class
-
tests.test_io_sensors.
test_sim_sensor
(patch_pigpio_i2c, mock_i2c_hardware)[source]¶ __________________________________________________________________________________________________________TEST #2 Tests the proper functioning of a simulated sensor. Not much to this one, really. Also checks that age sends back -1
when update() has not been called
-
tests.test_io_sensors.
test_analog_sensor_single_read
(patch_pigpio_i2c, mock_i2c_hardware, ads1x15, seed, pga, mode)[source]¶ __________________________________________________________________________________________________________TEST #3 Tests the proper functioning of an AnalogSensor with random, but plausible, calibration.
- Performs a sequence of observations and verifies that each matches expectations and that the age of each reading
properly reflects called updates
-
tests.test_io_sensors.
test_analog_sensor_single_read_drop_kwargs
(patch_pigpio_i2c, mock_i2c_hardware, ads1x15, seed)[source]¶ __________________________________________________________________________________________________________TEST #4 Same as the above test, except it will randomly drop kwargs to check that the default attributes are
properly filled in and that the read functions normally. - Note: calibration values are stored seperately s.t. the later verification of the result can be calculated
even without the store the default calibration for later conversion.
-
tests.test_io_sensors.
test_analog_sensor_kwarg_exceptions
(patch_pigpio_i2c, mock_i2c_hardware, ads1x15, seed, pga, mode)[source]¶ __________________________________________________________________________________________________________TEST #5 Tests that an exception is properly raised when either:
a kwarg is passed that it unrecognized
MUX is not passed in kwargs
-
tests.test_io_sensors.
test_analog_sensor_average_read
(patch_pigpio_i2c, mock_i2c_hardware, ads1x15, seed)[source]¶ __________________________________________________________________________________________________________TEST #6 Performs a several updates before averaging AnalogSensor.data to determine if the result matches expectations
Data loaded into the conversion register is gaussian normal about the expected value
-
tests.test_io_sensors.
test_sfm_single_read
(patch_pigpio_i2c, mock_i2c_hardware, seed)[source]¶ __________________________________________________________________________________________________________TEST #7 Tests the proper functioning of an SFM sensor. similar to single read of analog sensor, except starts with 4 bytes
in the register and discards two (just like in real life)
tests.test_io_valves module¶
Functions
|
__________________________________________________________________________________________________________TEST #1 |
|
__________________________________________________________________________________________________________TEST #2 |
|
__________________________________________________________________________________________________________TEST #3 |
|
__________________________________________________________________________________________________________TEST #5 |
|
__________________________________________________________________________________________________________TEST #4 |
-
tests.test_io_valves.
test_form
(patch_pigpio_gpio, gpio, form)[source]¶ __________________________________________________________________________________________________________TEST #1 Tests the set/get interface of SolenoidBase/children
Initializes an OnOffValve
Sets a form
asserts form is set to expected form
-
tests.test_io_valves.
test_on_off_valve
(patch_pigpio_gpio, gpio, form)[source]¶ __________________________________________________________________________________________________________TEST #2 Tests the open/close interface of an OnOffValve
Initializes an OnOffValve
records is_open
Opens the valve, records is_open
Closes the valve, records is_open
Asserts that the valve follows the pattern of a cycled valve with the set form
-
tests.test_io_valves.
test_pwm_control_valve
(patch_pigpio_gpio, seed)[source]¶ __________________________________________________________________________________________________________TEST #3 Tests the open/close interface of an PWMControlValve. This should mimic the behavior of an OnOffValve, but uses a
- different backend.
Tests that an exception is raised if an attempt is made to initialize w/o a response curve
Initializes a PWMControlValve
Checks proper functioning of open()/close() commands
- Checks that valve.setpoint = 100 -> sets the highest duty of the ‘rising’ == True column of the response file
And that valve.is_open works
- Checks that valve.setpoint = 1 -> sets the lowest duty from the ‘rising’ == False column of the response file
And that valve.is_open still reports that the valve is open
Checks that valve.setpoint = 0 -> valve.duty = 0 & valve.is_open reports false
-
tests.test_io_valves.
test_sim_on_off_valve
(patch_pigpio_gpio, gpio, form)[source]¶ __________________________________________________________________________________________________________TEST #4 Tests the open/close interface of an SimOnOffValve
Initializes an OnOffValve
records is_open
Opens the valve, records is_open
Closes the valve, records is_open
Asserts that the valve follows the pattern of a cycled valve with the set form