Codebase list distro-info / e2877dc
python: Use PEP440 compliant version in setup.py The version `1.1ubuntu1` in Ubuntu is clearly not compliant with https://peps.python.org/pep-0440/. Bug: https://launchpad.net/bugs/1991606 Signed-off-by: Benjamin Drung <bdrung@debian.org> Benjamin Drung 1 year, 6 months ago
2 changed file(s) with 44 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 # Copyright (C) 2022, Benjamin Drung <bdrung@debian.org>
1 #
2 # Permission to use, copy, modify, and/or distribute this software for any
3 # purpose with or without fee is hereby granted, provided that the above
4 # copyright notice and this permission notice appear in all copies.
5 #
6 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
7 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
8 # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
9 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
10 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
11 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12 # PERFORMANCE OF THIS SOFTWARE.
13
14 """Test functions in setup.py."""
15
16 import unittest
17 import unittest.mock
18
19 from setup import get_pep440_version
20
21
22 class SetupTestCase(unittest.TestCase):
23 """Test functions in setup.py."""
24
25 @unittest.mock.patch("setup.get_debian_version")
26 def test_get_pep440_version_unchanged(self, debian_version_mock):
27 """Test get_pep440_version() for version '1.2'."""
28 debian_version_mock.return_value = "1.2"
29 self.assertEqual(get_pep440_version(), "1.2")
30 debian_version_mock.assert_called_once_with()
31
32 @unittest.mock.patch("setup.get_debian_version")
33 def test_get_pep440_version_ubuntu(self, debian_version_mock):
34 """Test get_pep440_version() for version '1.1ubuntu1'."""
35 debian_version_mock.return_value = "1.1ubuntu1"
36 self.assertEqual(get_pep440_version(), "1.1+ubuntu1")
37 debian_version_mock.assert_called_once_with()
2222 return version
2323
2424
25 def get_pep440_version():
26 """Return the a PEP440 compliant version."""
27 return re.sub("([a-zA-Z])", r"+\1", get_debian_version(), count=1)
28
29
2530 if __name__ == "__main__":
2631 setup(
2732 name="distro-info",
28 version=get_debian_version(),
33 version=get_pep440_version(),
2934 py_modules=PY_MODULES,
3035 packages=PACKAGES,
3136 test_suite="distro_info_test",