aboutsummaryrefslogtreecommitdiff
path: root/tests/test_versions.py
blob: 43a3f33a4d0dea5b49aece32e31bcc41e556e0ca (about) (plain)
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
# SPDX-License-Identifier: CC0-1.0

# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
#
# Available under the terms of Creative Commons Zero v1.0 Universal.

import pytest

from hydrilla import versions

sample_version_tuples  = [(4, 5, 3), (1, 0, 5), (3,)]
sample_version_strings = ['4.5.3',   '1.0.5',   '3']

sample_versions = [*zip(sample_version_tuples, sample_version_strings)]

@pytest.mark.parametrize('version_tuple', sample_version_tuples)
def test_normalize_version(version_tuple):
    """Verify that normalize_version() produces proper results."""
    assert versions.normalize_version([*version_tuple])    == version_tuple
    assert versions.normalize_version([*version_tuple, 0]) == version_tuple

@pytest.mark.parametrize('version_tuple, string', sample_versions)
def test_parse_version(version_tuple, string):
    """Verify that parse_version() produces proper results."""
    assert versions.parse_version(string)
    assert versions.parse_version(string + '.0') == tuple([*version_tuple, 0])

def test_parse_version_bad_string():
    """Verify that parse_version() raises when passed an invalid string."""
    with pytest.raises(ValueError):
        versions.parse_version('i am not a valid version')

@pytest.mark.parametrize('version_tuple, string', sample_versions)
def test_version_string(version_tuple, string):
    """Verify that version_string() produces proper results."""
    for _version_tuple, _string in [
            (version_tuple,              string),
            (tuple([*version_tuple, 0]), f'{string}.0')
    ]:
        assert versions.version_string(_version_tuple)    == _string
        assert versions.version_string(_version_tuple, 5) == f'{_string}-5'