summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_apt_cache.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index 448aed75..fc429cf3 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -7,19 +7,21 @@
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
"""Unit tests for verifying the correctness of check_dep, etc in apt_pkg."""
+
+import glob
+import logging
import os
+import shutil
+import sys
import tempfile
import unittest
from test_all import get_library_dir
-import sys
sys.path.insert(0, get_library_dir())
import apt
import apt_pkg
-import shutil
-import glob
-import logging
+
def if_sources_list_is_readable(f):
def wrapper(*args, **kwargs):
@@ -29,6 +31,16 @@ def if_sources_list_is_readable(f):
logging.warn("skipping '%s' because sources.list is not readable" % f)
return wrapper
+
+def get_open_file_descriptors():
+ try:
+ fds = os.listdir("/proc/self/fd")
+ except OSError:
+ logging.warn("failed to list /proc/self/fd")
+ return set([])
+ return set(map(int, fds))
+
+
class TestAptCache(unittest.TestCase):
""" test the apt cache """
@@ -70,6 +82,16 @@ class TestAptCache(unittest.TestCase):
self.assertTrue(len(r['Description']) > 0)
self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname))
+ @if_sources_list_is_readable
+ def test_closeable_cache(self):
+ fd_0 = get_open_file_descriptors()
+ cache = apt.Cache()
+ opened_fd = get_open_file_descriptors().difference(fd_0)
+ cache.close()
+ fd_1 = get_open_file_descriptors()
+ unclosed_fd = opened_fd.intersection(fd_1)
+ self.assertEqual(unclosed_fd, set())
+
def test_get_provided_packages(self):
apt.apt_pkg.config.set("Apt::architecture", "i386")
cache = apt.Cache(rootdir="./data/test-provides/")