Skip to content

Commit

Permalink
Add __eq__ method to SigMFFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Teque5 committed Jan 10, 2025
1 parent 2311513 commit eb32e02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sigmf/sigmffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ def __init__(self, metadata=None, data_file=None, global_info=None, skip_checksu
def __len__(self):
return self._memmap.shape[0]

def __eq__(self, other):
"""
Define equality between two `SigMFFile`s.
Rely on the checksum value in the metadata to decide whether `data_file` is the same since the path of the
dataset is immaterial to equivalency.
"""
if isinstance(other, SigMFFile):
return self._metadata == other._metadata
return False

def __next__(self):
"""get next batch of samples"""
if self.iter_position < len(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sigmffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def test_checksum(self):
with self.assertRaises(error.SigMFFileError):
_ = SigMFFile(bad_checksum_metadata, self.temp_path_data)

def test_equality(self):
"""Ensure __eq__ working as expected"""
other = SigMFFile(copy.deepcopy(TEST_METADATA))
self.assertEqual(self.sigmf_object, other)
# different after changing any part of metadata
other.add_annotation(start_index=0, metadata={"a": 0})
self.assertNotEqual(self.sigmf_object, other)


class TestAnnotationHandling(unittest.TestCase):
def test_get_annotations_with_index(self):
Expand Down

0 comments on commit eb32e02

Please sign in to comment.