diff options
author | crvi <crvisqr@gmail.com> | 2020-08-14 03:03:27 +0530 |
---|---|---|
committer | crvi <crvisqr@gmail.com> | 2020-08-14 03:44:02 +0530 |
commit | e68d4b07a74434dbed3fb92779891e2f325b00eb (patch) | |
tree | 14db615c5c01222b63a1dbcf6e3e11499c03b9e4 | |
parent | ec864ad39bc7a4ed46d2396871f89363dc209c5f (diff) | |
download | zeitgeist-e68d4b07a74434dbed3fb92779891e2f325b00eb.tar.gz |
test: fix ResourceWarning: unclosed file errors
-rw-r--r-- | python/datamodel.py | 3 | ||||
-rw-r--r-- | test/dbus/testutils.py | 3 | ||||
-rw-r--r-- | 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 |