summaryrefslogtreecommitdiff
path: root/tests/test_apt_cache.py
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2011-04-06 11:15:47 +0200
committerJulian Andres Klode <jak@debian.org>2011-04-06 11:15:47 +0200
commit5ad927a38cad08a2d79f327e7bb3cc46316fa6a4 (patch)
tree0ad729e5abaeaa66923883251587695ea2e4c00c /tests/test_apt_cache.py
parentb766dc001aeea1c18b0c17c1d5029673ef539ef0 (diff)
downloadpython-apt-5ad927a38cad08a2d79f327e7bb3cc46316fa6a4.tar.gz
all: Fix all instances of ResourceWarning about unclosed files
Diffstat (limited to 'tests/test_apt_cache.py')
-rw-r--r--tests/test_apt_cache.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index b4cc650d..151a20e2 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -89,17 +89,17 @@ class TestAptCache(unittest.TestCase):
tmpdir = tempfile.mkdtemp()
dpkg_dir = os.path.join(tmpdir,"var","lib","dpkg")
os.makedirs(os.path.join(dpkg_dir,"updates"))
- open(os.path.join(dpkg_dir,"status"), "w")
+ open(os.path.join(dpkg_dir,"status"), "w").close()
apt_pkg.config.set("Dir::State::status",
os.path.join(dpkg_dir,"status"))
cache = apt.Cache()
# test empty
self.assertFalse(cache.dpkg_journal_dirty)
# that is ok, only [0-9] are dpkg jounral entries
- open(os.path.join(dpkg_dir,"updates","xxx"), "w")
+ open(os.path.join(dpkg_dir,"updates","xxx"), "w").close()
self.assertFalse(cache.dpkg_journal_dirty)
# that is a dirty journal
- open(os.path.join(dpkg_dir,"updates","000"), "w")
+ open(os.path.join(dpkg_dir,"updates","000"), "w").close()
self.assertTrue(cache.dpkg_journal_dirty)
# reset config value
apt_pkg.config.set("Dir::State::status", old_status)
@@ -121,20 +121,19 @@ class TestAptCache(unittest.TestCase):
apt_pkg.config.set("dir::etc::sourceparts", "xxx")
# main sources.list
sources_list = base_sources
- f=open(sources_list, "w")
- repo = os.path.abspath("./data/test-repo2")
- f.write("deb copy:%s /\n" % repo)
- f.close()
+ with open(sources_list, "w") as f:
+ repo = os.path.abspath("./data/test-repo2")
+ f.write("deb copy:%s /\n" % repo)
# test single sources.list fetching
sources_list = os.path.join(rootdir, "test.list")
- f=open(sources_list, "w")
- repo_dir = os.path.abspath("./data/test-repo")
- f.write("deb copy:%s /\n" % repo_dir)
- f.close()
+ with open(sources_list, "w") as f:
+ repo_dir = os.path.abspath("./data/test-repo")
+ f.write("deb copy:%s /\n" % repo_dir)
+
self.assertTrue(os.path.exists(sources_list))
# write marker to ensure listcleaner is not run
- open("./data/tmp/var/lib/apt/lists/marker", "w")
+ open("./data/tmp/var/lib/apt/lists/marker", "w").close()
# update a single sources.list
cache = apt.Cache()