blob: dbf1809c20a6a784e2660f426579002644d5bccb [file] [log] [blame]
Matthew Treinish32d35702013-08-13 11:59:06 -04001# 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
17import os
18import shutil
19import subprocess
20import tempfile
Matthew Treinish87086212013-10-28 20:21:54 +000021
22from tempest.tests import base
Matthew Treinish32d35702013-08-13 11:59:06 -040023
Matthew Treinish32d35702013-08-13 11:59:06 -040024DEVNULL = open(os.devnull, 'wb')
25
26
Matthew Treinish87086212013-10-28 20:21:54 +000027class TestWrappers(base.TestCase):
Matthew Treinish32d35702013-08-13 11:59:06 -040028 def setUp(self):
29 super(TestWrappers, self).setUp()
30 # Setup test dirs
31 self.directory = tempfile.mkdtemp(prefix='tempest-unit')
32 self.test_dir = os.path.join(self.directory, 'tests')
33 os.mkdir(self.test_dir)
34 # Setup Test files
35 self.testr_conf_file = os.path.join(self.directory, '.testr.conf')
36 self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg')
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)
47
Matthew Treinish32d35702013-08-13 11:59:06 -040048 def test_pretty_tox(self):
49 # Copy wrapper script and requirements:
50 pretty_tox = os.path.join(self.directory, 'pretty_tox.sh')
51 shutil.copy('tools/pretty_tox.sh', pretty_tox)
52 # Change directory, run wrapper and check result
53 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
54 os.chdir(self.directory)
55 # Git init is required for the pbr testr command. pbr requires a git
56 # version or an sdist to work. so make the test directory a git repo
57 # too.
58 subprocess.call(['git', 'init'])
59 exit_code = subprocess.call('sh pretty_tox.sh tests.passing',
60 shell=True, stdout=DEVNULL, stderr=DEVNULL)
Chang Bo Guofc77e932013-09-16 17:38:26 -070061 self.assertEqual(exit_code, 0)
Matthew Treinish32d35702013-08-13 11:59:06 -040062
Matthew Treinish32d35702013-08-13 11:59:06 -040063 def test_pretty_tox_fails(self):
64 # Copy wrapper script and requirements:
65 pretty_tox = os.path.join(self.directory, 'pretty_tox.sh')
66 shutil.copy('tools/pretty_tox.sh', pretty_tox)
67 # Change directory, run wrapper and check result
68 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
69 os.chdir(self.directory)
70 # Git init is required for the pbr testr command. pbr requires a git
71 # version or an sdist to work. so make the test directory a git repo
72 # too.
73 subprocess.call(['git', 'init'])
74 exit_code = subprocess.call('sh pretty_tox.sh', shell=True,
75 stdout=DEVNULL, stderr=DEVNULL)
Chang Bo Guofc77e932013-09-16 17:38:26 -070076 self.assertEqual(exit_code, 1)
Matthew Treinish32d35702013-08-13 11:59:06 -040077
Matthew Treinish32d35702013-08-13 11:59:06 -040078 def test_pretty_tox_serial(self):
79 # Copy wrapper script and requirements:
80 pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh')
81 shutil.copy('tools/pretty_tox_serial.sh', pretty_tox)
82 # Change directory, run wrapper and check result
83 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
84 os.chdir(self.directory)
85 exit_code = subprocess.call('sh pretty_tox_serial.sh tests.passing',
86 shell=True, stdout=DEVNULL, stderr=DEVNULL)
Chang Bo Guofc77e932013-09-16 17:38:26 -070087 self.assertEqual(exit_code, 0)
Matthew Treinish32d35702013-08-13 11:59:06 -040088
Matthew Treinish32d35702013-08-13 11:59:06 -040089 def test_pretty_tox_serial_fails(self):
90 # Copy wrapper script and requirements:
91 pretty_tox = os.path.join(self.directory, 'pretty_tox_serial.sh')
92 shutil.copy('tools/pretty_tox_serial.sh', pretty_tox)
93 # Change directory, run wrapper and check result
94 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
95 os.chdir(self.directory)
96 exit_code = subprocess.call('sh pretty_tox_serial.sh', shell=True,
97 stdout=DEVNULL, stderr=DEVNULL)
Chang Bo Guofc77e932013-09-16 17:38:26 -070098 self.assertEqual(exit_code, 1)