1 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Copyright (C) 2013 Association of Universities for Research in Astronomy
19 # Redistribution and use in source and binary forms, with or without
20 # modification, are permitted provided that the following conditions are met:
22 # 1. Redistributions of source code must retain the above copyright
23 # notice, this list of conditions and the following disclaimer.
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.
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.
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
47 from pbr.tests import base
50 class TestCore(base.BaseTestCase):
52 cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class')
54 def check_script_install(self, install_stdout):
55 for cmd_name in self.cmd_names:
56 install_txt = 'Installing %s script to %s' % (cmd_name,
58 self.assertIn(install_txt, install_stdout)
60 cmd_filename = os.path.join(self.temp_dir, cmd_name)
62 script_txt = open(cmd_filename, 'r').read()
63 self.assertNotIn('pkg_resources', script_txt)
65 stdout, _, return_code = self._run_cmd(cmd_filename)
66 self.assertIn("PBR", stdout)
68 def test_setup_py_keywords(self):
69 """setup.py --keywords.
71 Test that the `./setup.py --keywords` command returns the correct
72 value without balking.
75 self.run_setup('egg_info')
76 stdout, _, _ = self.run_setup('--keywords')
77 assert stdout == 'packaging, distutils, setuptools'
79 def test_setup_py_build_sphinx(self):
80 stdout, _, return_code = self.run_setup('build_sphinx')
81 self.assertEqual(0, return_code)
83 def test_sdist_extra_files(self):
84 """Test that the extra files are correctly added."""
86 stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
88 # There can be only one
90 tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
92 assert False, 'source dist not found'
94 tf = tarfile.open(tf_path)
95 names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
97 self.assertIn('extra-file.txt', names)
99 def test_console_script_install(self):
100 """Test that we install a non-pkg-resources console script."""
103 self.skipTest('Windows support is passthrough')
105 stdout, _, return_code = self.run_setup(
106 'install_scripts', '--install-dir=%s' % self.temp_dir)
109 fixtures.EnvironmentVariable('PYTHONPATH', '.'))
111 self.check_script_install(stdout)
113 def test_console_script_develop(self):
114 """Test that we develop a non-pkg-resources console script."""
117 self.skipTest('Windows support is passthrough')
120 fixtures.EnvironmentVariable(
121 'PYTHONPATH', ".:%s" % self.temp_dir))
123 stdout, _, return_code = self.run_setup(
124 'develop', '--install-dir=%s' % self.temp_dir)
126 self.check_script_install(stdout)
129 class TestGitSDist(base.BaseTestCase):
132 super(TestGitSDist, self).setUp()
134 stdout, _, return_code = self._run_cmd('git', ('init',))
136 self.skipTest("git not installed")
138 stdout, _, return_code = self._run_cmd('git', ('add', '.'))
139 stdout, _, return_code = self._run_cmd(
140 'git', ('commit', '-m', 'Turn this into a git repo'))
142 stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
144 def test_sdist_git_extra_files(self):
145 """Test that extra files found in git are correctly added."""
146 # There can be only one
147 tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
148 tf = tarfile.open(tf_path)
149 names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
151 self.assertIn('git-extra-file.txt', names)