Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'users/t-vali/light-temp-accel-sensors' into users/t-anm…
Browse files Browse the repository at this point in the history
…ah/sensor-integration
  • Loading branch information
andreamah committed Feb 11, 2020
2 parents 039e440 + b46af05 commit 900dbd9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/microbit/__model/accelerometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __get_accel(self, axis):

def __set_accel(self, axis, accel):
if accel < CONSTANTS.MIN_ACCELERATION or accel > CONSTANTS.MAX_ACCELERATION:
raise ValueError("")
raise ValueError(CONSTANTS.INVALID_ACCEL_ERR)
if axis == "x":
self.__x = accel
elif axis == "y":
Expand Down
2 changes: 1 addition & 1 deletion src/microbit/test/test_accelerometer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from unittest import mock

from ..__model import constants as CONSTANTS
from ..__model.accelerometer import Accelerometer
from ..__model import constants as CONSTANTS


class TestAccelerometer(object):
Expand Down
3 changes: 1 addition & 2 deletions src/microbit/test/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ def test_async_tests(self):
assert Image._Image__same_image(Image(STR_SIX), self.display._Display__image)

@pytest.mark.parametrize(
"light_level",
[CONSTANTS.MIN_LIGHT_LEVEL + 10, 100, CONSTANTS.MAX_LIGHT_LEVEL,],
"light_level", [CONSTANTS.MIN_LIGHT_LEVEL + 10, 100, CONSTANTS.MAX_LIGHT_LEVEL],
)
def test_light_level(self, light_level):
self.display._Display__set_light_level(light_level)
Expand Down
18 changes: 18 additions & 0 deletions src/microbit/test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,35 @@

class TestShim(object):
def test_sleep(self):
# Save pointer to function about to be mocked
real_function = MicrobitModel.sleep

milliseconds = 100
MicrobitModel.sleep = mock.Mock()
sleep(milliseconds)
MicrobitModel.sleep.assert_called_with(milliseconds)

# Restore original function
MicrobitModel.sleep = real_function

def test_running_time(self):
# Save pointer to function about to be mocked
real_function = MicrobitModel.running_time

MicrobitModel.running_time = mock.Mock()
running_time()
MicrobitModel.running_time.assert_called_once()

# Restore original function
MicrobitModel.running_time = real_function

def test_temperature(self):
# Save pointer to function about to be mocked
real_function = MicrobitModel.temperature

MicrobitModel.temperature = mock.Mock()
temperature()
MicrobitModel.temperature.asser_called_once()

# Restore original function
MicrobitModel.temperature = real_function
3 changes: 1 addition & 2 deletions src/microbit/test/test_microbit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
from unittest import mock
from ..__model.microbit_model import MicrobitModel
from ..__model import constants as CONSTANTS
from ..__model.microbit_model import MicrobitModel


class TestMicrobitModel(object):
Expand All @@ -21,7 +21,6 @@ def test_running_time(self):
mock_end_time = 300
self.__mb._MicrobitModel__start_time = mock_start_time
time.time = mock.MagicMock(return_value=mock_end_time)
print(time.time())
assert mock_end_time - mock_start_time == pytest.approx(
self.__mb.running_time()
)
Expand Down

0 comments on commit 900dbd9

Please sign in to comment.