second try
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / tests / test_files.py
1 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
2 # All Rights Reserved.
3 #
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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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
14 # under the License.
15
16 from __future__ import print_function
17
18 import os
19
20 import fixtures
21
22 from pbr.hooks import files
23 from pbr.tests import base
24
25
26 class FilesConfigTest(base.BaseTestCase):
27
28     def setUp(self):
29         super(FilesConfigTest, self).setUp()
30
31         pkg_fixture = fixtures.PythonPackage(
32             "fake_package", [
33                 ("fake_module.py", b""),
34                 ("other_fake_module.py", b""),
35             ])
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',
42                                       'more spaces')
43         pkg_sub = os.path.join(pkg_etc, 'sub')
44         subpackage = os.path.join(
45             pkg_fixture.base, 'fake_package', 'subpackage')
46         os.makedirs(pkg_sub)
47         os.makedirs(subpackage)
48         os.makedirs(pkg_ansible)
49         os.makedirs(dir_spcs)
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")
63
64         self.useFixture(base.DiveDir(pkg_fixture.base))
65
66     def test_implicit_auto_package(self):
67         config = dict(
68             files=dict(
69             )
70         )
71         files.FilesConfig(config, 'fake_package').run()
72         self.assertIn('subpackage', config['files']['packages'])
73
74     def test_auto_package(self):
75         config = dict(
76             files=dict(
77                 packages='fake_package',
78             )
79         )
80         files.FilesConfig(config, 'fake_package').run()
81         self.assertIn('subpackage', config['files']['packages'])
82
83     def test_data_files_globbing(self):
84         config = dict(
85             files=dict(
86                 data_files="\n  etc/pbr = etc/*"
87             )
88         )
89         files.FilesConfig(config, 'fake_package').run()
90         self.assertIn(
91             "\n'etc/pbr/' = \n 'etc/foo'\n'etc/pbr/sub' = \n 'etc/sub/bar'",
92             config['files']['data_files'])
93
94     def test_data_files_with_spaces(self):
95         config = dict(
96             files=dict(
97                 data_files="\n  'i like spaces' = 'dir with space'/*"
98             )
99         )
100         files.FilesConfig(config, 'fake_package').run()
101         self.assertIn(
102             "\n'i like spaces/' = \n 'dir with space/file with spc'",
103             config['files']['data_files'])
104
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'/*"
108         expected = (
109             "\n'one space/two space/' = "
110             "\n 'multi space/more spaces/file with spc'")
111         config = dict(
112             files=dict(
113                 data_files=data_files
114             )
115         )
116         files.FilesConfig(config, 'fake_package').run()
117         self.assertIn(expected, config['files']['data_files'])
118
119     def test_data_files_with_spaces_quoted_components(self):
120         # test that we can quote individual path components
121         data_files = (
122             "\n'one space'/'two space' = 'multi space'/'more spaces'/*"
123         )
124         expected = ("\n'one space/two space/' = "
125                     "\n 'multi space/more spaces/file with spc'")
126         config = dict(
127             files=dict(
128                 data_files=data_files
129             )
130         )
131         files.FilesConfig(config, 'fake_package').run()
132         self.assertIn(expected, config['files']['data_files'])
133
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"
137         config = dict(
138             files=dict(
139                 data_files="\n  share/ansible = ansible/*"
140             )
141         )
142         files.FilesConfig(config, 'fake_package').run()
143         self.assertIn(
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'])