Pin pip to 20.3.3 and disable tmpfs in DIB
[ta/build-tools.git] / tools / rpm_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 import os
16 import re
17
18 import pytest
19
20 from tools.rpm import RpmInfoParser
21 from tools.rpm_test_data import \
22     bash_expected, conntrack_tools_expected, cpp_expected, usbredir_expected, perl_compress_expected
23 from tools.test_data_rpm import \
24     bash_rpm_info, cpp_rpm_info, conntrack_tools_rpm_info, usbredir_rpm_info, perl_compress_rpm_info
25
26
27 @pytest.mark.parametrize('rpm_info, expected_output', [
28     (bash_rpm_info, bash_expected),
29     (conntrack_tools_rpm_info, conntrack_tools_expected),
30     (cpp_rpm_info, cpp_expected),
31     (usbredir_rpm_info, usbredir_expected),
32     (perl_compress_rpm_info, perl_compress_expected)
33 ])
34 def test_parse_package(rpm_info, expected_output):
35     parsed = RpmInfoParser().parse_package(rpm_info)
36     assert parsed == expected_output
37
38
39 def test_parse_multiple():
40     parsed = RpmInfoParser().parse_multiple('\n'.join([bash_rpm_info, conntrack_tools_rpm_info]))
41     assert parsed == [bash_expected, conntrack_tools_expected]
42
43
44 def test_parse_file():
45     test_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
46                              'rpm_info_installed.sample')
47     parsed = RpmInfoParser().parse_file(test_file)
48     with open(test_file, 'r') as f:
49         expected_rpms = re.findall(r'^Name\s+:.*$', f.read(), re.MULTILINE)
50     assert len(parsed) == len(expected_rpms)