Skip to content

Commit

Permalink
made ruff compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Feb 29, 2024
1 parent edc5af9 commit 71bd847
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/pandablocks_ioc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .ioc import create_softioc

from importlib.metadata import version # noqa

from .ioc import create_softioc

__version__ = version("pandablocks-ioc")
del version

Expand Down
8 changes: 0 additions & 8 deletions src/pandablocks_ioc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from argparse import ArgumentParser

from . import __version__

import logging

import click
Expand Down Expand Up @@ -32,10 +28,6 @@ def cli(ctx, log_level: str):
if ctx.invoked_subcommand is None:
click.echo(cli.get_help(ctx))

parser = ArgumentParser()
parser.add_argument("-v", "--version", action="version", version=__version__)
args = parser.parse_args(args)


@cli.command()
@click.argument("host")
Expand Down
6 changes: 3 additions & 3 deletions src/pandablocks_ioc/_pvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def add_data_capture_pvi_info(
component = SignalRW(
name=epics_to_pvi_name(data_capture_record_name),
pv=data_capture_record_name,
widget=ButtonPanel(actions=dict(Start="1", Stop="0")),
widget=ButtonPanel(actions={"Start": "1", "Stop": "0"}),
read_widget=LED(),
)
add_pvi_info_to_record(data_capture_pvi_record, data_capture_record_name, "rw")
Expand All @@ -97,7 +97,7 @@ def add_pcap_arm_pvi_info(group: PviGroup, pcap_arm_pvi_record: RecordWrapper):
component = SignalRW(
name=epics_to_pvi_name(pcap_arm_record_name),
pv=pcap_arm_record_name,
widget=ButtonPanel(actions=dict(Arm="1", Disarm="0")),
widget=ButtonPanel(actions={"Arm": "1", "Disarm": "0"}),
read_widget=LED(),
)
add_pvi_info_to_record(pcap_arm_pvi_record, pcap_arm_record_name, "rw")
Expand All @@ -123,7 +123,7 @@ def add_automatic_pvi_info(
component = SignalRW(
name=pvi_name,
pv=record_name,
widget=ButtonPanel(actions=dict(Arm="1", Disarm="0")),
widget=ButtonPanel(actions={"Arm": "1", "Disarm": "0"}),
read_widget=LED(),
)
access = "rw"
Expand Down
5 changes: 4 additions & 1 deletion src/pandablocks_ioc/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def _create_record_info(
record_creation_func: Callable,
data_type_func: Callable,
group: PviGroup,
labels: List[str] = [],
labels: Optional[List[str]] = None,
*args,
**kwargs,
) -> RecordInfo:
Expand Down Expand Up @@ -605,6 +605,9 @@ def _create_record_info(
RecordInfo: Class containing the created record and anything needed for
updating the record.
"""
if labels is None:
labels = []

extra_kwargs: Dict[str, Any] = {}
assert (
record_creation_func in self._builder_methods
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from multiprocessing.connection import Connection
from pathlib import Path
from typing import Any, Generator, Iterator, Optional, Tuple, TypeVar
from unittest.mock import MagicMock, patch
from uuid import uuid4

import pytest
import pytest_asyncio
from aioca import purge_channel_caches
from mock import MagicMock, patch
from pandablocks.commands import (
Arm,
ChangeGroup,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/panda_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def table_data_2() -> List[str]:

@pytest.fixture
def table_unpacked_data(
table_fields: Dict[str, TableFieldDetails]
table_fields: Dict[str, TableFieldDetails],
) -> OrderedDict[EpicsName, ndarray]:
"""The unpacked equivalent of table_data"""
array_values: List[ndarray] = [
Expand Down
1 change: 1 addition & 0 deletions tests/test-bobfiles/regenerate_test_bobfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from time import sleep

import pytest

from fixtures.mocked_panda import (
BOBFILE_DIR,
TEST_PREFIX,
Expand Down
47 changes: 25 additions & 22 deletions tests/test_hdf_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
import pytest
import pytest_asyncio
from aioca import DBR_CHAR_STR, CANothing, caget, caput
from fixtures.mocked_panda import (
TIMEOUT,
MockedAsyncioClient,
Rows,
append_random_uppercase,
custom_logger,
enable_codecov_multiprocess,
get_multiprocessing_context,
select_and_recv,
)
from mock.mock import AsyncMock, MagicMock, patch
from pandablocks.asyncio import AsyncioClient
from pandablocks.responses import (
Expand All @@ -35,6 +25,16 @@
)
from softioc import asyncio_dispatcher, builder, softioc

from fixtures.mocked_panda import (
TIMEOUT,
MockedAsyncioClient,
Rows,
append_random_uppercase,
custom_logger,
enable_codecov_multiprocess,
get_multiprocessing_context,
select_and_recv,
)
from pandablocks_ioc._hdf_ioc import (
CaptureMode,
HDF5Buffer,
Expand Down Expand Up @@ -676,11 +676,14 @@ def test_hdf_buffer_forever(differently_sized_framedata, tmp_path):
assert buffer.finish_capturing

assert len(frames_written_to_file) == 14
sum(
len(frame.data)
for frame in frames_written_to_file
if isinstance(frame, FrameData)
) == 116
assert (
sum(
len(frame.data)
for frame in frames_written_to_file
if isinstance(frame, FrameData)
)
== 116
)


def test_hdf_buffer_last_n(differently_sized_framedata, tmp_path):
Expand Down Expand Up @@ -780,12 +783,12 @@ def test_hdf_buffer_last_n_large_data(tmp_path):
large_data = [
ReadyData(),
StartData([], 0, "Scaled", "Framed", 52),
FrameData(numpy.zeros((25000))),
FrameData(numpy.zeros((25000))),
FrameData(numpy.zeros((25000))),
FrameData(numpy.zeros((25000))),
FrameData(numpy.zeros((25000))),
FrameData(numpy.append(numpy.zeros((15000)), numpy.arange(1, 10001))),
FrameData(numpy.zeros(25000)),
FrameData(numpy.zeros(25000)),
FrameData(numpy.zeros(25000)),
FrameData(numpy.zeros(25000)),
FrameData(numpy.zeros(25000)),
FrameData(numpy.append(numpy.zeros(15000), numpy.arange(1, 10001))),
EndData(150000, EndReason.OK),
]

Expand All @@ -797,7 +800,7 @@ def test_hdf_buffer_last_n_large_data(tmp_path):

expected_output = [
StartData([], 0, "Scaled", "Framed", 52),
FrameData(numpy.append(numpy.zeros((15000)), numpy.arange(1, 10001))),
FrameData(numpy.append(numpy.zeros(15000), numpy.arange(1, 10001))),
EndData(150000, EndReason.OK),
]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import logging
from pathlib import Path
from typing import Dict, Tuple
from unittest.mock import AsyncMock, patch

import pytest
from fixtures.mocked_panda import TEST_PREFIX
from mock import AsyncMock, patch
from mock.mock import MagicMock, call
from pandablocks.asyncio import AsyncioClient
from pandablocks.commands import GetLine, Put
Expand All @@ -26,6 +25,7 @@
)
from softioc import builder, fields

from fixtures.mocked_panda import TEST_PREFIX
from pandablocks_ioc._pvi import PviGroup
from pandablocks_ioc._types import (
ONAM_STR,
Expand Down
20 changes: 10 additions & 10 deletions tests/test_ioc_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
import numpy
import pytest
from aioca import DBR_CHAR_STR, CANothing, caget, camonitor, caput
from fixtures.mocked_panda import (
BOBFILE_DIR,
TEST_PREFIX,
TIMEOUT,
MockedAsyncioClient,
ResponseHandler,
command_to_key,
multiprocessing_queue_to_list,
)
from numpy import ndarray
from pandablocks.commands import Arm, Disarm, Put
from pandablocks.responses import (
Expand All @@ -24,6 +15,15 @@
)
from pvi.device import SignalX

from fixtures.mocked_panda import (
BOBFILE_DIR,
TEST_PREFIX,
TIMEOUT,
MockedAsyncioClient,
ResponseHandler,
command_to_key,
multiprocessing_queue_to_list,
)
from pandablocks_ioc._pvi import Pvi, PviGroup
from pandablocks_ioc._types import EpicsName
from pandablocks_ioc.ioc import _BlockAndFieldInfo, introspect_panda
Expand Down Expand Up @@ -115,7 +115,7 @@ async def test_create_softioc_system(
pcap1_label = await caget(test_prefix + ":PCAP:LABEL")
assert numpy.array_equal(
pcap1_label,
numpy.array(list("PcapMetadataLabel".encode() + b"\0"), dtype=numpy.uint8),
numpy.array(list(b"PcapMetadataLabel" + b"\0"), dtype=numpy.uint8),
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_pvaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import OrderedDict

import numpy
from fixtures.mocked_panda import TIMEOUT
from numpy import ndarray
from p4p.client.asyncio import Context

from fixtures.mocked_panda import TIMEOUT
from pandablocks_ioc._types import EpicsName


Expand Down
14 changes: 7 additions & 7 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import asyncio
import typing
from typing import Dict, List
from unittest.mock import AsyncMock

import numpy
import numpy.testing
import pytest
from aioca import caget, camonitor, caput
from fixtures.mocked_panda import TIMEOUT, command_to_key, multiprocessing_queue_to_list
from mock import AsyncMock
from mock.mock import MagicMock, PropertyMock
from numpy import ndarray
from pandablocks.asyncio import AsyncioClient
from pandablocks.commands import GetMultiline, Put
from pandablocks.responses import TableFieldDetails, TableFieldInfo
from softioc import alarm

from fixtures.mocked_panda import TIMEOUT, command_to_key, multiprocessing_queue_to_list
from pandablocks_ioc._tables import (
TableFieldRecordContainer,
TableModeEnum,
Expand Down Expand Up @@ -363,9 +363,9 @@ async def test_table_updater_update_mode_submit_exception_data_error(
assert isinstance(table_updater.client.send, AsyncMock)
table_updater.client.send.side_effect = Exception("Mocked exception")

table_updater.all_values_dict[EpicsName(EPICS_FORMAT_TABLE_NAME)] = (
InErrorException("Mocked in error exception")
)
table_updater.all_values_dict[
EpicsName(EPICS_FORMAT_TABLE_NAME)
] = InErrorException("Mocked in error exception")

await table_updater.update_mode(TableModeEnum.SUBMIT.value)

Expand Down Expand Up @@ -433,7 +433,7 @@ async def test_table_updater_update_mode_other(
table_updater.client.send.assert_not_called()

# Confirm each record was not called
for field_name, data in table_unpacked_data.items():
for field_name, _ in table_unpacked_data.items():
record_info = table_updater.table_fields_records[field_name].record_info
assert record_info

Expand Down Expand Up @@ -479,7 +479,7 @@ def test_table_updater_update_table_not_view(
table_updater.mode_record_info.record.get.assert_called_once()

# Confirm the records were not called
for field_name, data in table_unpacked_data.items():
for field_name, _ in table_unpacked_data.items():
# Note table_unpacked_data is deliberately in a different order to the sorted
# data, hence use this lookup mechanism instead
record_info = table_updater.table_fields_records[field_name].record_info
Expand Down

0 comments on commit 71bd847

Please sign in to comment.