File: test_valid_package_names.py

package info (click to toggle)
aptdaemon 0.45-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,540 kB
  • sloc: python: 11,257; sh: 62; makefile: 5
file content (66 lines) | stat: -rw-r--r-- 2,115 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Test index handling."""

import apt
import unittest

import aptdaemon.core
import aptdaemon.errors


import mock

class TestValidPacakgeNames(unittest.TestCase):

    """Test the code that verifies for valid package names
    """

    def setUp(self):
        self.cache = apt.Cache()
        opt = mock.Mock()
        opt.dummy = True
        self.daemon = aptdaemon.core.AptDaemon(opt, connect=False)

    def test_valid_package_names(self):
        # ensure that the code raises on invalid ones, note that we
        # test each item individually instead of the list because each
        # needs to raise 
        for invalid in [
            "foo_bar", "รครครค", "i space", "a", "+invalidstart", "noUpper", 
            "foo=", "foo=", "foo=a", "foo=0 space"
            "foo/", "foo/ space"]:
            with self.assertRaises(aptdaemon.errors.AptDaemonError):
                self.daemon._check_package_names([invalid])

        # check some simple good cases
        for pkgname in ["apt", "apt/unstable", "apt=0.3.2", "apt:i386",
                        "apt+:i386/unstable", "apt+:amd64=0.3.2"]:
            self.daemon._check_package_names([pkgname])

        # ensure the code does not wrongly label valid packages as 
        # invalid, _check_package_names will raise on error
        for pkg in self.cache:
            self.daemon._check_package_names([pkg.name])

        # test again, this time with version number
        for pkg in self.cache:
            if not pkg.candidate:
                continue
            self.daemon._check_package_names(
                ["%s=%s" % (pkg.name,pkg.candidate.version)])

        # test again, this time with release origin
        for pkg in self.cache:
            if not pkg.candidate:
                continue
            archive = pkg.candidate.origins[0].archive
            if archive:
                self.daemon._check_package_names(["%s/%s" % (pkg.name,
                                                             archive)])


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

# vim: ts=4 et sts=4