@@ -631,38 +631,26 @@ def test_length_and_hash_validation(self):
631
631
# test exceptions
632
632
expected_length = snapshot_metafile .length
633
633
snapshot_metafile .length = 2345
634
- self .assertRaises (
635
- exceptions .LengthOrHashMismatchError ,
636
- snapshot_metafile .verify_length_and_hashes ,
637
- data ,
638
- )
634
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
635
+ snapshot_metafile .verify_length_and_hashes (data )
639
636
640
637
snapshot_metafile .length = expected_length
641
638
snapshot_metafile .hashes = {"sha256" : "incorrecthash" }
642
- self .assertRaises (
643
- exceptions .LengthOrHashMismatchError ,
644
- snapshot_metafile .verify_length_and_hashes ,
645
- data ,
646
- )
639
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
640
+ snapshot_metafile .verify_length_and_hashes (data )
647
641
648
642
snapshot_metafile .hashes = {
649
643
"unsupported-alg" : "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
650
644
}
651
- self .assertRaises (
652
- exceptions .LengthOrHashMismatchError ,
653
- snapshot_metafile .verify_length_and_hashes ,
654
- data ,
655
- )
645
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
646
+ snapshot_metafile .verify_length_and_hashes (data )
656
647
657
648
# Test wrong algorithm format (sslib.FormatError)
658
649
snapshot_metafile .hashes = {
659
650
256 : "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
660
651
}
661
- self .assertRaises (
662
- exceptions .LengthOrHashMismatchError ,
663
- snapshot_metafile .verify_length_and_hashes ,
664
- data ,
665
- )
652
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
653
+ snapshot_metafile .verify_length_and_hashes (data )
666
654
667
655
# test optional length and hashes
668
656
snapshot_metafile .length = None
@@ -681,19 +669,13 @@ def test_length_and_hash_validation(self):
681
669
# test exceptions
682
670
expected_length = file1_targetfile .length
683
671
file1_targetfile .length = 2345
684
- self .assertRaises (
685
- exceptions .LengthOrHashMismatchError ,
686
- file1_targetfile .verify_length_and_hashes ,
687
- file1 ,
688
- )
672
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
673
+ file1_targetfile .verify_length_and_hashes (file1 )
689
674
690
675
file1_targetfile .length = expected_length
691
676
file1_targetfile .hashes = {"sha256" : "incorrecthash" }
692
- self .assertRaises (
693
- exceptions .LengthOrHashMismatchError ,
694
- file1_targetfile .verify_length_and_hashes ,
695
- file1 ,
696
- )
677
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
678
+ file1_targetfile .verify_length_and_hashes (file1 )
697
679
698
680
def test_targetfile_from_file (self ):
699
681
# Test with an existing file and valid hash algorithm
@@ -707,23 +689,15 @@ def test_targetfile_from_file(self):
707
689
708
690
# Test with a non-existing file
709
691
file_path = os .path .join (self .repo_dir , "targets" , "file123.txt" )
710
- self .assertRaises (
711
- FileNotFoundError ,
712
- TargetFile .from_file ,
713
- file_path ,
714
- file_path ,
715
- [sslib_hash .DEFAULT_HASH_ALGORITHM ],
716
- )
692
+ with self .assertRaises (FileNotFoundError ):
693
+ TargetFile .from_file (
694
+ file_path , file_path , [sslib_hash .DEFAULT_HASH_ALGORITHM ]
695
+ )
717
696
718
697
# Test with an unsupported algorithm
719
698
file_path = os .path .join (self .repo_dir , "targets" , "file1.txt" )
720
- self .assertRaises (
721
- exceptions .UnsupportedAlgorithmError ,
722
- TargetFile .from_file ,
723
- file_path ,
724
- file_path ,
725
- ["123" ],
726
- )
699
+ with self .assertRaises (exceptions .UnsupportedAlgorithmError ):
700
+ TargetFile .from_file (file_path , file_path , ["123" ])
727
701
728
702
def test_targetfile_from_data (self ):
729
703
data = b"Inline test content"
0 commit comments