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