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

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandy Liu committed Feb 11, 2020
1 parent 933b4ad commit b46af05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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
1 change: 0 additions & 1 deletion src/microbit/test/test_microbit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 b46af05

Please sign in to comment.