Fix leaking file object when loading non-blend file
This commit is contained in:
parent
8e0b135eb3
commit
eb8281ea82
@ -94,6 +94,7 @@ class BlendFile:
|
|||||||
fileobj.close()
|
fileobj.close()
|
||||||
self.fileobj = tmpfile
|
self.fileobj = tmpfile
|
||||||
elif magic != BLENDFILE_MAGIC:
|
elif magic != BLENDFILE_MAGIC:
|
||||||
|
fileobj.close()
|
||||||
raise exceptions.BlendFileError("File is not a blend file", path)
|
raise exceptions.BlendFileError("File is not a blend file", path)
|
||||||
|
|
||||||
self.header = header.BlendFileHeader(self.fileobj, self.raw_filepath)
|
self.header = header.BlendFileHeader(self.fileobj, self.raw_filepath)
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
import unittest
|
||||||
|
|
||||||
from blender_asset_tracer import blendfile
|
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
|
from abstract_test import AbstractBlendFileTest
|
||||||
|
|
||||||
|
|
||||||
@ -206,3 +208,9 @@ class LoadCompressedTest(AbstractBlendFileTest):
|
|||||||
ob = self.bf.code_index[b'OB'][0]
|
ob = self.bf.code_index[b'OB'][0]
|
||||||
name = ob.get((b'id', b'name'))
|
name = ob.get((b'id', b'name'))
|
||||||
self.assertEqual('OBümlaut', name)
|
self.assertEqual('OBümlaut', name)
|
||||||
|
|
||||||
|
|
||||||
|
class LoadNonBlendfileTest(unittest.TestCase):
|
||||||
|
def test_loading(self):
|
||||||
|
with self.assertRaises(exceptions.BlendFileError):
|
||||||
|
blendfile.BlendFile(pathlib.Path(__file__))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user