• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.25
/spinnman/messages/scp/abstract_messages/bmp_response.py
1
# Copyright (c) 2015 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from logging import getLogger
1✔
16
from typing import Generic, Optional, TypeVar, final
1✔
17
from spinn_utilities.abstract_base import abstractmethod
1✔
18
from spinn_utilities.log import FormatAdapter
1✔
19
from spinn_utilities.overrides import overrides
1✔
20
from spinnman.messages.scp.enums import SCPCommand, SCPResult
1✔
21
from spinnman.exceptions import SpinnmanUnexpectedResponseCodeException
1✔
22
from .scp_response import AbstractSCPResponse
1✔
23

24
logger = FormatAdapter(getLogger(__name__))
1✔
25
#: :meta private:
26
T = TypeVar("T")
1✔
27

28

29
class BMPResponse(AbstractSCPResponse, Generic[T]):
1✔
30
    """
31
    Represents an SCP response that's tailored for the BMP connection.
32
    """
33
    __slots__ = ("__operation", "__command", "__value")
1✔
34

35
    def __init__(self, operation: str, command: SCPCommand):
1✔
36
        super().__init__()
×
37
        self.__operation = operation
×
38
        self.__command = command
×
39
        self.__value: Optional[T] = None
×
40

41
    @property
1✔
42
    def _value(self) -> T:
1✔
43
        """
44
        The value parsed from the message. Subclasses have to expose this to
45
        make the parsed payload visible.
46
        """
47
        if self.__value is None:
×
48
            raise ValueError("no value parsed yet")
×
49
        return self.__value
×
50

51
    @overrides(AbstractSCPResponse.read_data_bytestring)
1✔
52
    def read_data_bytestring(self, data: bytes, offset: int):
1✔
53
        result = self.scp_response_header.result
×
54
        if result != SCPResult.RC_OK:
×
55
            raise SpinnmanUnexpectedResponseCodeException(
×
56
                self.__operation, self.__command.name, result.name)
57
        self.__value = self._parse_payload(data, offset)
×
58

59
    @abstractmethod
1✔
60
    def _parse_payload(self, data: bytes, offset: int) -> T:
1✔
61
        """
62
        Parse the payload of the message. The header will already be OK.
63

64
        :param data:
65
            The full content of the message
66
        :param offset:
67
            Where the payload should start in the message
68
        :return:
69
            The parsed payload
70
        """
71
        raise NotImplementedError
72

73

74
@final
1✔
75
class BMPOKResponse(BMPResponse[None]):
1✔
76
    """
77
    A BMP response without payload to parse.
78
    """
79
    @abstractmethod
1✔
80
    def _parse_payload(self, data: bytes, offset: int) -> None:
1✔
81
        if len(data) != offset:
×
82
            logger.warning("response message with unexpected extra {} bytes",
×
83
                           len(data) - offset)
84
        return None
×
85

86
    @property
1✔
87
    def _value(self) -> None:
1✔
88
        # Override to remove None check; this is always None
89
        return None
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc