test_core.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 sys
  43. import tarfile
  44. import fixtures
  45. from pbr.tests import base
  46. class TestCore(base.BaseTestCase):
  47. cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class')
  48. def check_script_install(self, install_stdout):
  49. for cmd_name in self.cmd_names:
  50. install_txt = 'Installing %s script to %s' % (cmd_name,
  51. self.temp_dir)
  52. self.assertIn(install_txt, install_stdout)
  53. cmd_filename = os.path.join(self.temp_dir, cmd_name)
  54. script_txt = open(cmd_filename, 'r').read()
  55. self.assertNotIn('pkg_resources', script_txt)
  56. stdout, _, return_code = self._run_cmd(cmd_filename)
  57. self.assertIn("PBR", stdout)
  58. def test_setup_py_keywords(self):
  59. """setup.py --keywords.
  60. Test that the `./setup.py --keywords` command returns the correct
  61. value without balking.
  62. """
  63. self.run_setup('egg_info')
  64. stdout, _, _ = self.run_setup('--keywords')
  65. assert stdout == 'packaging, distutils, setuptools'
  66. def test_sdist_extra_files(self):
  67. """Test that the extra files are correctly added."""
  68. stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
  69. # There can be only one
  70. try:
  71. tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
  72. except IndexError:
  73. assert False, 'source dist not found'
  74. tf = tarfile.open(tf_path)
  75. names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
  76. self.assertIn('extra-file.txt', names)
  77. def test_console_script_install(self):
  78. """Test that we install a non-pkg-resources console script."""
  79. if os.name == 'nt':
  80. self.skipTest('Windows support is passthrough')
  81. stdout, _, return_code = self.run_setup(
  82. 'install_scripts', '--install-dir=%s' % self.temp_dir)
  83. self.useFixture(
  84. fixtures.EnvironmentVariable('PYTHONPATH', '.'))
  85. self.check_script_install(stdout)
  86. def test_console_script_develop(self):
  87. """Test that we develop a non-pkg-resources console script."""
  88. if sys.version_info < (3, 0):
  89. self.skipTest(
  90. 'Fails with recent virtualenv due to '
  91. 'https://github.com/pypa/virtualenv/issues/1638'
  92. )
  93. if os.name == 'nt':
  94. self.skipTest('Windows support is passthrough')
  95. self.useFixture(
  96. fixtures.EnvironmentVariable(
  97. 'PYTHONPATH', ".:%s" % self.temp_dir))
  98. stdout, _, return_code = self.run_setup(
  99. 'develop', '--install-dir=%s' % self.temp_dir)
  100. self.check_script_install(stdout)
  101. class TestGitSDist(base.BaseTestCase):
  102. def setUp(self):
  103. super(TestGitSDist, self).setUp()
  104. stdout, _, return_code = self._run_cmd('git', ('init',))
  105. if return_code:
  106. self.skipTest("git not installed")
  107. stdout, _, return_code = self._run_cmd('git', ('add', '.'))
  108. stdout, _, return_code = self._run_cmd(
  109. 'git', ('commit', '-m', 'Turn this into a git repo'))
  110. stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
  111. def test_sdist_git_extra_files(self):
  112. """Test that extra files found in git are correctly added."""
  113. # There can be only one
  114. tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
  115. tf = tarfile.open(tf_path)
  116. names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
  117. self.assertIn('git-extra-file.txt', names)