1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#############################################################################
##
## Copyright (C) 2022 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the release tools of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
from tests import testhelpers
import unittest
from ddt import ddt
from typing import List
import release_task_reader
import configparser
@ddt
class TestReleaseTaskReader(unittest.TestCase):
@testhelpers.asyncio_test_parallel_data(("linux,x64,common", ["linux", "x64", "common"]),
("linux, x64, common ", ["linux", "x64", "common"]),
("linux; , x64 common ", ["linux", "x64", "common"]),
(": ,,; linux x64 common ", ["linux", "x64", "common"]))
async def test_get_filter_parts(self, task_filters: str, expected_result: List[str]) -> None:
self.assertEqual(release_task_reader.get_filter_parts(task_filters), expected_result)
@testhelpers.asyncio_test
async def test_release_task_reader(self) -> None:
sample_config = """
[task.repository.linux.x86_64]
config_file: foobar-file-repository
substitutions: arg1, arg2, arg3
repo_components_to_update: *
repo_path: foo/bar/path
rta_key_list: key1, key2,key3 , key4
[task.offline.linux.x86_64.foobar]
config_file: foobar-file-repository-2
substitutions: arg1, arg2, arg3
repo_components_to_update: *
repo_path: foo/bar/path2
rta_key_list: key1, key2,key3 , key4
[task.offline.linux.x86_64]
config_file: foobar-file-offline
substitutions: arg11, arg21, arg31
rta_key_list: keyA, keyB
[task.online.linux.x86_64]
config_file: foobar-file-online
substitutions: arg12, arg22, arg32
rta_key_list: key12, key22
[foo.online.linux.x86_64]
config_file: foobar-file-online
substitutions: arg13, arg23, arg33
rta_key_list: key13, key23
"""
config = configparser.ConfigParser()
config.read_string(sample_config)
# parse all tasks i.e. no filters
tasks = release_task_reader.parse_data(config, task_filters=[])
self.assertTrue(len(tasks) == 4, "Did not parse all tasks from sample config")
# parse only "repository" tasks
tasks = release_task_reader.parse_data(config, task_filters=["repository"])
self.assertTrue(len(tasks) == 1)
self.assertEqual(tasks[0].is_repository_task(), True)
self.assertEqual(tasks[0].is_offline_installer_task(), False)
self.assertEqual(tasks[0].is_online_installer_task(), False)
self.assertEqual(tasks[0].get_config_file(), "foobar-file-repository")
self.assertEqual(tasks[0].get_substitutions(), "arg1, arg2, arg3")
self.assertEqual(tasks[0].get_installer_string_replacement_list(), ["arg1", "arg2", "arg3"])
self.assertEqual(tasks[0].get_repo_components_to_update(), "*")
self.assertEqual(tasks[0].get_repo_path(), "foo/bar/path")
self.assertEqual(sorted(tasks[0].get_rta_key_list()), sorted(["key1", "key2", "key3", "key4"]))
# parse only "offline" tasks with multiple filters
tasks = release_task_reader.parse_data(config, task_filters=["offline,linux,x86_64"])
self.assertTrue(len(tasks) == 2)
tasks = release_task_reader.parse_data(config, task_filters=["offline,linux,x86_64,foobar"])
self.assertTrue(len(tasks) == 1)
# parse "offline" tasks with multiple filters and "online" tasks
tasks = release_task_reader.parse_data(config, task_filters=["offline,linux,x86_64", "online,linux,x86_64"])
self.assertTrue(len(tasks) == 3)
@testhelpers.asyncio_test
async def test_release_task_reader_invalid_config(self) -> None:
sample_config = """
[task.repository]
config_file: foobar-file-repository
substitutions: arg1, arg2, arg3
repo_components_to_update: *
repo_path: foo/bar/path
rta_key_list: key1, key2
"""
config = configparser.ConfigParser()
config.read_string(sample_config)
with self.assertRaises(release_task_reader.ReleaseTaskError):
release_task_reader.parse_data(config, task_filters=[])
if __name__ == '__main__':
unittest.main()
|