File: test_progress.py

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (47 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download
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
#!/usr/bin/python
#
# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
"""Unit tests for verifying the correctness of apt.progress"""
import unittest

import apt
import apt_pkg
import os

class TestAcquireProgress(apt.progress.base.AcquireProgress):
    def pulse(self, owner):
        self.pulsed = True
        # there should be a return value here, either (True,False)
        # but often this is forgoten (and causes odd error messages)
        # so the lib supports it. we test the lack of support value here

class TestProgress(unittest.TestCase):

    def setUp(self):
        basedir = os.path.abspath(os.path.dirname(__file__))
        # setup apt_pkg config
        apt_pkg.init()
        apt_pkg.config.set("APT::Architecture", "amd64")
        apt_pkg.config.set("Dir::Etc", basedir)
        apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx")
        # setup lists dir
        if not os.path.exists("./tmp/partial"):
            os.makedirs("./tmp/partial")
        apt_pkg.config.set("Dir::state::lists", "./tmp")
        # create artifical line
        deb_line = "deb file:%s/data/fake-packages/ /\n" % basedir
        open("fetch_sources.list","w").write(deb_line)
        apt_pkg.config.set("Dir::Etc::sourcelist", "fetch_sources.list")

    def test_acquire_progress(self):
        progress = TestAcquireProgress()
        cache = apt.Cache()
        res = cache.update(progress)
        self.assertTrue(progress.pulsed)

if __name__ == "__main__":
    unittest.main()