Skip to content

Commit

Permalink
Fix linting and spelling (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Jun 10, 2020
1 parent 7e5e618 commit 6617f91
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 76 deletions.
6 changes: 3 additions & 3 deletions leicacam/async_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ async def send(self, commands):
async def receive(self):
"""Receive message from socket interface as list of OrderedDict."""
try:
incomming = await self.reader.read(self.buffer_size)
incoming = await self.reader.read(self.buffer_size)
except OSError:
return []

return _parse_receive(incomming)
return _parse_receive(incoming)

async def wait_for(self, cmd, value=None, timeout=60):
"""Hang until command is received.
Expand All @@ -72,7 +72,7 @@ async def wait_for(self, cmd, value=None, timeout=60):
----------
cmd : string
Command to wait for in bytestring from microscope CAM interface. If
``value`` is falsey, value of received command does not matter.
``value`` is falsy, value of received command does not matter.
value : string
Wait until ``cmd:value`` is received.
timeout : int
Expand Down
83 changes: 14 additions & 69 deletions leicacam/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def debug(msg):
class BaseCAM:
"""Base driver for LASAF Computer Assisted Microscopy."""

# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-instance-attributes, too-few-public-methods

def __init__(self, host="127.0.0.1", port=8895):
"""Set up instance."""
Expand All @@ -59,62 +59,7 @@ def __init__(self, host="127.0.0.1", port=8895):
self.prefix = [("cli", "python-leicacam"), ("app", "matrix")]
self.prefix_bytes = b"/cli:python-leicacam /app:matrix "
self.buffer_size = 1024
self.delay = 0.1 # poll every 100ms when waiting for incomming

def send(self, commands):
"""Send commands to LASAF through CAM-socket.
Parameters
----------
commands : list of tuples or bytes string
Commands as a list of tuples or a bytes string. cam.prefix is
allways prepended before sending.
Returns
-------
int
Bytes sent.
Example
-------
::
>>> # send list of tuples
>>> cam.send([('cmd', 'enableall'), ('value', 'true')])
>>> # send bytes string
>>> cam.send(b'/cmd:enableall /value:true')
"""
raise NotImplementedError

def receive(self):
"""Receive message from socket interface as list of OrderedDict."""
raise NotImplementedError

def wait_for(self, cmd, value=None, timeout=60):
"""Hang until command is received.
If value is supplied, it will hang until ``cmd:value`` is received.
Parameters
----------
cmd : string
Command to wait for in bytestring from microscope CAM interface. If
``value`` is falsey, value of received command does not matter.
value : string
Wait until ``cmd:value`` is received.
timeout : int
Minutes to wait for command. If timeout is reached, an empty
OrderedDict will be returned.
Returns
-------
collections.OrderedDict
Last received messsage or empty message if timeout is reached.
"""
raise NotImplementedError
self.delay = 0.1 # poll every 100ms when waiting for incoming

def _prepare_send(self, commands):
"""Prepare message to be sent.
Expand All @@ -139,25 +84,25 @@ def _prepare_send(self, commands):
return msg


def _parse_receive(incomming):
def _parse_receive(incoming):
"""Parse received response.
Parameters
----------
incomming : bytes string
Incomming bytes from socket server.
incoming : bytes string
incoming bytes from socket server.
Returns
-------
list of OrderedDict
Received message as a list of OrderedDict.
"""
debug(b"< " + incomming)
debug(b"< " + incoming)
# first split on terminating null byte
incomming = incomming.split(b"\x00")
incoming = incoming.split(b"\x00")
msgs = []
for msg in incomming:
for msg in incoming:
# then split on line ending
split_msg = msg.splitlines()
msgs.extend(split_msg)
Expand All @@ -184,8 +129,8 @@ def connect(self):
self.welcome_msg = self.socket.recv(self.buffer_size) # receive welcome message

def flush(self):
"""Flush incomming socket messages."""
debug("flushing incomming socket messages")
"""Flush incoming socket messages."""
debug("flushing incoming socket messages")
try:
while True:
msg = self.socket.recv(self.buffer_size)
Expand Down Expand Up @@ -225,11 +170,11 @@ def send(self, commands):
def receive(self):
"""Receive message from socket interface as list of OrderedDict."""
try:
incomming = self.socket.recv(self.buffer_size)
incoming = self.socket.recv(self.buffer_size)
except socket.error:
return []

return _parse_receive(incomming)
return _parse_receive(incoming)

def wait_for(self, cmd, value=None, timeout=60):
"""Hang until command is received.
Expand All @@ -240,7 +185,7 @@ def wait_for(self, cmd, value=None, timeout=60):
----------
cmd : string
Command to wait for in bytestring from microscope CAM interface. If
``value`` is falsey, value of received command does not matter.
``value`` is falsy, value of received command does not matter.
value : string
Wait until ``cmd:value`` is received.
timeout : int
Expand Down Expand Up @@ -488,7 +433,7 @@ def check_messages(msgs, cmd, value=None):
----------
cmd : string
Command to check for in bytestring from microscope CAM interface. If
``value`` is falsey, value of received command does not matter.
``value`` is falsy, value of received command does not matter.
value : string
Check if ``cmd:value`` is received.
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def validate_version():
"""Validate version before release."""
import leicacam
import leicacam # pylint: disable=import-outside-toplevel

version_string = leicacam.__version__
versions = version_string.split(".", 3)
Expand Down
4 changes: 2 additions & 2 deletions test/test_async_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def mock_connection():

@pytest.fixture
def mock_writer(mock_connection):
"""Mock an asycio connection writer."""
"""Mock an asyncio connection writer."""
writer = Mock()
writer.write = mock_connection.write
writer.drain = CoroutineMock()
Expand All @@ -42,7 +42,7 @@ def mock_writer(mock_connection):

@pytest.fixture
def mock_reader(mock_connection):
"""Mock an asycio connection reader."""
"""Mock an asyncio connection reader."""
reader = Mock()
reader.read = mock_connection.read
reader.read_line = CoroutineMock()
Expand Down
2 changes: 1 addition & 1 deletion test/test_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def close(self):


# TEST
# key (here cli) overrided if defined several times
# key (here cli) overridden if defined several times
# prefix added
# types (integer, float) should be converted to strings

Expand Down

0 comments on commit 6617f91

Please sign in to comment.