From e68d4b07a74434dbed3fb92779891e2f325b00eb Mon Sep 17 00:00:00 2001 From: crvi Date: Fri, 14 Aug 2020 03:03:27 +0530 Subject: test: fix ResourceWarning: unclosed file errors --- python/datamodel.py | 3 ++- test/dbus/testutils.py | 3 ++- test/dbus/upgrade-test.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/datamodel.py b/python/datamodel.py index 02a54a9a..2f148ca6 100644 --- a/python/datamodel.py +++ b/python/datamodel.py @@ -1169,7 +1169,8 @@ _SYMBOLS_BY_URI["Manifestation"] = Manifestation # Load the ontology definitions ontology_file = os.path.join(os.path.dirname(__file__), "_ontology.py") try: - exec(compile(open(ontology_file, "rb").read(), ontology_file, 'exec')) + with open(ontology_file, "rb") as f: + exec(compile(f.read(), ontology_file, 'exec')) except IOError: raise ImportError("Unable to load Zeitgeist ontology. Did you run `make`?") diff --git a/test/dbus/testutils.py b/test/dbus/testutils.py index ad2fe25c..cffcc683 100644 --- a/test/dbus/testutils.py +++ b/test/dbus/testutils.py @@ -77,7 +77,8 @@ def dict2event(d): return ev def parse_events(path): - data = json.load(open(path)) + with open(path) as f: + data = json.load(f) events = list(map(dict2event, data)) return events diff --git a/test/dbus/upgrade-test.py b/test/dbus/upgrade-test.py index 6e9a7b3c..2854cf3b 100644 --- a/test/dbus/upgrade-test.py +++ b/test/dbus/upgrade-test.py @@ -42,7 +42,8 @@ class ZeitgeistUpgradeTest(testutils.RemoteTestCase): def prepare(self, from_version): # Create initial database con = sqlite3.connect(self._db_file) - initial_sql = open("test/data/databases/%s.sql" % from_version).read() + with open("test/data/databases/%s.sql" % from_version) as f: + initial_sql = f.read() con.cursor().executescript(initial_sql) del con -- cgit v1.2.1