1 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
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
16 from __future__ import print_function
22 from pbr.hooks import files
23 from pbr.tests import base
26 class FilesConfigTest(base.BaseTestCase):
29 super(FilesConfigTest, self).setUp()
31 pkg_fixture = fixtures.PythonPackage(
33 ("fake_module.py", b""),
34 ("other_fake_module.py", b""),
36 self.useFixture(pkg_fixture)
37 pkg_etc = os.path.join(pkg_fixture.base, 'etc')
38 pkg_ansible = os.path.join(pkg_fixture.base, 'ansible',
39 'kolla-ansible', 'test')
40 dir_spcs = os.path.join(pkg_fixture.base, 'dir with space')
41 dir_subdir_spc = os.path.join(pkg_fixture.base, 'multi space',
43 pkg_sub = os.path.join(pkg_etc, 'sub')
44 subpackage = os.path.join(
45 pkg_fixture.base, 'fake_package', 'subpackage')
47 os.makedirs(subpackage)
48 os.makedirs(pkg_ansible)
50 os.makedirs(dir_subdir_spc)
51 with open(os.path.join(pkg_etc, "foo"), 'w') as foo_file:
52 foo_file.write("Foo Data")
53 with open(os.path.join(pkg_sub, "bar"), 'w') as foo_file:
54 foo_file.write("Bar Data")
55 with open(os.path.join(pkg_ansible, "baz"), 'w') as baz_file:
56 baz_file.write("Baz Data")
57 with open(os.path.join(subpackage, "__init__.py"), 'w') as foo_file:
58 foo_file.write("# empty")
59 with open(os.path.join(dir_spcs, "file with spc"), 'w') as spc_file:
60 spc_file.write("# empty")
61 with open(os.path.join(dir_subdir_spc, "file with spc"), 'w') as file_:
62 file_.write("# empty")
64 self.useFixture(base.DiveDir(pkg_fixture.base))
66 def test_implicit_auto_package(self):
71 files.FilesConfig(config, 'fake_package').run()
72 self.assertIn('subpackage', config['files']['packages'])
74 def test_auto_package(self):
77 packages='fake_package',
80 files.FilesConfig(config, 'fake_package').run()
81 self.assertIn('subpackage', config['files']['packages'])
83 def test_data_files_globbing(self):
86 data_files="\n etc/pbr = etc/*"
89 files.FilesConfig(config, 'fake_package').run()
91 "\n'etc/pbr/' = \n 'etc/foo'\n'etc/pbr/sub' = \n 'etc/sub/bar'",
92 config['files']['data_files'])
94 def test_data_files_with_spaces(self):
97 data_files="\n 'i like spaces' = 'dir with space'/*"
100 files.FilesConfig(config, 'fake_package').run()
102 "\n'i like spaces/' = \n 'dir with space/file with spc'",
103 config['files']['data_files'])
105 def test_data_files_with_spaces_subdirectories(self):
106 # test that we can handle whitespace in subdirectories
107 data_files = "\n 'one space/two space' = 'multi space/more spaces'/*"
109 "\n'one space/two space/' = "
110 "\n 'multi space/more spaces/file with spc'")
113 data_files=data_files
116 files.FilesConfig(config, 'fake_package').run()
117 self.assertIn(expected, config['files']['data_files'])
119 def test_data_files_with_spaces_quoted_components(self):
120 # test that we can quote individual path components
122 "\n'one space'/'two space' = 'multi space'/'more spaces'/*"
124 expected = ("\n'one space/two space/' = "
125 "\n 'multi space/more spaces/file with spc'")
128 data_files=data_files
131 files.FilesConfig(config, 'fake_package').run()
132 self.assertIn(expected, config['files']['data_files'])
134 def test_data_files_globbing_source_prefix_in_directory_name(self):
135 # We want to test that the string, "docs", is not replaced in a
136 # subdirectory name, "sub-docs"
139 data_files="\n share/ansible = ansible/*"
142 files.FilesConfig(config, 'fake_package').run()
144 "\n'share/ansible/' = "
145 "\n'share/ansible/kolla-ansible' = "
146 "\n'share/ansible/kolla-ansible/test' = "
147 "\n 'ansible/kolla-ansible/test/baz'",
148 config['files']['data_files'])