summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-06-29 11:23:31 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-06-29 11:23:31 +0200
commit508f1ddb5b6a0cc69655e39dbd59fe3466173a84 (patch)
tree0c8688b9adbea946ca41757e0c446d8374e06657 /tests
parentcdaebccd5f7a5a0e23a9be7989b64850fabafed1 (diff)
downloadpython-apt-508f1ddb5b6a0cc69655e39dbd59fe3466173a84.tar.gz
* apt/cache.py:
- add new "dpkg_journal_dirty" property that can be used to detect a interrupted dpkg (the famous "E: dpkg was interrupted, you must manually run 'dpkg --configure -a'")
Diffstat (limited to 'tests')
-rw-r--r--tests/test_apt_cache.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index a00fa08b..b27ed778 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -9,6 +9,9 @@
import unittest
import apt
+import apt_pkg
+import os
+import tempfile
class TestAptCache(unittest.TestCase):
@@ -39,5 +42,28 @@ class TestAptCache(unittest.TestCase):
self.assert_(len(r['Description']) > 0)
self.assert_(str(r).startswith('Package: %s\n' % pkg.name))
+ def test_dpkg_journal_dirty(self):
+ # backup old value
+ old_status = apt_pkg.Config.find_file("Dir::State::status")
+ # create tmp env
+ 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")
+ 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")
+ self.assertFalse(cache.dpkg_journal_dirty)
+ # that is a dirty journal
+ open(os.path.join(dpkg_dir,"updates","000"), "w")
+ self.assertTrue(cache.dpkg_journal_dirty)
+ # reset config value
+ apt_pkg.Config.set("Dir::State::status", old_status)
+
+
if __name__ == "__main__":
unittest.main()