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 | |
| 23 | from tempest.test import attr |
| 24 | |
| 25 | DEVNULL = open(os.devnull, 'wb') |
| 26 | |
| 27 | |
| 28 | class TestWrappers(testtools.TestCase): |
| 29 | def setUp(self): |
| 30 | super(TestWrappers, self).setUp() |
| 31 | # Setup test dirs |
| 32 | self.directory = tempfile.mkdtemp(prefix='tempest-unit') |
| 33 | self.test_dir = os.path.join(self.directory, 'tests') |
| 34 | os.mkdir(self.test_dir) |
| 35 | # Setup Test files |
| 36 | self.testr_conf_file = os.path.join(self.directory, '.testr.conf') |
| 37 | self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg') |
| 38 | self.passing_file = os.path.join(self.test_dir, 'test_passing.py') |
| 39 | self.failing_file = os.path.join(self.test_dir, 'test_failing.py') |
| 40 | self.init_file = os.path.join(self.test_dir, '__init__.py') |
| 41 | self.setup_py = os.path.join(self.directory, 'setup.py') |
| 42 | shutil.copy('tempest/tests/files/testr-conf', self.testr_conf_file) |
| 43 | shutil.copy('tempest/tests/files/passing-tests', self.passing_file) |
| 44 | shutil.copy('tempest/tests/files/failing-tests', self.failing_file) |
| 45 | shutil.copy('setup.py', self.setup_py) |
| 46 | shutil.copy('tempest/tests/files/setup.cfg', self.setup_cfg_file) |
| 47 | shutil.copy('tempest/tests/files/__init__.py', self.init_file) |
| 48 | |
| 49 | @attr(type='smoke') |
| 50 | def test_pretty_tox(self): |
| 51 | # Copy wrapper script and requirements: |
| 52 | pretty_tox = os.path.join(self.directory, 'pretty_tox.sh') |
| 53 | shutil.copy('tools/pretty_tox.sh', pretty_tox) |
| 54 | # Change directory, run wrapper and check result |
| 55 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 56 | os.chdir(self.directory) |
| 57 | # Git init is required for the pbr testr command. pbr requires a git |
| 58 | # version or an sdist to work. so make the test directory a git repo |
| 59 | # too. |
| 60 | subprocess.call(['git', 'init']) |
| 61 | exit_code = subprocess.call('sh pretty_tox.sh tests.passing', |
| 62 | shell=True, stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 63 | self.assertEqual(exit_code, 0) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 64 | |
| 65 | @attr(type='smoke') |
| 66 | def test_pretty_tox_fails(self): |
| 67 | # Copy wrapper script and requirements: |
| 68 | pretty_tox = os.path.join(self.directory, 'pretty_tox.sh') |
| 69 | shutil.copy('tools/pretty_tox.sh', pretty_tox) |
| 70 | # Change directory, run wrapper and check result |
| 71 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 72 | os.chdir(self.directory) |
| 73 | # Git init is required for the pbr testr command. pbr requires a git |
| 74 | # version or an sdist to work. so make the test directory a git repo |
| 75 | # too. |
| 76 | subprocess.call(['git', 'init']) |
| 77 | exit_code = subprocess.call('sh pretty_tox.sh', shell=True, |
| 78 | stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 79 | self.assertEqual(exit_code, 1) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 80 | |
| 81 | @attr(type='smoke') |
| 82 | def test_pretty_tox_serial(self): |
| 83 | # Copy wrapper script and requirements: |
| 84 | pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh') |
| 85 | shutil.copy('tools/pretty_tox_serial.sh', pretty_tox) |
| 86 | # Change directory, run wrapper and check result |
| 87 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 88 | os.chdir(self.directory) |
| 89 | exit_code = subprocess.call('sh pretty_tox_serial.sh tests.passing', |
| 90 | shell=True, stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 91 | self.assertEqual(exit_code, 0) |
Matthew Treinish | 32d3570 | 2013-08-13 11:59:06 -0400 | [diff] [blame] | 92 | |
| 93 | @attr(type='smoke') |
| 94 | def test_pretty_tox_serial_fails(self): |
| 95 | # Copy wrapper script and requirements: |
| 96 | pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh') |
| 97 | shutil.copy('tools/pretty_tox_serial.sh', pretty_tox) |
| 98 | # Change directory, run wrapper and check result |
| 99 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 100 | os.chdir(self.directory) |
| 101 | exit_code = subprocess.call('sh pretty_tox_serial.sh', shell=True, |
| 102 | stdout=DEVNULL, stderr=DEVNULL) |
Chang Bo Guo | fc77e93 | 2013-09-16 17:38:26 -0700 | [diff] [blame] | 103 | self.assertEqual(exit_code, 1) |