1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Test index handling."""
import os.path
import apt
import apt_pkg
import unittest
import aptdaemon.test
class IndexRaceTest(unittest.TestCase):
"""If the indexes are deleted or manipulated at the time
apt.Cache.required_download was called we get the following error:
SystemError: I wasn't able to locate file for the XXX package.
This might mean you need to manually fix this package.
See lp:#659438
"""
def setUp(self):
self.chroot = aptdaemon.test.Chroot()
self.chroot.setup()
self.chroot.add_test_repository()
# Check if installing an uninstalled package works
self.cache = apt.Cache(rootdir=self.chroot.path)
self.cache["silly-base"].mark_install()
self.assertEqual(self.cache.required_download, 0)
self.cache.clear()
def test(self):
lists_path = apt_pkg.config.find_dir("Dir::State::Lists")
for file_name in os.listdir(lists_path):
if file_name.endswith("Packages"):
os.remove(os.path.join(lists_path, file_name))
self.cache["silly-base"].mark_install()
self.assertRaises(SystemError,
lambda: self.cache.required_download)
# self.cache.required_download
if __name__ == "__main__":
unittest.main()
# vim: ts=4 et sts=4
|