From e9beeb85fc97d6c78624522e88a4df8038e6bfbb Mon Sep 17 00:00:00 2001 From: shortcutme Date: Wed, 4 Oct 2017 13:35:55 +0200 Subject: [PATCH] Use with to open files to avoid keeping them open in case of errors --- src/Test/TestContent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Test/TestContent.py b/src/Test/TestContent.py index 7d0e0f63..82229623 100644 --- a/src/Test/TestContent.py +++ b/src/Test/TestContent.py @@ -231,12 +231,12 @@ class TestContent: def testVerifyUnsafePattern(self, site): site.content_manager.contents["content.json"]["includes"]["data/test_include/content.json"]["files_allowed"] = "([a-zA-Z]+)*" with pytest.raises(UnsafePatternError) as err: - data = site.storage.open("data/test_include/content.json") - site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False) - assert "Potentially unsafe" in str(err) + with site.storage.open("data/test_include/content.json") as data: + site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False) + assert "Potentially unsafe" in str(err) site.content_manager.contents["data/users/content.json"]["user_contents"]["permission_rules"]["([a-zA-Z]+)*"] = {"max_size": 0} with pytest.raises(UnsafePatternError) as err: - data = site.storage.open("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") - site.content_manager.verifyFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", data, ignore_same=False) - assert "Potentially unsafe" in str(err) + with site.storage.open("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") as data: + site.content_manager.verifyFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", data, ignore_same=False) + assert "Potentially unsafe" in str(err)