From 32ba736e05f70b95e63391db621458c045b77453 Mon Sep 17 00:00:00 2001 From: Bruce Schubert Date: Wed, 19 Aug 2020 11:54:39 -0700 Subject: [PATCH] Added close method to indicators to release GPIO pins --- src/hardware/indicators.py | 3 ++ src/messaging/voicemail.py | 67 -------------------------------------- tests/test_modem.py | 4 ++- 3 files changed, 6 insertions(+), 68 deletions(-) diff --git a/src/hardware/indicators.py b/src/hardware/indicators.py index 5a8699d..bb0f63d 100644 --- a/src/hardware/indicators.py +++ b/src/hardware/indicators.py @@ -47,6 +47,9 @@ def blink(self, max_times=10): def turn_off(self): self.led.off() + def close(self): + self.led.close() + def __init__(self, gpio_pin): self.led = LED(gpio_pin) diff --git a/src/messaging/voicemail.py b/src/messaging/voicemail.py index b87a7a4..cfbcd84 100644 --- a/src/messaging/voicemail.py +++ b/src/messaging/voicemail.py @@ -128,70 +128,3 @@ def reset_message_indicator(self): self.message_indicator.pulse() else: self.message_indicator.turn_off() - - -def test(db, config): - """ - Unit Tests - """ - - print("*** Running VoiceMail Unit Tests ***") - - # Create dependencies - from hardware.modem import Modem - from screening.calllogger import CallLogger - modem = Modem(config, lambda arg: arg, lambda arg: arg) - modem.open_serial_port() - logger = CallLogger(db, config) - # Create the object to be tested - voicemail = VoiceMail(db, config, modem) - - # Test data - caller = {"NAME": "Bruce", "NMBR": "1234567890", "DATE": "1012", "TIME": "0600"} - - try: - call_no = logger.log_caller(caller) - - msg_no = voicemail.record_message(call_no, caller) - - count = voicemail.get_unplayed_count() - assert count == 1, "Unplayed count should be 1" - - # List the records - query = 'select * from Message' - curs = db.execute(query) - print(query + " results:") - pprint(curs.fetchall()) - - voicemail.delete_message(msg_no) - - except AssertionError as e: - print("*** Unit Test FAILED ***") - pprint(e) - return 1 - - print("*** Unit Tests PASSED ***") - return 0 - - -if __name__ == '__main__': - - # Create the test db in RAM - import sqlite3 - db = sqlite3.connect(":memory:") - - # Add the parent directory to the path so callattendant can be found - import os - import sys - currentdir = os.path.dirname(os.path.realpath(__file__)) - parentdir = os.path.dirname(currentdir) - sys.path.append(parentdir) - - # Create and tweak a default config suitable for unit testing - from callattendant import make_config, print_config - config = make_config() - config['DEBUG'] = True - print_config(config) - - # Run the tests - sys.exit(test(db, config)) diff --git a/tests/test_modem.py b/tests/test_modem.py index 740785e..4deff53 100644 --- a/tests/test_modem.py +++ b/tests/test_modem.py @@ -56,7 +56,9 @@ def modem(): # modem.open_serial_port() modem._init_modem() - return modem + yield modem + + modem.ring_indicator.close() def test_factory_reset(modem):