Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import os |
| 18 | import shutil |
| 19 | import subprocess |
| 20 | import tempfile |
| 21 | import testtools |
| 22 | |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 23 | DEVNULL = open(os.devnull, 'wb') |
| 24 | |
| 25 | |
| 26 | class TestWrappers(testtools.TestCase): |
| 27 | def setUp(self): |
| 28 | super(TestWrappers, self).setUp() |
| 29 | # Setup test dirs |
| 30 | self.directory = tempfile.mkdtemp(prefix='tempest-unit') |
| 31 | self.test_dir = os.path.join(self.directory, 'tests') |
| 32 | os.mkdir(self.test_dir) |
| 33 | # Setup Test files |
| 34 | self.testr_conf_file = os.path.join(self.directory, '.testr.conf') |
| 35 | self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg') |
| 36 | self.passing_file = os.path.join(self.test_dir, 'test_passing.py') |
| 37 | self.failing_file = os.path.join(self.test_dir, 'test_failing.py') |
| 38 | self.init_file = os.path.join(self.test_dir, '__init__.py') |
| 39 | self.setup_py = os.path.join(self.directory, 'setup.py') |
| 40 | shutil.copy('tempest/tests/files/testr-conf', self.testr_conf_file) |
| 41 | shutil.copy('tempest/tests/files/passing-tests', self.passing_file) |
| 42 | shutil.copy('tempest/tests/files/failing-tests', self.failing_file) |
| 43 | shutil.copy('setup.py', self.setup_py) |
| 44 | shutil.copy('tempest/tests/files/setup.cfg', self.setup_cfg_file) |
| 45 | shutil.copy('tempest/tests/files/__init__.py', self.init_file) |
| 46 | |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 47 | def test_pretty_tox(self): |
| 48 | # Copy wrapper script and requirements: |
| 49 | pretty_tox = os.path.join(self.directory, 'pretty_tox.sh') |
| 50 | shutil.copy('tools/pretty_tox.sh', pretty_tox) |
| 51 | # Change directory, run wrapper and check result |
| 52 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 53 | os.chdir(self.directory) |
| 54 | # Git init is required for the pbr testr command. pbr requires a git |
| 55 | # version or an sdist to work. so make the test directory a git repo |
| 56 | # too. |
| 57 | subprocess.call(['git', 'init']) |
| 58 | exit_code = subprocess.call('sh pretty_tox.sh tests.passing', |
| 59 | shell=True, stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 60 | self.assertEqual(exit_code, 0) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 61 | |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 62 | def test_pretty_tox_fails(self): |
| 63 | # Copy wrapper script and requirements: |
| 64 | pretty_tox = os.path.join(self.directory, 'pretty_tox.sh') |
| 65 | shutil.copy('tools/pretty_tox.sh', pretty_tox) |
| 66 | # Change directory, run wrapper and check result |
| 67 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 68 | os.chdir(self.directory) |
| 69 | # Git init is required for the pbr testr command. pbr requires a git |
| 70 | # version or an sdist to work. so make the test directory a git repo |
| 71 | # too. |
| 72 | subprocess.call(['git', 'init']) |
| 73 | exit_code = subprocess.call('sh pretty_tox.sh', shell=True, |
| 74 | stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 75 | self.assertEqual(exit_code, 1) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 76 | |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 77 | def test_pretty_tox_serial(self): |
| 78 | # Copy wrapper script and requirements: |
| 79 | pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh') |
| 80 | shutil.copy('tools/pretty_tox_serial.sh', pretty_tox) |
| 81 | # Change directory, run wrapper and check result |
| 82 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 83 | os.chdir(self.directory) |
| 84 | exit_code = subprocess.call('sh pretty_tox_serial.sh tests.passing', |
| 85 | shell=True, stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 86 | self.assertEqual(exit_code, 0) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 87 | |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 88 | def test_pretty_tox_serial_fails(self): |
| 89 | # Copy wrapper script and requirements: |
| 90 | pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh') |
| 91 | shutil.copy('tools/pretty_tox_serial.sh', pretty_tox) |
| 92 | # Change directory, run wrapper and check result |
| 93 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 94 | os.chdir(self.directory) |
| 95 | exit_code = subprocess.call('sh pretty_tox_serial.sh', shell=True, |
| 96 | stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 97 | self.assertEqual(exit_code, 1) |