tests package

Submodules

tests.pigpio_mocks module

Classes:

MockHardwareDevice(*args)

A simple mock device with registers defined by kwargs.

Pin(pin[, pig])

Base Class wrapping pigpio methods for interacting with GPIO pins on the raspberry pi.

deque

deque([iterable[, maxlen]]) –> deque object

Functions:

choice(seq)

Choose a random element from a non-empty sequence.

getrandbits(k)

mock_i2c_hardware()

Factory fixture for creating MockHardwareDevice objects

mock_pigpio_bad_gpio_arg(func)

mock_pigpio_bad_user_gpio_arg(func)

mock_pigpio_errors(func)

patch_bad_socket(monkeypatch)

Monkeypatches socket.create_connection() to always throw an Exception as if things had gone poorly (instead of doing anything else)

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

patch_pigpio_gpio(patch_pigpio_base, monkeypatch)

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.

patch_pigpio_i2c(patch_pigpio_base, monkeypatch)

monkeypatches pigpio.pi() with a mock I2C interface that does not depend on the pigpio daemon

token_bytes([nbytes])

Return a random byte string containing nbytes bytes.

wraps(wrapped[, assigned, updated])

Decorator factory to apply update_wrapper() to a wrapper function

Exceptions:

socket_error

alias of builtins.OSError

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

tests.pigpio_mocks.mock_pigpio_errors(func)[source]
tests.pigpio_mocks.mock_pigpio_bad_gpio_arg(func)[source]
tests.pigpio_mocks.mock_pigpio_bad_user_gpio_arg(func)[source]
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.

Parameters

*args – register_values of type bytes; one, per, register

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

__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)

read_mock_hardware_register(reg_num=None, count=None)[source]

Reads count bytes from a specific register

Parameters
  • reg_num – The index of the register to read

  • count (int) – The number of bytes to read

Returns

the register contents

Return type

bytes

write_mock_hardware_register(reg_num, value)[source]

Writes value to register specified by reg_num

Parameters
  • reg_num – The index of the register to write

  • value (bytes) – The stuff to write to the register

tests.test_alarms module

Classes:

Alarm(alarm_type, severity, start_time, …)

Representation of alarm status and parameters

AlarmSeverity(value)

An enumeration.

AlarmType(value)

An enumeration.

Alarm_Manager()

The Alarm Manager

Alarm_Rule(name, conditions[, latch, technical])

  • name of rule

ControlSetting(name, value, min_value, …)

Message containing ventilation control parameters.

SensorValues([timestamp, loop_counter, …])

Structured class for communicating sensor readings throughout PVP.

ValueName(value)

Canonical names of all values used in PVP.

Functions:

fake_rule()

fake_sensors()

test_alarm_manager_dismiss(fake_sensors, …)

  • dismissed when not latched until alarm conditions return to off then back on

test_alarm_manager_escalation(fake_sensors, …)

For unlatched alarms, test that alarms are:

test_alarm_manager_latch(fake_sensors, fake_rule)

  • not decremented when alarm severity is decreased and alarm is latched

test_alarm_manager_logged_alarms(…)

test_alarm_manager_raise(fake_sensors)

Test that the alarm manager raises a single alarm

test_alarm_rule(fake_sensors)

test the alarm rule class itself

test_alarmseverity_condition(fake_rule, …)

test_condition_addition(fake_sensors)

test_condition_dependency(fake_rule, test_mode)

test_cyclealarmseverity_condition()

test_cyclevalue_condition(fake_sensors, …)

test_rules_individual()

test_value_condition(fake_sensors, test_value)

tests.test_alarms.fake_sensors()[source]
tests.test_alarms.fake_rule()[source]
tests.test_alarms.test_value_condition(fake_sensors, test_value)[source]
tests.test_alarms.test_cyclevalue_condition(fake_sensors, test_value)[source]
tests.test_alarms.test_alarmseverity_condition(fake_rule, fake_sensors)[source]
tests.test_alarms.test_cyclealarmseverity_condition()[source]
tests.test_alarms.test_condition_addition(fake_sensors)[source]
tests.test_alarms.test_condition_dependency(fake_rule, test_mode)[source]
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_rules_individual()[source]
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_alarms.test_alarm_manager_dismiss(fake_sensors, fake_rule)[source]
  • dismissed when not latched until alarm conditions return to off then back on

  • dismissed when not latched until duration regardless of alarm condition

Parameters
  • fake_sensors

  • fake_rule

Returns:

tests.test_alarms.test_alarm_manager_logged_alarms(fake_sensors, fake_rule)[source]

tests.test_controller module

Classes:

Alarm(alarm_type, severity, start_time, …)

Representation of alarm status and parameters

AlarmSeverity(value)

An enumeration.

AlarmType(value)

An enumeration.

ControlSetting(name, value, min_value, …)

Message containing ventilation control parameters.

ValueName(value)

Canonical names of all values used in PVP.

Functions:

get_control_module([sim_mode, simulator_dt])

Generates control module.

test_control_dynamical()

This tests whether the controller is controlling pressure as intended.

test_control_settings(control_setting_name)

This test set_controls and get_controls Set and read a all five variables, make sure that they are identical.

test_erratic_dt()

This is a function to test whether the controller works with random update times

test_missed_heartbeat_alarm()

test_nan_HAL()

nan should work to, make PEEP et al.

test_random_HAL()

Simulates a broken HAL, providing (physiologically unreasonable) random numbers to infinity

test_reset_controller()

Tests the reset functionality

test_restart_controller()

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_controller.test_reset_controller()[source]

Tests the reset functionality

tests.test_controller.test_control_dynamical()[source]

This tests whether the controller is controlling pressure as intended. Start controller, set control values, measure whether actually there.

tests.test_controller.test_missed_heartbeat_alarm()[source]
tests.test_controller.test_random_HAL()[source]

Simulates a broken HAL, providing (physiologically unreasonable) random numbers to infinity

tests.test_controller.test_nan_HAL()[source]

nan should work to, make PEEP et al. nan

tests.test_controller.test_erratic_dt()[source]

This is a function to test whether the controller works with random update times

tests.test_coordinator module

Classes:

Alarm(alarm_type, severity, start_time, …)

Representation of alarm status and parameters

AlarmSeverity(value)

An enumeration.

ControlModuleBase(save_logs, flush_every)

Abstract controller class for simulation/hardware.

ControlModuleMock()

Initializes the ControlModuleBase class.

ControlSetting(name, value, min_value, …)

Message containing ventilation control parameters.

Mock(*args, **kw)

Create a new Mock object.

SensorValues([timestamp, loop_counter, …])

Structured class for communicating sensor readings throughout PVP.

ValueName(value)

Canonical names of all values used in PVP.

Functions:

get_coordinator([single_process, sim_mode])

is_port_in_use(port)

mock_get_control_module(sim_mode)

patch(target[, new, spec, create, spec_set, …])

patch acts as a function decorator, class decorator or a context manager.

test_local_coordinator(control_setting_name)

test_local_sensors()

test_process_manager()

test_remote_coordinator(control_setting_name)

test_remote_sensors()

tests.test_coordinator.is_port_in_use(port)[source]
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_active_alarms()

get_control(control_setting_name)

A method callable from the outside to get current control settings.

get_logged_alarms()

get_sensors()

A method callable from the outside to get a copy of sensorValues

is_running()

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

bool

start()[source]

Method to start _start_mainloop as a thread.

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

SensorValues

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

ControlSetting

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]

get_active_alarms()[source]
get_logged_alarms()[source]
tests.test_coordinator.mock_get_control_module(sim_mode)[source]
tests.test_coordinator.test_local_coordinator(control_setting_name)[source]
tests.test_coordinator.test_remote_coordinator(control_setting_name)[source]
tests.test_coordinator.test_process_manager()[source]
tests.test_coordinator.test_local_sensors()[source]
tests.test_coordinator.test_remote_sensors()[source]

tests.test_gui module

test objects * main * components * control * monitor * plot * control_panel

test types * user interaction * flooding

Classes:

Alarm(alarm_type, severity, start_time, …)

Representation of alarm status and parameters

AlarmSeverity(value)

An enumeration.

AlarmType(value)

An enumeration.

Alarm_Manager()

The Alarm Manager

ValueName(value)

Canonical names of all values used in PVP.

Functions:

copy(x)

Shallow copy operation on arbitrary Python objects.

fake_rule()

fake_sensors()

generic_minmax()

Make a (min, max) range of values that has some safe space in between.

generic_saferange()

Make a (min, max) range of values that has some safe space in between.

get_coordinator([single_process, sim_mode])

sleep(seconds)

Delay execution for a given number of seconds.

spawn_gui(qtbot)

test_VTE_set(qtbot, spawn_gui)

test_alarm_bar(qtbot, fake_rule)

test_alarm_manager_signals(qtbot, spawn_gui)

test_autoset_cycle(qtbot, spawn_gui, test_value)

test_doubleslider(qtbot)

test that the doubleslider accurately represents floats

test_doubleslider_minmax(qtbot, generic_minmax)

test_editable_label(qtbot)

test_gui_controls(qtbot, spawn_gui, …)

test setting controls in all the ways available to the GUI

test_gui_launch(qtbot)

test_gui_main_etc(qtbot, spawn_gui)

test_handle_controller_alarm(qtbot, spawn_gui)

test_pressure_unit_conversion(qtbot, …)

test_raise_alarm_card(qtbot, spawn_gui, …)

test_save_restore_gui_state(qtbot, spawn_gui)

test_set_breath_detection(qtbot, spawn_gui)

time()

Return the current time in seconds since the Epoch.

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.spawn_gui(qtbot)[source]
tests.test_gui.fake_sensors()[source]
tests.test_gui.test_gui_launch(qtbot)[source]
tests.test_gui.test_gui_controls(qtbot, spawn_gui, test_value, test_units)[source]

test setting controls in all the ways available to the GUI

from the Control widget:

Parameters
  • qtbot

  • spawn_gui

  • test_value

tests.test_gui.test_VTE_set(qtbot, spawn_gui)[source]
tests.test_gui.test_autoset_cycle(qtbot, spawn_gui, test_value)[source]
tests.test_gui.test_alarm_manager_signals(qtbot, spawn_gui)[source]
tests.test_gui.test_handle_controller_alarm(qtbot, spawn_gui)[source]
tests.test_gui.test_save_restore_gui_state(qtbot, spawn_gui)[source]
tests.test_gui.test_raise_alarm_card(qtbot, spawn_gui, fake_sensors)[source]
tests.test_gui.test_gui_main_etc(qtbot, spawn_gui)[source]
tests.test_gui.test_pressure_unit_conversion(qtbot, spawn_gui, fake_sensors)[source]
tests.test_gui.test_set_breath_detection(qtbot, spawn_gui)[source]
tests.test_gui.test_alarm_bar(qtbot, fake_rule)[source]
tests.test_gui.test_doubleslider(qtbot)[source]

test that the doubleslider accurately represents floats

tests.test_gui.test_doubleslider_minmax(qtbot, generic_minmax)[source]
tests.test_gui.test_editable_label(qtbot)[source]

tests.test_io_devices module

Classes:

ADS1015([address, i2c_bus, pig])

ADS1015 16 bit, 4 Channel Analog to Digital Converter. Datasheet: http://www.ti.com/lit/ds/symlink/ads1015.pdf?&ts=1589228228921.

ADS1115([address, i2c_bus, pig])

ADS1115 16 bit, 4 Channel Analog to Digital Converter. Datasheet: http://www.ti.com/lit/ds/symlink/ads1114.pdf?ts=1587872241912.

I2CDevice(i2c_address, i2c_bus[, pig])

A class wrapper for pigpio I2C handles.

IODeviceBase(pig)

Abstract base Class for pigpio handles (or whatever other GPIO library we end up using)

MockHardwareDevice(*args)

A simple mock device with registers defined by kwargs.

SPIDevice(channel, baudrate[, pig])

A class wrapper for pigpio SPI handles.

Functions:

mock_i2c_hardware()

Factory fixture for creating MockHardwareDevice objects

patch_bad_socket(monkeypatch)

Monkeypatches socket.create_connection() to always throw an Exception as if things had gone poorly (instead of doing anything else)

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

patch_pigpio_gpio(patch_pigpio_base, monkeypatch)

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.

patch_pigpio_i2c(patch_pigpio_base, monkeypatch)

monkeypatches pigpio.pi() with a mock I2C interface that does not depend on the pigpio daemon

test_i2c_device(patch_pigpio_i2c, …)

__________________________________________________________________________________________________________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.

test_io_device_base_no_handles_to_close(…)

__________________________________________________________________________________________________________TEST #3 Tests that IODeviceBase._close() returns cleanly when it has no handles

test_mock_pigpio_base(patch_pigpio_base)

__________________________________________________________________________________________________________TEST #1 Tests that the base fixture of pigpio mocks is indeed enough to instantiate pigpio.pi()

test_mock_pigpio_i2c(patch_pigpio_i2c, …)

__________________________________________________________________________________________________________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. 3) 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.

test_pigpio_connection_exception(…)

__________________________________________________________________________________________________________TEST #2 Tests to make sure an exception is thrown if, upon init, a PigpioConnection finds it is not connected.

test_read_conversion(patch_pigpio_i2c, …)

_________________________________________________________________________________________________________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

test_register_arg_exception()

__________________________________________________________________________________________________________TEST #6 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments

test_spi_device(patch_pigpio_i2c)

__________________________________________________________________________________________________________TEST #9 Tests that an SPI device can be created without issue.

test_value_field_insert_unknown_value_exception()

__________________________________________________________________________________________________________TEST #8 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments

test_value_field_pack_unknown_value_exception()

__________________________________________________________________________________________________________TEST #7 Tests that I2CDevice.Register throws an exception if it tries to init with a mismatched number of arguments

token_bytes([nbytes])

Return a random byte string containing nbytes bytes.

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.

      1. 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

Classes:

Hal([config_file])

Hardware Abstraction Layer for ventilator hardware.

Functions:

getrandbits(k)

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

randint(a, b)

Return random integer in range [a, b], including both end points.

test_functions(patch_pigpio_base)

__________________________________________________________________________________________________________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_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

Classes:

PWMOutput(pin[, initial_duty, frequency, pig])

A pin configured to output a PWM signal.

Pin(pin[, pig])

Base Class wrapping pigpio methods for interacting with GPIO pins on the raspberry pi.

Functions:

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

patch_pigpio_gpio(patch_pigpio_base, monkeypatch)

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.

test_bad_mode_exception(patch_pigpio_gpio)

__________________________________________________________________________________________________________TEST #2 Tests that an exception is thrown if an attempt is made to set an unrecognized mode

test_duty(patch_pigpio_gpio, gpio, duty)

__________________________________________________________________________________________________________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

test_frequency(patch_pigpio_gpio, seed)

__________________________________________________________________________________________________________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)

test_mode(patch_pigpio_gpio, seed, gpio)

__________________________________________________________________________________________________________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

test_read_write_toggle(patch_pigpio_gpio, …)

__________________________________________________________________________________________________________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

token_bytes([nbytes])

Return a random byte string containing nbytes bytes.

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

Classes:

ADS1015([address, i2c_bus, pig])

ADS1015 16 bit, 4 Channel Analog to Digital Converter. Datasheet: http://www.ti.com/lit/ds/symlink/ads1015.pdf?&ts=1589228228921.

ADS1115([address, i2c_bus, pig])

ADS1115 16 bit, 4 Channel Analog to Digital Converter. Datasheet: http://www.ti.com/lit/ds/symlink/ads1114.pdf?ts=1587872241912.

AnalogSensor(adc, **kwargs)

Generalized class describing an analog sensor attached to the ADS1115 analog to digital converter.

DLiteSensor(adc, **kwargs)

D-Lite flow sensor setup.

SFM3200([address, i2c_bus, pig])

I2C Inspiratory flow sensor manufactured by Sensirion AG. Range: +/- 250 SLM Datasheet: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/ … … 5_Mass_Flow_Meters/Datasheets/Sensirion_Mass_Flow_Meters_SFM3200_Datasheet.pdf.

Sensor()

Abstract base Class describing generalized sensors.

SimSensor([low, high, pig])

TODO Stub simulated sensor.

Functions:

mock_i2c_hardware()

Factory fixture for creating MockHardwareDevice objects

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

patch_pigpio_gpio(patch_pigpio_base, monkeypatch)

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.

patch_pigpio_i2c(patch_pigpio_base, monkeypatch)

monkeypatches pigpio.pi() with a mock I2C interface that does not depend on the pigpio daemon

test_analog_sensor_average_read(…)

__________________________________________________________________________________________________________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

test_analog_sensor_kwarg_exceptions(…)

__________________________________________________________________________________________________________TEST #5 Tests that an exception is properly raised when either: - a kwarg is passed that it unrecognized - MUX is not passed in kwargs

test_analog_sensor_single_read(…)

__________________________________________________________________________________________________________TEST #3 Tests the proper functioning of an AnalogSensor with random, but plausible, calibration.

test_analog_sensor_single_read_drop_kwargs(…)

__________________________________________________________________________________________________________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.

test_sensor()

__________________________________________________________________________________________________________TEST #1 Tests errors are thrown when you try to do stuff with the abstract base class

test_sfm_single_read(patch_pigpio_i2c, …)

__________________________________________________________________________________________________________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).

test_sim_sensor(patch_pigpio_i2c, …)

__________________________________________________________________________________________________________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.

token_bytes([nbytes])

Return a random byte string containing nbytes bytes.

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

Classes:

OnOffValve(pin[, form, pig])

An extension of pvp.io.iobase.Pin which uses valve terminology for its methods.

PWMControlValve(pin[, form, frequency, …])

An extension of PWMOutput which incorporates linear compensation of the valve’s response.

SimControlValve([pin, form, frequency, …])

stub: a simulated linear control valve

SimOnOffValve([pin, form, pig])

stub: a simulated on/off valve

Functions:

patch_pigpio_base(monkeypatch)

monkeypatches the bare-minimum elements of pigpio to instantiate pigpio.pi() without communicating with the pigpio daemon (or hardware)

patch_pigpio_gpio(patch_pigpio_base, monkeypatch)

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.

test_form(patch_pigpio_gpio, gpio, form)

__________________________________________________________________________________________________________TEST #1 Tests the set/get interface of SolenoidBase/children - Initializes an OnOffValve - Sets a form - asserts form is set to expected form

test_on_off_valve(patch_pigpio_gpio, gpio, form)

__________________________________________________________________________________________________________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

test_pwm_control_valve(patch_pigpio_gpio, seed)

__________________________________________________________________________________________________________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.

test_sim_control_valve(patch_pigpio_gpio, gpio)

__________________________________________________________________________________________________________TEST #5 Tests SimControlValve in much the same way as PWMControlValve.

test_sim_on_off_valve(patch_pigpio_gpio, …)

__________________________________________________________________________________________________________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

test_valve_paths(patch_pigpio_gpio)

token_bytes([nbytes])

Return a random byte string containing nbytes bytes.

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_valve_paths(patch_pigpio_gpio)[source]
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

tests.test_io_valves.test_sim_control_valve(patch_pigpio_gpio, gpio)[source]

__________________________________________________________________________________________________________TEST #5 Tests SimControlValve in much the same way as PWMControlValve.

tests.test_logging module

Classes:

ControlSetting(name, value, min_value, …)

Message containing ventilation control parameters.

ControlValues(control_signal_in, …)

Class to save control values, analogous to SensorValues.

DataLogger(compression_level)

Class for logging numerical respiration data and control settings. Creates a hdf5 file with this general structure: / root |— waveforms (group) | |— time | pressure_data | flow_out | control_signal_in | control_signal_out | FiO2 | Cycle No. | |— controls (group) | |— (time, controllsignal) | |— derived_quantities (group) | |— (time, Cycle No, I_PHASE_DURATION, PIP_TIME, PEEP_time, PIP, PIP_PLATEAU, PEEP, VTE ) | |.

DerivedValues(timestamp, breath_count, …)

Class to save derived values, analogous to SensorValues.

SensorValues([timestamp, loop_counter, …])

Structured class for communicating sensor readings throughout PVP.

ValueName(value)

Canonical names of all values used in PVP.

Functions:

test_checks()

test_control_storage(control_setting_name)

test_derived_storage()

test_sensor_storage()

tests.test_logging.test_control_storage(control_setting_name)[source]
tests.test_logging.test_sensor_storage()[source]
tests.test_logging.test_derived_storage()[source]
tests.test_logging.test_checks()[source]

Module contents