@@ -613,38 +613,26 @@ def test_length_and_hash_validation(self):
613
613
# test exceptions
614
614
expected_length = snapshot_metafile .length
615
615
snapshot_metafile .length = 2345
616
- self .assertRaises (
617
- exceptions .LengthOrHashMismatchError ,
618
- snapshot_metafile .verify_length_and_hashes ,
619
- data ,
620
- )
616
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
617
+ snapshot_metafile .verify_length_and_hashes (data )
621
618
622
619
snapshot_metafile .length = expected_length
623
620
snapshot_metafile .hashes = {"sha256" : "incorrecthash" }
624
- self .assertRaises (
625
- exceptions .LengthOrHashMismatchError ,
626
- snapshot_metafile .verify_length_and_hashes ,
627
- data ,
628
- )
621
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
622
+ snapshot_metafile .verify_length_and_hashes (data )
629
623
630
624
snapshot_metafile .hashes = {
631
625
"unsupported-alg" : "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
632
626
}
633
- self .assertRaises (
634
- exceptions .LengthOrHashMismatchError ,
635
- snapshot_metafile .verify_length_and_hashes ,
636
- data ,
637
- )
627
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
628
+ snapshot_metafile .verify_length_and_hashes (data )
638
629
639
630
# Test wrong algorithm format (sslib.FormatError)
640
631
snapshot_metafile .hashes = {
641
632
256 : "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
642
633
}
643
- self .assertRaises (
644
- exceptions .LengthOrHashMismatchError ,
645
- snapshot_metafile .verify_length_and_hashes ,
646
- data ,
647
- )
634
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
635
+ snapshot_metafile .verify_length_and_hashes (data )
648
636
649
637
# test optional length and hashes
650
638
snapshot_metafile .length = None
@@ -663,19 +651,13 @@ def test_length_and_hash_validation(self):
663
651
# test exceptions
664
652
expected_length = file1_targetfile .length
665
653
file1_targetfile .length = 2345
666
- self .assertRaises (
667
- exceptions .LengthOrHashMismatchError ,
668
- file1_targetfile .verify_length_and_hashes ,
669
- file1 ,
670
- )
654
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
655
+ file1_targetfile .verify_length_and_hashes (file1 )
671
656
672
657
file1_targetfile .length = expected_length
673
658
file1_targetfile .hashes = {"sha256" : "incorrecthash" }
674
- self .assertRaises (
675
- exceptions .LengthOrHashMismatchError ,
676
- file1_targetfile .verify_length_and_hashes ,
677
- file1 ,
678
- )
659
+ with self .assertRaises (exceptions .LengthOrHashMismatchError ):
660
+ file1_targetfile .verify_length_and_hashes (file1 )
679
661
680
662
def test_targetfile_from_file (self ):
681
663
# Test with an existing file and valid hash algorithm
@@ -689,23 +671,15 @@ def test_targetfile_from_file(self):
689
671
690
672
# Test with a non-existing file
691
673
file_path = os .path .join (self .repo_dir , "targets" , "file123.txt" )
692
- self .assertRaises (
693
- FileNotFoundError ,
694
- TargetFile .from_file ,
695
- file_path ,
696
- file_path ,
697
- [sslib_hash .DEFAULT_HASH_ALGORITHM ],
698
- )
674
+ with self .assertRaises (FileNotFoundError ):
675
+ TargetFile .from_file (
676
+ file_path , file_path , [sslib_hash .DEFAULT_HASH_ALGORITHM ]
677
+ )
699
678
700
679
# Test with an unsupported algorithm
701
680
file_path = os .path .join (self .repo_dir , "targets" , "file1.txt" )
702
- self .assertRaises (
703
- exceptions .UnsupportedAlgorithmError ,
704
- TargetFile .from_file ,
705
- file_path ,
706
- file_path ,
707
- ["123" ],
708
- )
681
+ with self .assertRaises (exceptions .UnsupportedAlgorithmError ):
682
+ TargetFile .from_file (file_path , file_path , ["123" ])
709
683
710
684
def test_targetfile_from_data (self ):
711
685
data = b"Inline test content"
0 commit comments