diff options
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r-- | tests/unittests/test_util.py | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 9722ddd5..0b297ef1 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -2464,6 +2464,47 @@ class TestGetProcEnv(helpers.TestCase): my_ppid = os.getppid() self.assertEqual(my_ppid, util.get_proc_ppid(my_pid)) + def test_get_proc_ppid_mocked(self): + for ppid, proc_data in ( + ( + 0, + "1 (systemd) S 0 1 1 0 -1 4194560 112664 14612195 153 18014" + "274 237 756828 152754 20 0 1 0 3 173809664 3736" + "18446744073709551615 1 1 0 0 0 0 671173123 4096 1260 0 0 0 17" + "8 0 0 0 0 123974 0 0 0 0 0 0 0 0", + ), + ( + 180771, + "180781 ([pytest-xdist r) R 180771 180598 167240 34825 " + "180598 4194304 128712 7570 0 0 1061 34 8 1 20 0 2 0 6551540 " + "351993856 25173 18446744073709551615 93907896635392 " + "93907899455533 140725724279536 0 0 0 0 16781312 17642 0 0 0 " + "17 1 0 0 0 0 0 93907901810800 93907902095288 93907928788992 " + "140725724288007 140725724288074 140725724288074 " + "140725724291047 0", + ), + ( + 5620, + "8723 (Utility Process) S 5620 5191 5191 0 -1 4194304 3219 " + "0 50 0 1045 431 0 0 20 0 3 0 9007 220585984 8758 " + "18446744073709551615 94469734690816 94469735319392 " + "140728350183632 0 0 0 0 69634 1073745144 0 0 0 17 10 0 0 0 0 " + "0 94469735327152 94469735331056 94469763170304 " + "140728350189012 140728350189221 140728350189221 " + "140728350195661 0", + ), + ( + 4946, + "4947 ((sd-pam)) S 4946 4946 4946 0 -1 1077936448 54 0 0 0 " + "0 0 0 0 20 0 1 0 4136 175616000 1394 18446744073709551615 1 1" + "0 0 0 0 0 4096 0 0 0 0 17 8 0 0 0 0 0 0 0 0 0 0 0 0 0", + ), + ): + with mock.patch( + "cloudinit.util.load_file", return_value=proc_data + ): + assert ppid == util.get_proc_ppid("mocked") + class TestKernelVersion: """test kernel version function""" @@ -2616,4 +2657,59 @@ class TestFindDevs: assert devlist == expected_devlist -# vi: ts=4 expandtab +class TestVersion: + @pytest.mark.parametrize( + ("v1", "v2", "eq"), + ( + ("3.1.0", "3.1.0", True), + ("3.1.0", "3.1.1", False), + ("3.1", "3.1.0.0", False), + ), + ) + def test_eq(self, v1, v2, eq): + if eq: + assert util.Version.from_str(v1) == util.Version.from_str(v2) + if not eq: + assert util.Version.from_str(v1) != util.Version.from_str(v2) + + @pytest.mark.parametrize( + ("v1", "v2", "gt"), + ( + ("3.1.0", "3.1.0", False), + ("3.1.0", "3.1.1", False), + ("3.1", "3.1.0.0", False), + ("3.1.0.0", "3.1", True), + ("3.1.1", "3.1.0", True), + ), + ) + def test_gt(self, v1, v2, gt): + if gt: + assert util.Version.from_str(v1) > util.Version.from_str(v2) + if not gt: + assert util.Version.from_str(v1) < util.Version.from_str( + v2 + ) or util.Version.from_str(v1) == util.Version.from_str(v2) + + @pytest.mark.parametrize( + ("str_ver", "cls_ver"), + ( + ( + "0.0.0.0", + util.Version(0, 0, 0, 0), + ), + ( + "1.0.0.0", + util.Version(1, 0, 0, 0), + ), + ( + "1.0.2.0", + util.Version(1, 0, 2, 0), + ), + ( + "9.8.2.0", + util.Version(9, 8, 2, 0), + ), + ), + ) + def test_from_str(self, str_ver, cls_ver): + assert util.Version.from_str(str_ver) == cls_ver |