@@ -1627,32 +1627,32 @@ def test_9__get_target_hash(self):
1627
1627
1628
1628
def test_10__hard_check_file_length (self ):
1629
1629
# Test for exception if file object is not equal to trusted file length.
1630
- temp_file_object = tempfile .TemporaryFile ()
1631
- temp_file_object .write (b'X' )
1632
- temp_file_object .seek (0 )
1633
- self .assertRaises (tuf .exceptions .DownloadLengthMismatchError ,
1634
- self .repository_updater ._hard_check_file_length ,
1635
- temp_file_object , 10 )
1630
+ with tempfile .TemporaryFile () as temp_file_object :
1631
+ temp_file_object .write (b'X' )
1632
+ temp_file_object .seek (0 )
1633
+ self .assertRaises (tuf .exceptions .DownloadLengthMismatchError ,
1634
+ self .repository_updater ._hard_check_file_length ,
1635
+ temp_file_object , 10 )
1636
1636
1637
1637
1638
1638
1639
1639
1640
1640
1641
1641
def test_10__soft_check_file_length (self ):
1642
1642
# Test for exception if file object is not equal to trusted file length.
1643
- temp_file_object = tempfile .TemporaryFile ()
1644
- temp_file_object .write (b'XXX' )
1645
- temp_file_object .seek (0 )
1646
- self .assertRaises (tuf .exceptions .DownloadLengthMismatchError ,
1647
- self .repository_updater ._soft_check_file_length ,
1648
- temp_file_object , 1 )
1643
+ with tempfile .TemporaryFile () as temp_file_object :
1644
+ temp_file_object .write (b'XXX' )
1645
+ temp_file_object .seek (0 )
1646
+ self .assertRaises (tuf .exceptions .DownloadLengthMismatchError ,
1647
+ self .repository_updater ._soft_check_file_length ,
1648
+ temp_file_object , 1 )
1649
1649
1650
- # Verify that an exception is not raised if the file length <= the observed
1651
- # file length.
1652
- temp_file_object .seek (0 )
1653
- self .repository_updater ._soft_check_file_length (temp_file_object , 3 )
1654
- temp_file_object .seek (0 )
1655
- self .repository_updater ._soft_check_file_length (temp_file_object , 4 )
1650
+ # Verify that an exception is not raised if the file length <= the observed
1651
+ # file length.
1652
+ temp_file_object .seek (0 )
1653
+ self .repository_updater ._soft_check_file_length (temp_file_object , 3 )
1654
+ temp_file_object .seek (0 )
1655
+ self .repository_updater ._soft_check_file_length (temp_file_object , 4 )
1656
1656
1657
1657
1658
1658
@@ -1763,14 +1763,13 @@ def test_10__visit_child_role(self):
1763
1763
1764
1764
def test_11__verify_metadata_file (self ):
1765
1765
# Test for invalid metadata content.
1766
- metadata_file_object = tempfile .TemporaryFile ()
1767
- metadata_file_object .write (b'X' )
1768
- metadata_file_object .seek (0 )
1769
-
1770
- self .assertRaises (tuf .exceptions .InvalidMetadataJSONError ,
1771
- self .repository_updater ._verify_metadata_file ,
1772
- metadata_file_object , 'root' )
1766
+ with tempfile .TemporaryFile () as metadata_file_object :
1767
+ metadata_file_object .write (b'X' )
1768
+ metadata_file_object .seek (0 )
1773
1769
1770
+ self .assertRaises (tuf .exceptions .InvalidMetadataJSONError ,
1771
+ self .repository_updater ._verify_metadata_file ,
1772
+ metadata_file_object , 'root' )
1774
1773
1775
1774
1776
1775
def test_12__get_file (self ):
@@ -1788,10 +1787,10 @@ def verify_target_file(targets_path):
1788
1787
self .repository_updater ._check_hashes (targets_path , file_hashes )
1789
1788
1790
1789
self .repository_updater ._get_file ('targets.json' , verify_target_file ,
1791
- file_type , file_size , download_safely = True )
1790
+ file_type , file_size , download_safely = True ). close ()
1792
1791
1793
1792
self .repository_updater ._get_file ('targets.json' , verify_target_file ,
1794
- file_type , file_size , download_safely = False )
1793
+ file_type , file_size , download_safely = False ). close ()
1795
1794
1796
1795
def test_13__targets_of_role (self ):
1797
1796
# Test case where a list of targets is given. By default, the 'targets'
0 commit comments