File: test_debcargo.py

package info (click to toggle)
debmutate 0.80
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 588 kB
  • sloc: python: 8,346; makefile: 12; sh: 1
file content (144 lines) | stat: -rw-r--r-- 5,252 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python
# Copyright (C) 2020 Jelmer Vernooij
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Tests for debmutate.debcargo."""

import os
import shutil
import tempfile
from contextlib import ExitStack
from unittest import TestCase

from debmutate.debcargo import (
    DEFAULT_MAINTAINER,
    DebcargoControlShimEditor,
    DebcargoEditor,
    debcargo_version_to_semver,
    semver_pair,
)


class DebcargoVersionToSemverTests(TestCase):
    def test_prerelease(self):
        self.assertEqual("1.0.0-rc1", debcargo_version_to_semver("1.0.0~rc1"))


class SemverPairTests(TestCase):
    def test_pair(self):
        self.assertEqual("1.2", semver_pair("1.2.3-rc1"))
        self.assertEqual("1.2", semver_pair("1.2.3"))
        self.assertEqual("1.2", semver_pair("1.2.4+ds"))


class DebcargoControlShimEditorTests(TestCase):
    def setUp(self):
        super().setUp()
        self.td = tempfile.mkdtemp()
        os.mkdir(os.path.join(self.td, "debian"))
        self.addCleanup(os.chdir, os.getcwd())
        os.chdir(self.td)
        self.addCleanup(shutil.rmtree, self.td)
        self.debcargo = DebcargoEditor(allow_missing=True)
        self.es = ExitStack()
        self.es.enter_context(self.debcargo)
        self.editor = DebcargoControlShimEditor(
            self.debcargo, "crate", "1.2.3", features=["feature1", "feature2"]
        )
        self.es.enter_context(self.editor)

    def test_properties(self):
        self.assertEqual(["feature1", "feature2"], self.editor.features)
        self.assertEqual("crate", self.editor.crate_name)
        self.assertEqual("1.2.3", self.editor.crate_version)

    def test_source(self):
        self.assertEqual("rust-crate", self.editor.source["Source"])

    def test_source_semver_suffix(self):
        self.debcargo["semver_suffix"] = True
        self.assertEqual("rust-crate-1.2", self.editor.source["Source"])

    def test_source_priority(self):
        self.assertEqual("optional", self.editor.source["Priority"])

    def test_source_vcs_git(self):
        self.assertEqual(
            "https://salsa.debian.org/rust-team/debcargo-conf.git [src/crate]",
            self.editor.source["Vcs-Git"],
        )

    def test_source_vcs_git_specified(self):
        self.debcargo["source"] = {"vcs_git": "https://github.com/jelmer/crate"}
        self.assertEqual(
            "https://github.com/jelmer/crate", self.editor.source["Vcs-Git"]
        )

    def test_source_vcs_browser(self):
        self.assertEqual(
            "https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/crate",
            self.editor.source["Vcs-Browser"],
        )

    def test_source_vcs_browser_specified(self):
        self.debcargo["source"] = {"vcs_browser": "https://github.com/jelmer/crate"}
        self.assertEqual(
            "https://github.com/jelmer/crate", self.editor.source["Vcs-Browser"]
        )

    def test_homepage(self):
        self.assertRaises(KeyError, self.editor.source.__getitem__, "Homepage")

    def test_homepage_specified(self):
        self.debcargo["source"] = {"homepage": "https://github.com/jelmer/crate"}
        self.assertEqual(
            "https://github.com/jelmer/crate", self.editor.source["Homepage"]
        )

    def test_section(self):
        self.assertEqual("rust", self.editor.source["Section"])

    def test_section_specified(self):
        self.debcargo["source"] = {"section": "web"}
        self.assertEqual("web", self.editor.source["Section"])

    def test_standards_version(self):
        self.assertIsInstance(self.editor.source["Standards-Version"], str)

    def test_standards_version_specified(self):
        self.debcargo["source"] = {"policy": "1.2.3"}
        self.assertEqual("1.2.3", self.editor.source["Standards-Version"])

    def test_maintainer(self):
        self.assertEqual(DEFAULT_MAINTAINER, self.editor.source["Maintainer"])

    def test_maintainer_specified(self):
        self.debcargo["maintainer"] = "Jelmer Vernooij <jelmer@example.com>"
        self.assertEqual(
            "Jelmer Vernooij <jelmer@example.com>", self.editor.source["Maintainer"]
        )

    def test_uploaders(self):
        self.assertRaises(KeyError, self.editor.source.__getitem__, "Uploaders")

    def test_uploaders_specified(self):
        self.debcargo["uploaders"] = "Jelmer Vernooij <jelmer@example.com>"
        self.assertEqual(
            "Jelmer Vernooij <jelmer@example.com>", self.editor.source["Uploaders"]
        )

    def test_rules_requires_root(self):
        self.assertEqual("no", self.editor.source["Rules-Requires-Root"])