Skip to content

Commit

Permalink
Automated autopep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitbot committed Aug 17, 2023
1 parent abe0ef2 commit 3ec5e8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion nanome/beta/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .redis_interface import PluginInstanceRedisInterface, StreamRedisInterface # noqa: E402
from .redis_interface import PluginInstanceRedisInterface, StreamRedisInterface # noqa: E402
7 changes: 4 additions & 3 deletions testing/unit/test_beta/test_plugin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_keep_alive(self) -> None:
@patch.object(PluginServer, "route_bytes", new_callable=AsyncMock)
def test_poll_nts(self, route_bytes_mock):
self.server.nts_reader = MagicMock()

packed_packet = self.packet.pack()
header_fut = asyncio.Future()
header_fut.set_result(packed_packet[:Packet.packet_header_length])
Expand Down Expand Up @@ -86,14 +86,15 @@ def test_connect_plugin(self, mock_header_unpack):
self.server.nts_writer.drain = AsyncMock()
self.server.nts_reader = MagicMock()
self.server.nts_reader.readexactly = AsyncMock()

mock_header_unpack.return_value = [0, 0, 0, "test_plugin_id", 0]

plugin_id = asyncio.run(self.server.connect_plugin("name", "description"))

self.assertEqual(plugin_id, "test_plugin_id")

# Add more test methods as necessary


if __name__ == "__main__":
unittest.main()
37 changes: 19 additions & 18 deletions testing/unit/test_beta/test_redis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from nanome.beta.redis_interface import StreamRedisInterface, PluginInstanceRedisInterface
from nanome.util import enums, Color


class TestStreamRedisInterface(unittest.TestCase):
def setUp(self):
self.mock_plugin_interface = Mock()
Expand Down Expand Up @@ -50,8 +51,8 @@ def test_rpc_request(self):
# You might need to expand on it depending on the specifics of your application.
function_name = 'request_complex_list'
with patch('json.dumps', return_value='json_string'), \
patch('time.time', side_effect=[0, 1, 2, 31]), \
patch.object(self.redis_interface, 'redis'):
patch('time.time', side_effect=[0, 1, 2, 31]), \
patch.object(self.redis_interface, 'redis'):
mock_pubsub = Mock()
mock_pubsub.get_message.return_value = {'type': 'message', 'data': b'[]'}
mock_pubsub.channels.keys.return_value = [b'channel']
Expand All @@ -61,7 +62,7 @@ def test_rpc_request(self):

# Verify interaction with Redis, etc.
self.redis_interface.redis.publish.assert_called_once_with('channel', 'json_string')

def test_request_complex_list(self):
fn_name = 'request_complex_list'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -70,7 +71,7 @@ def test_request_complex_list(self):
response = self.redis_interface.request_complex_list()
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_upload_shapes(self):
fn_name = 'upload_shapes'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -91,23 +92,23 @@ def test_stream_update(self):
response = self.redis_interface.stream_update(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_get_plugin_data(self):
fn_name = 'get_plugin_data'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
mock_rpc_request.return_value = {}
response = self.redis_interface.get_plugin_data()
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name)

def test_request_workspace(self):
fn_name = 'request_workspace'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
mock_rpc_request.return_value = [structure.Workspace()]
response = self.redis_interface.request_workspace()
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=[])

def test_request_complexes(self):
fn_name = 'request_complexes'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -117,7 +118,7 @@ def test_request_complexes(self):
response = self.redis_interface.request_complexes(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_update_structures_shallow(self):
fn_name = 'update_structures_shallow'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -127,7 +128,7 @@ def test_update_structures_shallow(self):
response = self.redis_interface.update_structures_shallow(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_update_structures_deep(self):
fn_name = 'update_structures_deep'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -137,7 +138,7 @@ def test_update_structures_deep(self):
response = self.redis_interface.update_structures_deep(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_update_workspace(self):
fn_name = 'update_workspace'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -157,7 +158,7 @@ def test_zoom_on_structures(self):
response = self.redis_interface.zoom_on_structures(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_center_on_structures(self):
fn_name = 'center_on_structures'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -167,7 +168,7 @@ def test_center_on_structures(self):
response = self.redis_interface.center_on_structures(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_add_to_workspace(self):
fn_name = 'add_to_workspace'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -177,7 +178,7 @@ def test_add_to_workspace(self):
response = self.redis_interface.add_to_workspace(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_add_bonds(self):
fn_name = 'add_bonds'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -187,7 +188,7 @@ def test_add_bonds(self):
response = self.redis_interface.add_bonds(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_open_url(self):
fn_name = 'open_url'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -197,7 +198,7 @@ def test_open_url(self):
response = self.redis_interface.open_url(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_request_presenter_info(self):
fn_name = 'request_presenter_info'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -206,7 +207,7 @@ def test_request_presenter_info(self):
response = self.redis_interface.request_presenter_info(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_request_controller_transforms(self):
fn_name = 'request_controller_transforms'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -215,7 +216,7 @@ def test_request_controller_transforms(self):
response = self.redis_interface.request_controller_transforms(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)

def test_apply_color_scheme(self):
fn_name = 'apply_color_scheme'
with patch.object(self.redis_interface, '_rpc_request') as mock_rpc_request:
Expand All @@ -226,4 +227,4 @@ def test_apply_color_scheme(self):
mock_rpc_request.return_value = []
response = self.redis_interface.apply_color_scheme(*args)
self.assertIsNotNone(response)
mock_rpc_request.assert_called_once_with(fn_name, args=args)
mock_rpc_request.assert_called_once_with(fn_name, args=args)
17 changes: 7 additions & 10 deletions testing/unit/test_beta/test_session_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def setUpClass(cls):
cls.version_table = json.load(f)
cls.plugin_id = 21
cls.session_id = 42


def setUp(self):
self.client = SessionClient(self.plugin_id, self.session_id, self.version_table)
self.client.writer = MagicMock()

# Mock request futs
self.request_id = 1
response_fut = asyncio.Future()
Expand All @@ -51,14 +50,14 @@ def test_update_menu(self):
expects_response = False
self.client.update_menu(menu, shallow=shallow)
mock_send_message.assert_called_once_with(Messages.menu_update, [menu, True], expects_response)

async def test_request_complex_list(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
expects_response = True
await self.client.request_complex_list()
mock_send_message.assert_called_once_with(Messages.complex_list_request, None, expects_response)

async def test_request_workspace(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
Expand All @@ -73,15 +72,15 @@ async def test_request_complexes(self):
expects_response = True
await self.client.request_complexes(comp_indices)
mock_send_message.assert_called_once_with(Messages.complexes_request, comp_indices, expects_response)

def test_update_workspace(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
workspace = structure.Workspace()
expects_response = False
self.client.update_workspace(workspace)
mock_send_message.assert_called_once_with(Messages.workspace_update, [workspace], expects_response)

async def test_send_notification(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
Expand All @@ -90,7 +89,7 @@ async def test_send_notification(self):
expects_response = False
await self.client.send_notification(notification_type, message)
mock_send_message.assert_called_once_with(Messages.notification_send, [notification_type, message], expects_response)

async def test_update_structures_deep(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
Expand All @@ -108,7 +107,7 @@ def test_update_structures_shallow(self):
expects_response = True
self.client.update_structures_shallow([atom, comp])
mock_send_message.assert_called_once_with(Messages.structures_shallow_update, [atom, comp], expects_response)

def test_zoom_on_structures(self):
with patch.object(self.client, '_send_message') as mock_send_message:
mock_send_message.return_value = self.request_id
Expand Down Expand Up @@ -156,5 +155,3 @@ def test_update_node(self):
expects_response = False
self.client.update_node(ln)
mock_send_message.assert_called_once_with(Messages.node_update, (ln,), expects_response)


0 comments on commit 3ec5e8e

Please sign in to comment.