Skip to content

Commit

Permalink
Added close method to indicators to release GPIO pins
Browse files Browse the repository at this point in the history
  • Loading branch information
emxsys committed Aug 19, 2020
1 parent 297d8f5 commit 32ba736
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 68 deletions.
3 changes: 3 additions & 0 deletions src/hardware/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
67 changes: 0 additions & 67 deletions src/messaging/voicemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 3 additions & 1 deletion tests/test_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 32ba736

Please sign in to comment.