Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity ID TLV update #80

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

# [unreleased]

# [v0.24.2] 2024-09-09

## Fixed

- Custom `EntityIdTlv` `__eq__` implementation which only compares the numerical value
of the entity ID TLVs

## Added

- `AbstractTlvBase` `__repr__` implementation

# [v0.24.1] 2024-04-23

## Reverted
Expand Down
7 changes: 6 additions & 1 deletion spacepackets/cfdp/tlv/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
def value(self) -> bytes:
pass

def __eq__(self, other: AbstractTlvBase):
def __repr__(self) -> str:
return f"Tlv(tlv_type={self.tlv_type!r}, value=0x[{self.value.hex(sep=',')}])"

def __eq__(self, other: object):
if not isinstance(other, AbstractTlvBase):
return False

Check warning on line 33 in spacepackets/cfdp/tlv/base.py

View check run for this annotation

Codecov / codecov/patch

spacepackets/cfdp/tlv/base.py#L33

Added line #L33 was not covered by tests
return self.tlv_type == other.tlv_type and self.value == other.value

def check_type(self, tlv_type: TlvType):
Expand Down
12 changes: 12 additions & 0 deletions spacepackets/cfdp/tlv/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from spacepackets.exceptions import BytesTooShortError
from spacepackets.cfdp.exceptions import TlvTypeMissmatch
from spacepackets.util import UnsignedByteField


def map_enum_status_code_to_int(status_code: FilestoreResponseStatusCode) -> int:
Expand Down Expand Up @@ -502,6 +503,9 @@


class EntityIdTlv(AbstractTlvBase):
"""This helper class has a :py:meth:`__eq__` implementation which only compares the numerical value
of the entity IDs"""

TLV_TYPE = TlvType.ENTITY_ID

def __init__(self, entity_id: bytes):
Expand Down Expand Up @@ -540,3 +544,11 @@
entity_id_tlv = cls.__empty()
entity_id_tlv.tlv = cfdp_tlv
return entity_id_tlv

def __eq__(self, other: AbstractTlvBase) -> bool:
"""Custom implementation which only compares the numerical value of the entity IDs"""
if not isinstance(other, EntityIdTlv):
return False

Check warning on line 551 in spacepackets/cfdp/tlv/tlv.py

View check run for this annotation

Codecov / codecov/patch

spacepackets/cfdp/tlv/tlv.py#L551

Added line #L551 was not covered by tests
own_id = UnsignedByteField.from_bytes(self.value)
other_id = UnsignedByteField.from_bytes(other.value)
return own_id.value == other_id.value
11 changes: 11 additions & 0 deletions tests/cfdp/tlvslvs/test_entity_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ def test_invalid_type(self):
entity_id_tlv_tlv.tlv_type = TlvType.FILESTORE_REQUEST
with self.assertRaises(TlvTypeMissmatch):
EntityIdTlv.from_tlv(cfdp_tlv=entity_id_tlv_tlv)

def test_custom_eq(self):
self.entity_id_tlv = EntityIdTlv(entity_id=bytes([0x00, 0x01]))
self.entity_id_tlv_same = EntityIdTlv(entity_id=bytes([0x01]))
self.assertEqual(self.entity_id_tlv, self.entity_id_tlv_same)

def test_repr(self):
repr_str = repr(self.entity_id_tlv)
self.assertEqual(
repr_str, f"Tlv(tlv_type={TlvType.ENTITY_ID!r}, value=0x[00,01,02,03])"
)
Loading