File: testcommon.py

package info (click to toggle)
python-apt 1.4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,980 kB
  • sloc: cpp: 10,003; python: 7,108; makefile: 107; sh: 27
file content (42 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download | duplicates (2)
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
"""Common testing stuff"""

import apt_pkg
import os

import sys
import unittest


class TestCase(unittest.TestCase):
    """Base class for python-apt unittests"""

    def setUp(self):
        self.resetConfig()

    def resetConfig(self):
        apt_pkg.config.clear("")
        for key in apt_pkg.config.list():
            apt_pkg.config.clear(key)

        # Avoid loading any host config files
        os.unsetenv("APT_CONFIG")
        apt_pkg.config["Dir::Etc::main"] = "/dev/null"
        apt_pkg.config["Dir::Etc::parts"] = "/dev/null"

        apt_pkg.init_config()
        apt_pkg.init_system()

        # Restore default values
        apt_pkg.config["Dir::Etc::main"] = "apt.conf"
        apt_pkg.config["Dir::Etc::parts"] = "apt.conf.d"

    if (sys.version_info.major, sys.version_info.minor) < (3, 2):
        def assertRaisesRegex(self, exc_typ, regex, func, *args, **kwds):
            """Compatibility helper"""
            try:
                func(*args, **kwds)
            except Exception as exc:
                self.assertIsInstance(exc, exc_typ)
                self.assertRegexpMatches(str(exc), regex)
            else:
                self.fail("Did not raise exception")