1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. (HP)
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
21 from six.moves import configparser
24 from pbr.tests import base
28 def config_from_ini(ini):
30 if sys.version_info >= (3, 2):
31 parser = configparser.ConfigParser()
33 parser = configparser.SafeConfigParser()
34 ini = textwrap.dedent(six.u(ini))
35 parser.readfp(io.StringIO(ini))
36 for section in parser.sections():
37 config[section] = dict(parser.items(section))
41 class TestExtrasRequireParsingScenarios(base.BaseTestCase):
54 'expected_extra_requires': {
55 'first': ['foo', 'bar==1.0'],
56 'second': ['baz>=3.2', 'foo'],
57 'test': ['requests-mock'],
58 "test:(python_version=='2.6')": ['ordereddict'],
65 foo:python_version=='2.6'
67 baz<1.6 :python_version=='2.6'
68 zaz :python_version>'1.0'
70 'expected_extra_requires': {
71 "test:(python_version=='2.6')": ['foo', 'baz<1.6'],
72 "test": ['bar', 'zaz']}}),
76 long_description = foo
78 'expected_extra_requires':
82 def test_extras_parsing(self):
83 config = config_from_ini(self.config_text)
84 kwargs = util.setup_cfg_to_setup_kwargs(config)
86 self.assertEqual(self.expected_extra_requires,
87 kwargs['extras_require'])
90 class TestInvalidMarkers(base.BaseTestCase):
92 def test_invalid_marker_raises_error(self):
93 config = {'extras': {'test': "foo :bad_marker>'1.0'"}}
94 self.assertRaises(SyntaxError, util.setup_cfg_to_setup_kwargs, config)
97 class TestMapFieldsParsingScenarios(base.BaseTestCase):
100 ('simple_project_urls', {
104 Bug Tracker = https://bugs.launchpad.net/pbr/
105 Documentation = https://docs.openstack.org/pbr/
106 Source Code = https://git.openstack.org/cgit/openstack-dev/pbr/
108 'expected_project_urls': {
109 'Bug Tracker': 'https://bugs.launchpad.net/pbr/',
110 'Documentation': 'https://docs.openstack.org/pbr/',
111 'Source Code': 'https://git.openstack.org/cgit/openstack-dev/pbr/', # noqa: E501
114 ('query_parameters', {
118 Bug Tracker = https://bugs.launchpad.net/pbr/?query=true
119 Documentation = https://docs.openstack.org/pbr/?foo=bar
120 Source Code = https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hash
122 'expected_project_urls': {
123 'Bug Tracker': 'https://bugs.launchpad.net/pbr/?query=true',
124 'Documentation': 'https://docs.openstack.org/pbr/?foo=bar',
125 'Source Code': 'https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hash', # noqa: E501
130 def test_project_url_parsing(self):
131 config = config_from_ini(self.config_text)
132 kwargs = util.setup_cfg_to_setup_kwargs(config)
134 self.assertEqual(self.expected_project_urls, kwargs['project_urls'])
137 class TestKeywordsParsingScenarios(base.BaseTestCase):
148 'expected_keywords': ['one', 'two', 'three'],
151 ('inline_keywords', {
154 keywords = one, two, three
156 'expected_keywords': ['one, two, three'],
160 def test_keywords_parsing(self):
161 config = config_from_ini(self.config_text)
162 kwargs = util.setup_cfg_to_setup_kwargs(config)
164 self.assertEqual(self.expected_keywords, kwargs['keywords'])
167 class TestProvidesExtras(base.BaseTestCase):
168 def test_provides_extras(self):
171 provides_extras = foo
174 config = config_from_ini(ini)
175 kwargs = util.setup_cfg_to_setup_kwargs(config)
176 self.assertEqual(['foo', 'bar'], kwargs['provides_extras'])
179 class TestDataFilesParsing(base.BaseTestCase):
187 'dir with space/file with spc 2'
188 'dir with space/file with spc 1'
191 ('i like spaces/', ['dir with space/file with spc 2',
192 'dir with space/file with spc 1'])
196 def test_handling_of_whitespace_in_data_files(self):
197 config = config_from_ini(self.config_text)
198 kwargs = util.setup_cfg_to_setup_kwargs(config)
200 self.assertEqual(self.data_files,
201 list(kwargs['data_files']))
204 class TestUTF8DescriptionFile(base.BaseTestCase):
205 def test_utf8_description_file(self):
206 _, path = tempfile.mkstemp()
209 description_file = %s
211 # Two \n's because pbr strips the file content and adds \n\n
212 # This way we can use it directly as the assert comparison
213 unicode_description = u'UTF8 description: é"…-ʃŋ\'\n\n'
214 ini = ini_template % path
215 with io.open(path, 'w', encoding='utf8') as f:
216 f.write(unicode_description)
217 config = config_from_ini(ini)
218 kwargs = util.setup_cfg_to_setup_kwargs(config)
219 self.assertEqual(unicode_description, kwargs['long_description'])