Skip to content

Commit

Permalink
Moved inidicators unit test to test_indicators.py
Browse files Browse the repository at this point in the history
- Re: #67
  • Loading branch information
emxsys committed Aug 19, 2020
1 parent 42fe487 commit 176fc55
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/hardware/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,56 +286,3 @@ def set_char_layout(self, char, layout):
self._layouts[char] = layout


def test():
""" Unit Tests """
import os

print("*** Running Indicator Unit Tests ***")

try:
print("[Constructing Indicators]")
ring = RingIndicator()
approved = ApprovedIndicator()
blocked = BlockedIndicator()
message = MessageIndicator()

print("[Visual Tests]")

print("Turning on all LEDs for 5 seconds...")
ring.turn_on()
approved.turn_on()
blocked.turn_on()
message.turn_on()
time.sleep(5)

print("Blinking on all LEDs for 5 seconds...")
ring.blink()
time.sleep(.1)
approved.blink()
time.sleep(.1)
blocked.blink()
time.sleep(.1)
message.blink()
time.sleep(5)

print("Turning off all LEDs...")
ring.turn_off()
approved.turn_off()
blocked.turn_off()
message.turn_off()
time.sleep(5)

except Exception as e:
print("*** Unit test FAILED ***")
pprint(e)
return 1

print("*** Unit tests PASSED ***")
return 0


if __name__ == '__main__':
""" Run the Unit Tests """
import sys
# Run the tests
sys.exit(test())
72 changes: 72 additions & 0 deletions tests/test_indicators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# test_indicators.py
#
# Copyright 2020 Bruce Schubert <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import sys
import time
from pprint import pprint

import pytest

from src.hardware.indicators import RingIndicator, ApprovedIndicator, BlockedIndicator, MessageIndicator

def test_multiple():

ring = RingIndicator()
approved = ApprovedIndicator()
blocked = BlockedIndicator()
message = MessageIndicator()

print("[Visual Tests]")

print("Turning on all LEDs for 5 seconds...")
ring.turn_on()
approved.turn_on()
blocked.turn_on()
message.turn_on()
time.sleep(5)

print("Blinking on all LEDs for 5 seconds...")
ring.blink()
time.sleep(.1)
approved.blink()
time.sleep(.1)
blocked.blink()
time.sleep(.1)
message.blink()
time.sleep(5)

print("Turning off all LEDs...")
ring.turn_off()
approved.turn_off()
blocked.turn_off()
message.turn_off()
time.sleep(5)

# Release GPIO pins
ring.close()
approved.close()
blocked.close()
message.close()

0 comments on commit 176fc55

Please sign in to comment.