test_core.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. # implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # Copyright (C) 2013 Association of Universities for Research in Astronomy
  17. # (AURA)
  18. #
  19. # Redistribution and use in source and binary forms, with or without
  20. # modification, are permitted provided that the following conditions are met:
  21. #
  22. # 1. Redistributions of source code must retain the above copyright
  23. # notice, this list of conditions and the following disclaimer.
  24. #
  25. # 2. Redistributions in binary form must reproduce the above
  26. # copyright notice, this list of conditions and the following
  27. # disclaimer in the documentation and/or other materials provided
  28. # with the distribution.
  29. #
  30. # 3. The name of AURA and its representatives may not be used to
  31. # endorse or promote products derived from this software without
  32. # specific prior written permission.
  33. #
  34. # THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED
  35. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  36. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37. # DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT,
  38. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  39. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. import glob
  41. import os
  42. import tarfile
  43. import fixtures
  44. from pbr.tests import base
  45. class TestCore(base.BaseTestCase):
  46. cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class')
  47. def check_script_install(self, install_stdout):
  48. for cmd_name in self.cmd_names:
  49. install_txt = 'Installing %s script to %s' % (cmd_name,
  50. self.temp_dir)
  51. self.assertIn(install_txt, install_stdout)
  52. cmd_filename = os.path.join(self.temp_dir, cmd_name)
  53. script_txt = open(cmd_filename, 'r').read()
  54. self.assertNotIn('pkg_resources', script_txt)
  55. stdout, _, return_code = self._run_cmd(cmd_filename)
  56. self.assertIn("PBR", stdout)
  57. def test_setup_py_keywords(self):
  58. """setup.py --keywords.
  59. Test that the `./setup.py --keywords` command returns the correct
  60. value without balking.
  61. """
  62. self.run_setup('egg_info')
  63. stdout, _, _ = self.run_setup('--keywords')
  64. assert stdout == 'packaging,distutils,setuptools'
  65. def test_setup_py_build_sphinx(self):
  66. stdout, _, return_code = self.run_setup('build_sphinx')
  67. self.assertEqual(0, return_code)
  68. def test_sdist_extra_files(self):
  69. """Test that the extra files are correctly added."""
  70. stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
  71. # There can be only one
  72. try:
  73. tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
  74. except IndexError:
  75. assert False, 'source dist not found'
  76. tf = tarfile.open(tf_path)
  77. names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
  78. self.assertIn('extra-file.txt', names)
  79. def test_console_script_install(self):
  80. """Test that we install a non-pkg-resources console script."""
  81. if os.name == 'nt':
  82. self.skipTest('Windows support is passthrough')
  83. stdout, _, return_code = self.run_setup(
  84. 'install_scripts', '--install-dir=%s' % self.temp_dir)
  85. self.useFixture(
  86. fixtures.EnvironmentVariable('PYTHONPATH', '.'))
  87. self.check_script_install(stdout)
  88. def test_console_script_develop(self):
  89. """Test that we develop a non-pkg-resources console script."""
  90. if os.name == 'nt':
  91. self.skipTest('Windows support is passthrough')
  92. self.useFixture(
  93. fixtures.EnvironmentVariable(
  94. 'PYTHONPATH', ".:%s" % self.temp_dir))
  95. stdout, _, return_code = self.run_setup(
  96. 'develop', '--install-dir=%s' % self.temp_dir)
  97. self.check_script_install(stdout)
  98. class TestGitSDist(base.BaseTestCase):
  99. def setUp(self):
  100. super(TestGitSDist, self).setUp()
  101. stdout, _, return_code = self._run_cmd('git', ('init',))
  102. if return_code:
  103. self.skipTest("git not installed")
  104. stdout, _, return_code = self._run_cmd('git', ('add', '.'))
  105. stdout, _, return_code = self._run_cmd(
  106. 'git', ('commit', '-m', 'Turn this into a git repo'))
  107. stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
  108. def test_sdist_git_extra_files(self):
  109. """Test that extra files found in git are correctly added."""
  110. # There can be only one
  111. tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
  112. tf = tarfile.open(tf_path)
  113. names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
  114. self.assertIn('git-extra-file.txt', names)