Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SensePi Tests #567

Merged
merged 7 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hardware/SensorPi/sense_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Conditional import for sense hat and emulator
try:
if not os.environ["EMULATE_SENSE_HAT"]:
if not os.environ.get("EMULATE_SENSE_HAT"):
from sense_hat import SenseHat
else:
raise ImportError("Import emulator")
Expand Down
16 changes: 16 additions & 0 deletions hardware/tests/test_comm_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ def test_post_radio(self, mock_transceiver=mock.MagicMock()):
url = f"http://localhost:{self.mock_server_port}/"
requests.post(url, data={"key": "value"}, headers={"Content-Length": "15"})
mock_transceiver.return_value.send.assert_called()

@mock.patch("builtins.print")
@mock.patch("hardware.CommunicationsPi.comm_pi.Transceiver")
def test_post_radio_with_internet(
self, mock_transceiver=mock.MagicMock(), mock_print=mock.MagicMock()
):
with patch.dict(
os.environ, {"ENABLE_INTERNET_TRANSMISSION": "True"},
):
mock_transceiver.return_value.send = mock.MagicMock()
url = f"http://localhost:{self.mock_server_port}/"
requests.post(url, data={"key": "value"}, headers={"Content-Length": "15"})
mock_transceiver.return_value.send.assert_not_called()
self.assertTrue(
mock_print.mock_calls == [mock.call("transmit via internet")]
)
16 changes: 16 additions & 0 deletions hardware/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ def test_info_message(self):

capture.check(("test_logger", "INFO", "test message"))

@mock.patch("builtins.print")
def test_info_message_with_print(self, mock_print=mock.MagicMock()):
"""
Tests the .info method
"""
with mock.patch.dict(
os.environ, {"LOG_DIRECTORY": self.temp_dir.path, "SHOW_LOGS": "True"}
):
with LogCapture() as capture:
logger = Logger(name="test_logger", filename="logger.txt")
logger.info("test message")

self.assertTrue(mock_print.mock_calls == [mock.call("test message")])

capture.check(("test_logger", "INFO", "test message"))

def test_message_failure(self):
"""
makes sure that nothing is logged during initialization
Expand Down