File: test_debtags.py

package info (click to toggle)
python-debian 0.1.21
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 636 kB
  • sloc: python: 4,390; makefile: 49
file content (73 lines) | stat: -rwxr-xr-x 2,676 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/python
## vim: fileencoding=utf-8

# Copyright (C) 2006 Enrico Zini <enrico@enricozini.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# dated June, 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import sys
import unittest

sys.path.insert(0, '../lib/debian/')
import debtags

class TestDebtags(unittest.TestCase):
    def mkdb(self):
        db = debtags.DB()
        db.read(open("test_tagdb", "r"))
        return db

    def test_insert(self):
        db = debtags.DB()
        db.insert("test", set(("a", "b")));
        assert db.has_package("test")
        assert not db.has_package("a")
        assert not db.has_package("b")
        assert db.has_tag("a")
        assert db.has_tag("b")
        assert not db.has_tag("test")
        self.assertEqual(db.tags_of_package("test"), set(("a", "b")))
        self.assertEqual(db.packages_of_tag("a"), set(("test")))
        self.assertEqual(db.packages_of_tag("b"), set(("test")))
        self.assertEqual(db.package_count(), 1)
        self.assertEqual(db.tag_count(), 2)

    def test_reverse(self):
        db = debtags.DB()
        db.insert("test", set(("a", "b")));
        db = db.reverse()
        assert db.has_package("a")
        assert db.has_package("b")
        assert not db.has_package("test")
        assert db.has_tag("test")
        assert not db.has_tag("a")
        assert not db.has_tag("b")
        self.assertEqual(db.packages_of_tag("test"), set(("a", "b")))
        self.assertEqual(db.tags_of_package("a"), set(("test")))
        self.assertEqual(db.tags_of_package("b"), set(("test")))
        self.assertEqual(db.package_count(), 2)
        self.assertEqual(db.tag_count(), 1)

    def test_read(self):
        db = self.mkdb()
        self.assertEqual(db.tags_of_package("polygen"), set(("devel::interpreter", "game::toys", "interface::commandline", "works-with::text")))
        assert "polygen" in db.packages_of_tag("interface::commandline")
        self.assertEqual(db.package_count(), 144)
        self.assertEqual(db.tag_count(), 94)

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

# vim:set ts=4 sw=4 expandtab: