test_files.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. from __future__ import print_function
  16. import os
  17. import fixtures
  18. from pbr.hooks import files
  19. from pbr.tests import base
  20. class FilesConfigTest(base.BaseTestCase):
  21. def setUp(self):
  22. super(FilesConfigTest, self).setUp()
  23. pkg_fixture = fixtures.PythonPackage(
  24. "fake_package", [
  25. ("fake_module.py", b""),
  26. ("other_fake_module.py", b""),
  27. ])
  28. self.useFixture(pkg_fixture)
  29. pkg_etc = os.path.join(pkg_fixture.base, 'etc')
  30. pkg_sub = os.path.join(pkg_etc, 'sub')
  31. subpackage = os.path.join(
  32. pkg_fixture.base, 'fake_package', 'subpackage')
  33. os.makedirs(pkg_sub)
  34. os.makedirs(subpackage)
  35. with open(os.path.join(pkg_etc, "foo"), 'w') as foo_file:
  36. foo_file.write("Foo Data")
  37. with open(os.path.join(pkg_sub, "bar"), 'w') as foo_file:
  38. foo_file.write("Bar Data")
  39. with open(os.path.join(subpackage, "__init__.py"), 'w') as foo_file:
  40. foo_file.write("# empty")
  41. self.useFixture(base.DiveDir(pkg_fixture.base))
  42. def test_implicit_auto_package(self):
  43. config = dict(
  44. files=dict(
  45. )
  46. )
  47. files.FilesConfig(config, 'fake_package').run()
  48. self.assertIn('subpackage', config['files']['packages'])
  49. def test_auto_package(self):
  50. config = dict(
  51. files=dict(
  52. packages='fake_package',
  53. )
  54. )
  55. files.FilesConfig(config, 'fake_package').run()
  56. self.assertIn('subpackage', config['files']['packages'])
  57. def test_data_files_globbing(self):
  58. config = dict(
  59. files=dict(
  60. data_files="\n etc/pbr = etc/*"
  61. )
  62. )
  63. files.FilesConfig(config, 'fake_package').run()
  64. self.assertIn(
  65. '\netc/pbr/ = \n etc/foo\netc/pbr/sub = \n etc/sub/bar',
  66. config['files']['data_files'])