Pin pip to 20.3.3 and disable tmpfs in DIB
[ta/build-tools.git] / tools / yum_test.py
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # pylint: disable=wildcard-import
16 import os
17 import pytest
18
19 from tools.test_data_yum import bash_yum_info, \
20     conntrack_tools_yum_info, \
21     pacemaker_yum_info
22 from tools.yum import YumInfoParser
23 from tools.yum_test_data import bash_expected, pacemaker_expected, \
24     yum_info_installed_header, \
25     yum_info_available_header, \
26     yum_info_available_header2
27 from tools.yum_test_data import conntrack_tools_expected
28
29
30 @pytest.mark.parametrize('yum_info, expected_output', [
31     (bash_yum_info, bash_expected),
32     (conntrack_tools_yum_info, conntrack_tools_expected),
33     (pacemaker_yum_info, pacemaker_expected)
34 ])
35 def test_parse_package(yum_info, expected_output):
36     parsed = YumInfoParser().parse_package(yum_info)
37     expected = expected_output
38     assert parsed == expected
39
40
41 def test_parse_installed():
42     fake_out = '\n'.join([yum_info_installed_header,
43                           bash_yum_info,
44                           conntrack_tools_yum_info])
45     parsed = YumInfoParser().parse_installed(fake_out)
46     expected = [bash_expected, conntrack_tools_expected]
47     assert parsed == expected
48
49
50 @pytest.mark.parametrize('available_header', [
51     yum_info_available_header,
52     yum_info_available_header2
53 ])
54 def test_parse_available(available_header):
55     fake_out = '\n'.join([available_header,
56                           bash_yum_info,
57                           conntrack_tools_yum_info])
58     parsed = YumInfoParser().parse_available(fake_out)
59     expected = [bash_expected, conntrack_tools_expected]
60     assert parsed == expected
61
62
63 def test_parse_file():
64     test_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
65                              'yum_info_installed.sample')
66     parsed = YumInfoParser().parse_file(test_file)
67     assert len(parsed) == 14