second try
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / tests / test_core.py
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
41 import glob
42 import os
43 import tarfile
44
45 import fixtures
46
47 from pbr.tests import base
48
49
50 class TestCore(base.BaseTestCase):
51
52     cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class')
53
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,
57                                                           self.temp_dir)
58             self.assertIn(install_txt, install_stdout)
59
60             cmd_filename = os.path.join(self.temp_dir, cmd_name)
61
62             script_txt = open(cmd_filename, 'r').read()
63             self.assertNotIn('pkg_resources', script_txt)
64
65             stdout, _, return_code = self._run_cmd(cmd_filename)
66             self.assertIn("PBR", stdout)
67
68     def test_setup_py_keywords(self):
69         """setup.py --keywords.
70
71         Test that the `./setup.py --keywords` command returns the correct
72         value without balking.
73         """
74
75         self.run_setup('egg_info')
76         stdout, _, _ = self.run_setup('--keywords')
77         assert stdout == 'packaging, distutils, setuptools'
78
79     def test_setup_py_build_sphinx(self):
80         stdout, _, return_code = self.run_setup('build_sphinx')
81         self.assertEqual(0, return_code)
82
83     def test_sdist_extra_files(self):
84         """Test that the extra files are correctly added."""
85
86         stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
87
88         # There can be only one
89         try:
90             tf_path = glob.glob(os.path.join('dist', '*.tar.gz'))[0]
91         except IndexError:
92             assert False, 'source dist not found'
93
94         tf = tarfile.open(tf_path)
95         names = ['/'.join(p.split('/')[1:]) for p in tf.getnames()]
96
97         self.assertIn('extra-file.txt', names)
98
99     def test_console_script_install(self):
100         """Test that we install a non-pkg-resources console script."""
101
102         if os.name == 'nt':
103             self.skipTest('Windows support is passthrough')
104
105         stdout, _, return_code = self.run_setup(
106             'install_scripts', '--install-dir=%s' % self.temp_dir)
107
108         self.useFixture(
109             fixtures.EnvironmentVariable('PYTHONPATH', '.'))
110
111         self.check_script_install(stdout)
112
113     def test_console_script_develop(self):
114         """Test that we develop a non-pkg-resources console script."""
115
116         if os.name == 'nt':
117             self.skipTest('Windows support is passthrough')
118
119         self.useFixture(
120             fixtures.EnvironmentVariable(
121                 'PYTHONPATH', ".:%s" % self.temp_dir))
122
123         stdout, _, return_code = self.run_setup(
124             'develop', '--install-dir=%s' % self.temp_dir)
125
126         self.check_script_install(stdout)
127
128
129 class TestGitSDist(base.BaseTestCase):
130
131     def setUp(self):
132         super(TestGitSDist, self).setUp()
133
134         stdout, _, return_code = self._run_cmd('git', ('init',))
135         if return_code:
136             self.skipTest("git not installed")
137
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'))
141
142         stdout, _, return_code = self.run_setup('sdist', '--formats=gztar')
143
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()]
150
151         self.assertIn('git-extra-file.txt', names)