diff options
| author | Jason Conti <jason.conti@gmail.com> | 2012-10-12 14:14:34 -0400 |
|---|---|---|
| committer | Jason Conti <jason.conti@gmail.com> | 2012-10-12 14:14:34 -0400 |
| commit | 44c2dafdd59c98f629b812f6e741c14073908eb2 (patch) | |
| tree | ead4d1a3653e2b05c6385f25a281e11887e42c7a /tests | |
| parent | d4fef411ff23681d5aaa298157f81576576eeb2b (diff) | |
| download | python-apt-44c2dafdd59c98f629b812f6e741c14073908eb2.tar.gz | |
* tests/test_apt_cache.py:
- Add test to verify all files are closed after calling apt.Cache.close()
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_apt_cache.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 448aed75..63ce46bc 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -19,6 +19,7 @@ import apt import apt_pkg import shutil import glob +import os import logging def if_sources_list_is_readable(f): @@ -29,6 +30,14 @@ 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 +79,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/") |
