File: test_debtags.py

package info (click to toggle)
python-debian 1.0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,260 kB
  • sloc: python: 12,905; makefile: 239; sh: 25
file content (84 lines) | stat: -rwxr-xr-x 2,834 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.

import os.path

import pytest

from debian import debtags

from typing import (
    Generator
)


def find_test_file(filename):
    # type: (str) -> str
    """ find a test file that is located within the test suite """
    return os.path.join(os.path.dirname(__file__), filename)


class TestDebtags:

    @pytest.fixture()
    def debtagsdb(self):
        # type: () -> Generator[debtags.DB, None, None]
        db = debtags.DB()
        with open(find_test_file("test_tagdb"), "r") as f:
            db.read(f)
        yield db

    def test_insert(self) -> None:
        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")
        assert db.tags_of_package("test") == set(("a", "b"))
        assert db.packages_of_tag("a") == set(("test"))
        assert db.packages_of_tag("b") == set(("test"))
        assert db.package_count() == 1
        assert db.tag_count() == 2

    def test_reverse(self) -> None:
        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")
        assert db.packages_of_tag("test") == set(("a", "b"))
        assert db.tags_of_package("a") == set(("test"))
        assert db.tags_of_package("b") == set(("test"))
        assert db.package_count() == 2
        assert db.tag_count() == 1

    def test_read(self, debtagsdb):
        # type: (debtags.DB) -> None
        db = debtagsdb
        assert db.tags_of_package("polygen") == \
            set(("devel::interpreter", "game::toys", "interface::commandline", "works-with::text"))
        assert "polygen" in db.packages_of_tag("interface::commandline")
        assert db.package_count() == 144
        assert db.tag_count() == 94