Skip to content

Commit

Permalink
Remove mock dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Willemsen committed Jan 19, 2025
1 parent bd7fa78 commit 01d090a
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 46 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ doc = [

dev = [
"genie_python[plot,doc]",
"mock",
"parameterized",
"pyhamcrest",
"pytest",
Expand Down
7 changes: 2 additions & 5 deletions src/genie_python/genie_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ def end_run(
prepost: run pre and post commands [optional]
"""
if self.get_run_state() == "ENDING" and not immediate:
print(
"Please specify the 'immediate=True' flag to end a run " "while in the ENDING state"
)
print("Please specify the 'immediate=True' flag to end a run while in the ENDING state")
return

run_number = self.get_run_number()
Expand Down Expand Up @@ -601,8 +599,7 @@ def pause_run(self, immediate: bool = False, prepost: bool = True) -> None:
"""
if self.get_run_state() == "PAUSING" and not immediate:
print(
"Please specify the 'immediate=True' flag "
"to pause a run while in the PAUSING state"
"Please specify the 'immediate=True' flag to pause a run while in the PAUSING state"
)
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _asyncio_send_exceptions_to_logfile_only(loop, context):
exception = context.get("exception")
try:
GenieLogger().log_info_msg(
f"Caught (non-fatal) asyncio exception: " f"{exception.__class__.__name__}: {exception}"
f"Caught (non-fatal) asyncio exception: {exception.__class__.__name__}: {exception}"
)
except Exception:
# Exception while logging, ignore...
Expand Down
2 changes: 1 addition & 1 deletion tests/py3_test_genie_experimental_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import datetime
import unittest
from unittest.mock import call, patch

from hamcrest import assert_that, calling, raises
from mock import call, patch
from parameterized import parameterized

from genie_python.genie_experimental_data import (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_block_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import json
import unittest
from time import sleep
from unittest.mock import Mock, patch

from hamcrest import assert_that, has_key, has_length, is_, only_contains
from mock import Mock, patch

from genie_python.block_names import BlockNames, BlockNamesManager
from genie_python.channel_access_exceptions import UnableToConnectToPVException
Expand Down
2 changes: 1 addition & 1 deletion tests/test_genie.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import unittest
from datetime import datetime, timedelta
from io import StringIO
from unittest.mock import MagicMock, call, patch

from hamcrest import assert_that, contains_exactly, has_length, is_
from mock import MagicMock, call, patch

import genie_python.genie_api_setup
from genie_python import genie
Expand Down
3 changes: 1 addition & 2 deletions tests/test_genie_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from __future__ import absolute_import, print_function

import unittest

from mock import patch
from unittest.mock import patch

import genie_python.genie_alerts
import genie_python.genie_api_setup
Expand Down
2 changes: 1 addition & 1 deletion tests/test_genie_api_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import os
import unittest
from unittest.mock import patch

from hamcrest import assert_that, is_
from mock import patch
from parameterized import parameterized

import genie_python.genie_api_setup
Expand Down
3 changes: 1 addition & 2 deletions tests/test_genie_blockserver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from __future__ import absolute_import

import unittest

from mock import MagicMock, Mock
from unittest.mock import MagicMock, Mock

from genie_python.genie_blockserver import BlockServer
from genie_python.utilities import compress_and_hex
Expand Down
5 changes: 2 additions & 3 deletions tests/test_genie_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from __future__ import absolute_import

import unittest
from unittest.mock import MagicMock, patch

import numpy as np
from hamcrest import assert_that, calling, close_to, is_, raises
from mock import MagicMock, patch
from parameterized import parameterized_class

from genie_python.genie_change_cache import ChangeCache
Expand Down Expand Up @@ -295,8 +295,7 @@ def test_GIVEN_in_transition_WHEN_change_finish_called_THEN_value_error_with_cor

self.assertRaisesRegexp(
ValueError,
"Another DAE change operation is currently in progress - values will be "
"inconsistent",
"Another DAE change operation is currently in progress - values will be inconsistent",
self.dae.change_finish,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_genie_epics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from __future__ import absolute_import

import unittest
from unittest.mock import MagicMock, patch

from hamcrest import assert_that, calling, is_, raises
from mock import MagicMock, patch
from parameterized import parameterized

from genie_python.channel_access_exceptions import UnableToConnectToPVException
Expand Down
5 changes: 2 additions & 3 deletions tests/test_matplotlib_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
import unittest

import mock
from unittest.mock import MagicMock

from genie_python.matplotlib_backend import ibex_websocket_backend

Expand All @@ -22,7 +21,7 @@ class TestMatplotlibBackend(unittest.TestCase):
def test_WHEN_plotting_thread_fails_to_start_THEN_script_does_not_hang(self):
ibex_websocket_backend.WebAggApplication = ErroringWebAggApplication
ibex_websocket_backend.ibex_open_plot_window = lambda *a, **k: None
ibex_websocket_backend.Gcf = mock.MagicMock()
ibex_websocket_backend.Gcf = MagicMock()

start = time.time()
ibex_websocket_backend._BackendIbexWebAgg.show()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_mysql_abstraction_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

import unittest
from typing import List
from unittest.mock import patch
from unittest.mock import Mock, patch

from hamcrest import assert_that, equal_to
from mock import Mock
from mysql.connector.connection import MySQLConnection
from mysql.connector.cursor import MySQLCursor
from mysql.connector.errors import InternalError
Expand Down
33 changes: 14 additions & 19 deletions tests/test_script_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def assertSymbolsDefined(self, script_lines, expected_symbols):

def test_GIVEN_end_without_brackets_WHEN_check_THEN_error_message(self):
script_lines = [
"from genie_python import genie as g\n" "def test():\n",
"from genie_python import genie as g\ndef test():\n",
" g.begin()\n",
" g.end\n",
]
Expand All @@ -65,14 +65,14 @@ def test_GIVEN_end_without_brackets_WHEN_check_THEN_error_message(self):
)

def test_GIVEN_end_as_start_of_another_word_WHEN_check_THEN_no_error_message(self):
script_lines = ["from genie_python import genie as g\n" "def test():\n", " endAngle = 1"]
script_lines = ["from genie_python import genie as g\ndef test():\n", " endAngle = 1"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(errors, [])

def test_GIVEN_end_as_end_of_another_word_WHEN_check_THEN_no_error_message(self):
script_lines = [
"from genie_python import genie as g\n" "def test():\n",
"from genie_python import genie as g\ndef test():\n",
" angle_end = 1",
]

Expand All @@ -82,7 +82,7 @@ def test_GIVEN_end_as_end_of_another_word_WHEN_check_THEN_no_error_message(self)
self.assertEqual(errors, [])

def test_GIVEN_end_without_brackets_at_start_of_line_WHEN_check_THEN_error_message(self):
script_lines = ["from genie_python import genie as g\n" "def test():\n" " g.end"]
script_lines = ["from genie_python import genie as g\ndef test():\n g.end"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(
Expand All @@ -92,15 +92,15 @@ def test_GIVEN_end_without_brackets_at_start_of_line_WHEN_check_THEN_error_messa
def test_GIVEN_end_without_brackets_on_line_with_fn_with_brackets_WHEN_check_THEN_error_message(
self,
):
script_lines = ["from genie_python import genie as g\n" "g.begin(); g.end "]
script_lines = ["from genie_python import genie as g\ng.begin(); g.end "]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(
errors, ["W: 2: Statement seems to have no effect (pointless-statement)"]
)

def test_GIVEN_end_in_string_without_brackets_WHEN_check_THEN_no_message(self):
script_lines = ["def test():\n" ' " a string containing end "']
script_lines = ['def test():\n " a string containing end "']

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(errors, [])
Expand Down Expand Up @@ -202,9 +202,7 @@ def test_GIVEN_variable_assignment_with_g__WHEN_check_THEN_no_message(self):
self.assertEqual(errors, [])

def test_GIVEN_function_with_g_WHEN_check_THEN_warn_user(self):
script_lines = [
"from genie_python import genie as g\n" "def test():\n" " g.test_function()\n"
]
script_lines = ["from genie_python import genie as g\ndef test():\n g.test_function()\n"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(
Expand All @@ -214,7 +212,7 @@ def test_GIVEN_function_with_g_WHEN_check_THEN_warn_user(self):

def test_GIVEN_2_g_assignments_WHEN_check_THEN_warning_message(self):
script_lines = [
"from genie_python import genie as g\n" "def test():\n" " g=16\n",
"from genie_python import genie as g\ndef test():\n g=16\n",
" g=17",
]

Expand All @@ -224,9 +222,7 @@ def test_GIVEN_2_g_assignments_WHEN_check_THEN_warning_message(self):
)

def test_GIVEN_g_non_existing_command_WHEN_call_THEN_error_message(self):
script_lines = [
"from genie_python import genie as g\n" "def test():\n" " g.aitfor_time(10)"
]
script_lines = ["from genie_python import genie as g\ndef test():\n g.aitfor_time(10)"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(
Expand Down Expand Up @@ -539,8 +535,7 @@ def test_GIVEN_trying_to_index_var_of_optional_type_WHEN_pyright_script_checker_
):
script_lines = [
"from typing import Optional, List\n",
"def get_first_element(elements: Optional[List[int]]) -> int:\n"
" return elements[0]\n",
"def get_first_element(elements: Optional[List[int]]) -> int:\n return elements[0]\n",
]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
Expand All @@ -563,7 +558,7 @@ def test_GIVEN_trying_to_iterate_over_var_of_optional_type_WHEN_pyright_script_c
):
script_lines = [
"from typing import Optional, List\n",
"def iter_elements(elements: Optional[List[int]]):\n" " for element in elements:\n",
"def iter_elements(elements: Optional[List[int]]):\n for element in elements:\n",
" pass\n",
]

Expand All @@ -573,23 +568,23 @@ def test_GIVEN_trying_to_iterate_over_var_of_optional_type_WHEN_pyright_script_c
def test_GIVEN_trying_to_define_function_with_none_type_args_type_WHEN_pyright_script_checker_called_THEN_no_error(
self,
):
script_lines = ["def none_func(arg: int = None):\n" " print(arg)\n"]
script_lines = ["def none_func(arg: int = None):\n print(arg)\n"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(errors, [])

def test_GIVEN_trying_to_use_optional_operand__WHEN_pyright_script_checker_called_THEN_no_error(
self,
):
script_lines = ["def none_func(arg1: int, arg2: int = None):\n" " print(arg2 + arg1)\n"]
script_lines = ["def none_func(arg1: int, arg2: int = None):\n print(arg2 + arg1)\n"]

with CreateTempScriptAndReturnErrors(self.checker, self.machine, script_lines) as errors:
self.assertEqual(errors, [])

def test_GIVEN_trying_to_use_undefined_variable_WHEN_pyright_script_checker_called_THEN_no_error(
self,
):
script_lines = ["def func():\n" " print(arg)\n"]
script_lines = ["def func():\n print(arg)\n"]

with CreateTempScriptAndReturnErrors(
self.checker, self.machine, script_lines, no_pylint=True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import unittest
from collections import OrderedDict
from datetime import datetime
from unittest.mock import patch

from mock import patch
from parameterized import parameterized

from genie_python import genie
Expand Down
3 changes: 1 addition & 2 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import json
import unittest

from mock import Mock
from unittest.mock import Mock

from genie_python.utilities import (
EnvironmentDetails,
Expand Down

0 comments on commit 01d090a

Please sign in to comment.