Enhancements K8s helm connector
[osm/N2VC.git] / modules / libjuju / tests / unit / test_overrides.py
1 from juju.client.overrides import Binary, Number # noqa
2
3 import pytest
4
5
6 # test cases ported from:
7 # https://github.com/juju/version/blob/master/version_test.go
8 @pytest.mark.parametrize("input,expected", (
9 (None, Number(major=0, minor=0, patch=0, tag='', build=0)),
10 (Number(major=1, minor=0, patch=0), Number(major=1, minor=0, patch=0)),
11 ({'major': 1, 'minor': 0, 'patch': 0}, Number(major=1, minor=0, patch=0)),
12 ("0.0.1", Number(major=0, minor=0, patch=1)),
13 ("0.0.2", Number(major=0, minor=0, patch=2)),
14 ("0.1.0", Number(major=0, minor=1, patch=0)),
15 ("0.2.3", Number(major=0, minor=2, patch=3)),
16 ("1.0.0", Number(major=1, minor=0, patch=0)),
17 ("10.234.3456", Number(major=10, minor=234, patch=3456)),
18 ("10.234.3456.1", Number(major=10, minor=234, patch=3456, build=1)),
19 ("10.234.3456.64", Number(major=10, minor=234, patch=3456, build=64)),
20 ("10.235.3456", Number(major=10, minor=235, patch=3456)),
21 ("1.21-alpha1", Number(major=1, minor=21, patch=1, tag="alpha")),
22 ("1.21-alpha1.1", Number(major=1, minor=21, patch=1, tag="alpha",
23 build=1)),
24 ("1.21-alpha10", Number(major=1, minor=21, patch=10, tag="alpha")),
25 ("1.21.0", Number(major=1, minor=21)),
26 ("1234567890.2.1", TypeError),
27 ("0.2..1", TypeError),
28 ("1.21.alpha1", TypeError),
29 ("1.21-alpha", TypeError),
30 ("1.21-alpha1beta", TypeError),
31 ("1.21-alpha-dev", TypeError),
32 ("1.21-alpha_dev3", TypeError),
33 ("1.21-alpha123dev3", TypeError),
34 ))
35 def test_number(input, expected):
36 if expected is TypeError:
37 with pytest.raises(expected):
38 Number.from_json(input)
39 else:
40 result = Number.from_json(input)
41 assert result == expected
42 if isinstance(input, str):
43 assert result.to_json() == input
44
45
46 # test cases ported from:
47 # https://github.com/juju/version/blob/master/version_test.go
48 @pytest.mark.parametrize("input,expected", (
49 (None, Binary(Number(), None, None)),
50 (Binary(Number(1), 'trusty', 'amd64'), Binary(Number(1),
51 'trusty', 'amd64')),
52 ({'number': {'major': 1},
53 'series': 'trusty',
54 'arch': 'amd64'}, Binary(Number(1), 'trusty', 'amd64')),
55 ("1.2.3-trusty-amd64", Binary(Number(1, 2, 3, "", 0),
56 "trusty", "amd64")),
57 ("1.2.3.4-trusty-amd64", Binary(Number(1, 2, 3, "", 4),
58 "trusty", "amd64")),
59 ("1.2-alpha3-trusty-amd64", Binary(Number(1, 2, 3, "alpha", 0),
60 "trusty", "amd64")),
61 ("1.2-alpha3.4-trusty-amd64", Binary(Number(1, 2, 3, "alpha", 4),
62 "trusty", "amd64")),
63 ("1.2.3", TypeError),
64 ("1.2-beta1", TypeError),
65 ("1.2.3--amd64", TypeError),
66 ("1.2.3-trusty-", TypeError),
67 ))
68 def test_binary(input, expected):
69 if expected is TypeError:
70 with pytest.raises(expected):
71 Binary.from_json(input)
72 else:
73 result = Binary.from_json(input)
74 assert result == expected
75 if isinstance(input, str):
76 assert result.to_json() == input