diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index f698f32..361efe6 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -94,6 +94,7 @@ class BlendFile: fileobj.close() self.fileobj = tmpfile elif magic != BLENDFILE_MAGIC: + fileobj.close() raise exceptions.BlendFileError("File is not a blend file", path) self.header = header.BlendFileHeader(self.fileobj, self.raw_filepath) diff --git a/tests/test_blendfile_loading.py b/tests/test_blendfile_loading.py index 5fc4f8a..2baeccc 100644 --- a/tests/test_blendfile_loading.py +++ b/tests/test_blendfile_loading.py @@ -1,7 +1,9 @@ import os +import pathlib +import unittest from blender_asset_tracer import blendfile -from blender_asset_tracer.blendfile import iterators +from blender_asset_tracer.blendfile import iterators, exceptions from abstract_test import AbstractBlendFileTest @@ -206,3 +208,9 @@ class LoadCompressedTest(AbstractBlendFileTest): ob = self.bf.code_index[b'OB'][0] name = ob.get((b'id', b'name')) self.assertEqual('OBümlaut', name) + + +class LoadNonBlendfileTest(unittest.TestCase): + def test_loading(self): + with self.assertRaises(exceptions.BlendFileError): + blendfile.BlendFile(pathlib.Path(__file__))