File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -505,7 +505,7 @@ def calculate_hash(self):
505505 new_hash = sigmf_hash .calculate_sha512 (self .data_file , offset = self .data_offset , size = self .data_size_bytes )
506506 else :
507507 new_hash = sigmf_hash .calculate_sha512 (fileobj = self .data_buffer , offset = self .data_offset , size = self .data_size_bytes )
508- if old_hash :
508+ if old_hash is not None :
509509 if old_hash != new_hash :
510510 raise SigMFFileError ("Calculated file hash does not match associated metadata." )
511511
Original file line number Diff line number Diff line change 1616
1717import numpy as np
1818
19- from sigmf import sigmffile , utils
19+ from sigmf import error , sigmffile , utils
2020from sigmf .sigmffile import SigMFFile
2121
2222from .testdata import *
@@ -51,6 +51,14 @@ def test_iterator_basic(self):
5151 count += 1
5252 self .assertEqual (count , len (self .sigmf_object ))
5353
54+ def test_checksum (self ):
55+ """Ensure checksum fails when incorrect or empty string."""
56+ for new_checksum in ("" , "a" , 0 ):
57+ bad_checksum_metadata = copy .deepcopy (TEST_METADATA )
58+ bad_checksum_metadata [SigMFFile .GLOBAL_KEY ][SigMFFile .HASH_KEY ] = new_checksum
59+ with self .assertRaises (error .SigMFFileError ):
60+ _ = SigMFFile (bad_checksum_metadata , self .temp_path_data )
61+
5462
5563class TestAnnotationHandling (unittest .TestCase ):
5664 def test_get_annotations_with_index (self ):
@@ -64,7 +72,7 @@ def test_get_annotations_with_index(self):
6472 [
6573 {SigMFFile .START_INDEX_KEY : 0 , SigMFFile .LENGTH_INDEX_KEY : 16 },
6674 {SigMFFile .START_INDEX_KEY : 1 },
67- ]
75+ ],
6876 )
6977
7078 def test__count_samples_from_annotation (self ):
You can’t perform that action at this time.
0 commit comments