Pylog test suite
[logging-analytics.git] / pylog / tests / test_utils.py
1 # Copyright (c) 2020 Deutsche Telekom.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
11 import sys
12
13 import unittest
14 if sys.version_info[0] < 3:
15     from mock import patch, MagicMock
16 if sys.version_info[0] >= 3:
17     from unittest.mock import patch, MagicMock
18
19 from onaplogging.utils import is_above_python_2_7, is_above_python_3_2
20
21
22 class TestUtils(unittest.TestCase):
23
24     def test_is_above_python_3_2(self):
25         with patch("onaplogging.utils.sys.version_info", (3, 4, 7)):
26             assert is_above_python_3_2() is True
27
28         with patch("onaplogging.utils.sys.version_info", (2, 7, 5)):
29             assert is_above_python_3_2() is False
30
31         with patch("onaplogging.utils.sys.version_info", (3, 2, 0, "final", 0)):
32             assert is_above_python_3_2() is True
33
34     def test_is_above_python_2_7(self):
35         with patch("onaplogging.utils.sys.version_info", (3, 4, 7)):
36             assert is_above_python_2_7() is True
37
38         with patch("onaplogging.utils.sys.version_info", (2, 7, 5)):
39             assert is_above_python_2_7() is True
40
41         with patch("onaplogging.utils.sys.version_info", (2, 5, 6)):
42             assert is_above_python_2_7() is False
43
44         with patch("onaplogging.utils.sys.version_info", (2, 7, 0, "final", 0)):
45             assert is_above_python_2_7() is True