Skip to content

Commit affca16

Browse files
committed
Update tests for windows.
1 parent 3583a03 commit affca16

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

tests/test_files.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,26 +638,29 @@ def test_convertible_substitles_weirdext_subtitlesformat():
638638

639639
@contextmanager
640640
def create_zip_with_manifest(manifest_filename, *additional_files):
641-
# Create a temporary file for the zipfile
642-
with tempfile.NamedTemporaryFile(suffix=".zip", delete=True) as temp_zip:
641+
# Create a temporary file for the zipfile but close it immediately for Windows compatibility
642+
temp_zip = tempfile.NamedTemporaryFile(suffix=".zip", delete=False)
643+
temp_zip_path = temp_zip.name
644+
temp_zip.close() # Close the file, so it's not locked
645+
try:
643646
# Define the paths
644647
base_path = os.path.dirname(os.path.abspath(__file__))
645648
source_folder = os.path.join(base_path, "testcontent", "samples", "ims_xml")
646649
manifest_file = os.path.join(source_folder, manifest_filename)
647650

648651
# Create the zipfile and add the manifest file
649-
with zipfile.ZipFile(temp_zip.name, "w") as zf:
652+
with zipfile.ZipFile(temp_zip_path, "w") as zf:
650653
zf.write(manifest_file, "imsmanifest.xml")
651654
for additional_file in additional_files:
652655
zf.write(os.path.join(source_folder, additional_file), additional_file)
653656

654657
yield temp_zip.name
655-
656-
# Clean up the zipfile
657-
try:
658-
os.remove(temp_zip.name)
659-
except FileNotFoundError:
660-
pass
658+
finally:
659+
# Clean up the zipfile
660+
try:
661+
os.remove(temp_zip.name)
662+
except (FileNotFoundError, OSError):
663+
pass
661664

662665

663666
expected_simple_metadata = {
@@ -799,6 +802,7 @@ def test_extract_metadata_from_simple_manifest():
799802
"title": "Introduction to Hummingbirds",
800803
"metadata": {
801804
"description": "Explore the fascinating world of hummingbirds, their unique characteristics and behaviors.",
805+
"language": "en-US",
802806
},
803807
"identifier": "item1",
804808
"identifierref": "resource1",

0 commit comments

Comments
 (0)