File: test_upstream_uscan.py

package info (click to toggle)
breezy-debian 2.8.80
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,444 kB
  • sloc: python: 17,599; makefile: 61; sh: 1
file content (132 lines) | stat: -rw-r--r-- 4,332 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
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
#    test_upstream_uscan.py -- Test getting the upstream source from uscan
#    Copyright (C) 2012 Jelmer Vernooij
#
#    This file is part of brz-debian
#
#    bzr-builddeb 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.
#
#    bzr-builddeb 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 bzr-builddeb; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

"""Tests for the upstream uscan module."""

import tempfile

from ....transport import NoSuchFile
from ....tests import (
    TestCase,
    TestCaseWithTransport,
    )
from ..upstream.uscan import (
    UScanSource,
    UScanError,
    _xml_report_extract_upstream_version,
    _xml_report_extract_warnings,
    )


class UScanSourceTests(TestCaseWithTransport):

    def setUp(self):
        super().setUp()
        self.tree = self.make_branch_and_tree('.')

    def test_export_watchfile_none(self):
        src = UScanSource(self.tree, '', False)
        self.assertRaises(NoSuchFile, src._export_file, 'watch', self.test_dir)

    def test_export_watchfile_top_level(self):
        src = UScanSource(self.tree, '', True)
        self.build_tree(['watch'])
        self.tree.add(['watch'])
        with tempfile.TemporaryDirectory() as tmpdir:
            self.assertIsNot(src._export_file('watch', tmpdir), None)

    def test_export_watchfile(self):
        src = UScanSource(self.tree, '', False)
        self.build_tree(['debian/', 'debian/watch'])
        self.tree.smart_add(['debian/watch'])
        with tempfile.TemporaryDirectory() as tmpdir:
            self.assertIsNot(src._export_file('watch', tmpdir), None)


class UScanOutputParsingTests(TestCase):

    def test__xml_report_extract_upstream_version(self):
        text = b"""
<dehs>
<package>tdb</package>
<debian-uversion>1.2.8</debian-uversion>
<debian-mangled-uversion>1.2.8</debian-mangled-uversion>
<upstream-version>1.2.9</upstream-version>
<upstream-url>ftp://ftp.samba.org/pub/tdb/tdb-1.2.9.tar.gz</upstream-url>
<status>Newer version available</status>
</dehs>"""
        self.assertEqual("1.2.9", _xml_report_extract_upstream_version(text))

    def test__xml_report_extract_warnings(self):
        text = b"""
<dehs>
<package>tdb</package>
<debian-uversion>1.2.8</debian-uversion>
<debian-mangled-uversion>1.2.8</debian-mangled-uversion>
<upstream-version>1.2.9</upstream-version>
<upstream-url>ftp://ftp.samba.org/pub/tdb/tdb-1.2.9.tar.gz</upstream-url>
<status>Newer version available</status>
<warnings>this is a warning
with a newline</warnings>
</dehs>"""
        self.assertEqual(
            ["this is a warning\nwith a newline"],
            list(_xml_report_extract_warnings(text)))

    def test__xml_report_extract_upstream_version_warnings(self):
        text = b"""
<dehs>
<package>tdb</package>
<warnings>uscan warning: Unable to determine current version
in debian/watch, skipping:
ftp://ftp.samba.org/pub/tdb/tdb-(.+).tar.gz</warnings>
</dehs>
"""
        self.assertIs(
            None,
            _xml_report_extract_upstream_version(text))

    def test__xml_report_extract_upstream_version_noise(self):
        text = b"""
<dehs>
blahf =>
<package>tdb</package>
<debian-uversion>1.2.8</debian-uversion>
<upstream-version>1.2.9</upstream-version>
<warnings>uscan warning: Unable to determine current version
in debian/watch, skipping:
ftp://ftp.samba.org/pub/tdb/tdb-(.+).tar.gz</warnings>
</dehs>
"""
        self.assertEqual(
            "1.2.9",
            _xml_report_extract_upstream_version(text))

    def test__xml_report_extract_upstream_version_errors(self):
        text = b"""
<dehs>
blahf =>
<package>tdb</package>
<debian-uversion>1.2.8</debian-uversion>
<errors>something something signature</errors>
</dehs>
"""
        self.assertRaises(
            UScanError,
            _xml_report_extract_upstream_version, text)