~launchpad-pqm/launchpad/devel

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
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for debversion."""

__metaclass__ = type

# These tests came from sourcerer.

import unittest

from lp.archivepublisher.debversion import (
    BadInputError,
    BadUpstreamError,
    Version,
    VersionError,
    )


class VersionTests(unittest.TestCase):
    # Known values that should work
    VALUES = (
        "1",
        "1.0",
        "1:1.0",
        "1.0-1",
        "1:1.0-1",
        "3.4-2.1",
        "1.5.4-1.woody.0",
        "1.6-0+1.5a-4",
        "1.3~rc1-4",
        )

    # Known less-than comparisons
    COMPARISONS = (
        ("1.0", "1.1"),
        ("1.1", "2.0"),
        ("2.1", "2.10"),
        ("2.2", "2.10"),
        ("1.0", "1:1.0"),
        ("1:9.0", "2:1.0"),
        ("1.0-1", "1.0-2"),
        ("1.0", "1.0-1"),
        ("1a", "1b"),
        ("1a", "2"),
        ("1a", "1."),
        ("1a", "1+"),
        ("1:1a", "1:1:"),
        ("1a-1", "1--1"),
        ("1+-1", "1--1"),
        ("1--1", "1.-1"),
        ("1:1.", "1:1:"),
        ("1A", "1a"),
        ("1~", "1"),
        ("1~", "1~a"),
        ("1~a", "1~b"),
        )

    def testAcceptsString(self):
        """Version should accept a string input."""
        Version("1.0")

    def testReturnString(self):
        """Version should convert to a string."""
        self.assertEquals(str(Version("1.0")), "1.0")

    def testAcceptsInteger(self):
        """Version should accept an integer."""
        self.assertEquals(str(Version(1)), "1")

    def testAcceptsNumber(self):
        """Version should accept a number."""
        self.assertEquals(str(Version(1.2)), "1.2")

    def testNotEmpty(self):
        """Version should fail with empty input."""
        self.assertRaises(BadInputError, Version, "")

    def testEpochNotEmpty(self):
        """Version should fail with empty epoch."""
        self.assertRaises(VersionError, Version, ":1")

    def testEpochNonNumeric(self):
        """Version should fail with non-numeric epoch."""
        self.assertRaises(VersionError, Version, "a:1")

    def testEpochNonInteger(self):
        """Version should fail with non-integral epoch."""
        self.assertRaises(VersionError, Version, "1.0:1")

    def testEpochNonNegative(self):
        """Version should fail with a negative epoch."""
        self.assertRaises(VersionError, Version, "-1:1")

    def testUpstreamNotEmpty(self):
        """Version should fail with empty upstream."""
        self.assertRaises(BadUpstreamError, Version, "1:-1")

    def testUpstreamNonDigitStart(self):
        """Version should fail when upstream doesn't start with a digit."""
        self.assertRaises(BadUpstreamError, Version, "a1")

    def testUpstreamInvalid(self):
        """Version should fail when upstream contains a bad character."""
        self.assertRaises(VersionError, Version, "1!0")

    def testRevisionNotEmpty(self):
        """Version should not allow an empty revision."""
        v = Version("1-")
        self.assertEquals("1-", v.upstream_version)
        self.assertEquals(None, v.debian_version)

    def testRevisionInvalid(self):
        """Version should fail when revision contains a bad character."""
        self.assertRaises(VersionError, Version, "1-!")

    def testValues(self):
        """Version should give same input as output."""
        for value in self.VALUES:
            result = str(Version(value))
            self.assertEquals(value, result)

    def testComparisons(self):
        """Sample Version comparisons should pass."""
        for x, y in self.COMPARISONS:
            self.failUnless(Version(x) < Version(y))

    def testNullEpochIsZero(self):
        """Version should treat an omitted epoch as a zero one."""
        self.assertEquals(Version("1.0"), Version("0:1.0"))

    def notestNullRevisionIsZero(self):
        """Version should treat an omitted revision as being equal to zero.
        """
        self.assertEquals(Version("1.0"), Version("1.0-0"))
        from lp.archivepublisher.debversion import Version
        self.failUnless(Version("1.0") == Version("1.0-0"))