diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-10-28 01:13:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-10-28 01:13:31 +0000 |
commit | e8a3c7e7ba4430870849ff34ab3437db2ed1f942 (patch) | |
tree | 2e69468b7f75b7b4c071124cbcc06d226e3a3997 | |
parent | a3a875b1a0eee25344d8d6a8898ee176d3dc46b3 (diff) | |
parent | 1f730e25803c9a263c147c1a35415ee8b2b49e5e (diff) | |
download | pbr-0.5.22.tar.gz |
Merge "Move base test case logic out of __init__.py"0.5.22
-rw-r--r-- | pbr/tests/__init__.py | 133 | ||||
-rw-r--r-- | pbr/tests/base.py | 133 | ||||
-rw-r--r-- | pbr/tests/test_commands.py | 4 | ||||
-rw-r--r-- | pbr/tests/test_core.py | 6 | ||||
-rw-r--r-- | pbr/tests/test_files.py | 6 | ||||
-rw-r--r-- | pbr/tests/test_hooks.py | 4 | ||||
-rw-r--r-- | pbr/tests/test_packaging.py | 8 | ||||
-rw-r--r-- | pbr/tests/test_setup.py | 18 | ||||
-rw-r--r-- | pbr/tests/test_version.py | 4 |
9 files changed, 158 insertions, 158 deletions
diff --git a/pbr/tests/__init__.py b/pbr/tests/__init__.py index 778b026..e69de29 100644 --- a/pbr/tests/__init__.py +++ b/pbr/tests/__init__.py @@ -1,133 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010-2011 OpenStack Foundation -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# Copyright (C) 2013 Association of Universities for Research in Astronomy -# (AURA) -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# 3. The name of AURA and its representatives may not be used to -# endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - -"""Common utilities used in testing""" - -import os -import shutil -import subprocess -import sys - -import fixtures -import testresources -import testtools - -from pbr import packaging - - -class DiveDir(fixtures.Fixture): - """Dive into given directory and return back on cleanup. - - :ivar path: The target directory. - """ - - def __init__(self, path): - self.path = path - - def setUp(self): - super(DiveDir, self).setUp() - self.addCleanup(os.chdir, os.getcwd()) - os.chdir(self.path) - - -class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase): - - def setUp(self): - super(BaseTestCase, self).setUp() - test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30) - try: - test_timeout = int(test_timeout) - except ValueError: - # If timeout value is invalid, fail hard. - print("OS_TEST_TIMEOUT set to invalid value" - " defaulting to no timeout") - test_timeout = 0 - if test_timeout > 0: - self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) - - if os.environ.get('OS_STDOUT_CAPTURE') in packaging.TRUE_VALUES: - stdout = self.useFixture(fixtures.StringStream('stdout')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if os.environ.get('OS_STDERR_CAPTURE') in packaging.TRUE_VALUES: - stderr = self.useFixture(fixtures.StringStream('stderr')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - self.log_fixture = self.useFixture( - fixtures.FakeLogger('pbr')) - - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.FakeLogger()) - self.useFixture(fixtures.EnvironmentVariable('PBR_VERSION', '0.0')) - - self.temp_dir = self.useFixture(fixtures.TempDir()).path - self.package_dir = os.path.join(self.temp_dir, 'testpackage') - shutil.copytree(os.path.join(os.path.dirname(__file__), 'testpackage'), - self.package_dir) - self.addCleanup(os.chdir, os.getcwd()) - os.chdir(self.package_dir) - self.addCleanup(self._discard_testpackage) - - def _discard_testpackage(self): - # Remove pbr.testpackage from sys.modules so that it can be freshly - # re-imported by the next test - for k in list(sys.modules): - if (k == 'pbr_testpackage' or - k.startswith('pbr_testpackage.')): - del sys.modules[k] - - def run_setup(self, *args): - return self._run_cmd(sys.executable, ('setup.py',) + args) - - def _run_cmd(self, cmd, args=[]): - """Run a command in the root of the test working copy. - - Runs a command, with the given argument list, in the root of the test - working copy--returns the stdout and stderr streams and the exit code - from the subprocess. - """ - - os.chdir(self.package_dir) - p = subprocess.Popen([cmd] + list(args), stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - - streams = tuple(s.decode('latin1').strip() for s in p.communicate()) - for line in streams: - print(line) - return (streams) + (p.returncode,) diff --git a/pbr/tests/base.py b/pbr/tests/base.py new file mode 100644 index 0000000..778b026 --- /dev/null +++ b/pbr/tests/base.py @@ -0,0 +1,133 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 OpenStack Foundation +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# Copyright (C) 2013 Association of Universities for Research in Astronomy +# (AURA) +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of AURA and its representatives may not be used to +# endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + +"""Common utilities used in testing""" + +import os +import shutil +import subprocess +import sys + +import fixtures +import testresources +import testtools + +from pbr import packaging + + +class DiveDir(fixtures.Fixture): + """Dive into given directory and return back on cleanup. + + :ivar path: The target directory. + """ + + def __init__(self, path): + self.path = path + + def setUp(self): + super(DiveDir, self).setUp() + self.addCleanup(os.chdir, os.getcwd()) + os.chdir(self.path) + + +class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase): + + def setUp(self): + super(BaseTestCase, self).setUp() + test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30) + try: + test_timeout = int(test_timeout) + except ValueError: + # If timeout value is invalid, fail hard. + print("OS_TEST_TIMEOUT set to invalid value" + " defaulting to no timeout") + test_timeout = 0 + if test_timeout > 0: + self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) + + if os.environ.get('OS_STDOUT_CAPTURE') in packaging.TRUE_VALUES: + stdout = self.useFixture(fixtures.StringStream('stdout')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) + if os.environ.get('OS_STDERR_CAPTURE') in packaging.TRUE_VALUES: + stderr = self.useFixture(fixtures.StringStream('stderr')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) + self.log_fixture = self.useFixture( + fixtures.FakeLogger('pbr')) + + self.useFixture(fixtures.NestedTempfile()) + self.useFixture(fixtures.FakeLogger()) + self.useFixture(fixtures.EnvironmentVariable('PBR_VERSION', '0.0')) + + self.temp_dir = self.useFixture(fixtures.TempDir()).path + self.package_dir = os.path.join(self.temp_dir, 'testpackage') + shutil.copytree(os.path.join(os.path.dirname(__file__), 'testpackage'), + self.package_dir) + self.addCleanup(os.chdir, os.getcwd()) + os.chdir(self.package_dir) + self.addCleanup(self._discard_testpackage) + + def _discard_testpackage(self): + # Remove pbr.testpackage from sys.modules so that it can be freshly + # re-imported by the next test + for k in list(sys.modules): + if (k == 'pbr_testpackage' or + k.startswith('pbr_testpackage.')): + del sys.modules[k] + + def run_setup(self, *args): + return self._run_cmd(sys.executable, ('setup.py',) + args) + + def _run_cmd(self, cmd, args=[]): + """Run a command in the root of the test working copy. + + Runs a command, with the given argument list, in the root of the test + working copy--returns the stdout and stderr streams and the exit code + from the subprocess. + """ + + os.chdir(self.package_dir) + p = subprocess.Popen([cmd] + list(args), stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + streams = tuple(s.decode('latin1').strip() for s in p.communicate()) + for line in streams: + print(line) + return (streams) + (p.returncode,) diff --git a/pbr/tests/test_commands.py b/pbr/tests/test_commands.py index f5831fa..c73a9f3 100644 --- a/pbr/tests/test_commands.py +++ b/pbr/tests/test_commands.py @@ -40,10 +40,10 @@ from testtools import content -from pbr import tests +from pbr.tests import base -class TestCommands(tests.BaseTestCase): +class TestCommands(base.BaseTestCase): def test_custom_build_py_command(self): """Test custom build_py command. diff --git a/pbr/tests/test_core.py b/pbr/tests/test_core.py index dd21e6f..1d1272a 100644 --- a/pbr/tests/test_core.py +++ b/pbr/tests/test_core.py @@ -44,10 +44,10 @@ import tarfile import fixtures -from pbr import tests +from pbr.tests import base -class TestCore(tests.BaseTestCase): +class TestCore(base.BaseTestCase): cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class') @@ -122,7 +122,7 @@ class TestCore(tests.BaseTestCase): self.check_script_install(stdout) -class TestGitSDist(tests.BaseTestCase): +class TestGitSDist(base.BaseTestCase): def setUp(self): super(TestGitSDist, self).setUp() diff --git a/pbr/tests/test_files.py b/pbr/tests/test_files.py index 3805339..d9cf3e5 100644 --- a/pbr/tests/test_files.py +++ b/pbr/tests/test_files.py @@ -22,10 +22,10 @@ import os import fixtures from pbr.hooks import files -from pbr import tests +from pbr.tests import base -class FilesConfigTest(tests.BaseTestCase): +class FilesConfigTest(base.BaseTestCase): def setUp(self): super(FilesConfigTest, self).setUp() @@ -49,7 +49,7 @@ class FilesConfigTest(tests.BaseTestCase): with open(os.path.join(subpackage, "__init__.py"), 'w') as foo_file: foo_file.write("# empty") - self.useFixture(tests.DiveDir(pkg_fixture.base)) + self.useFixture(base.DiveDir(pkg_fixture.base)) def test_implicit_auto_package(self): config = dict( diff --git a/pbr/tests/test_hooks.py b/pbr/tests/test_hooks.py index 491f8dd..b9e874a 100644 --- a/pbr/tests/test_hooks.py +++ b/pbr/tests/test_hooks.py @@ -43,11 +43,11 @@ import textwrap from testtools.matchers import Contains -from pbr import tests +from pbr.tests import base from pbr.tests import util -class TestHooks(tests.BaseTestCase): +class TestHooks(base.BaseTestCase): def setUp(self): super(TestHooks, self).setUp() with util.open_config( diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index dcb9c65..4922026 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -42,10 +42,10 @@ import os import fixtures -from pbr import tests +from pbr.tests import base -class TestPackagingInGitRepoWithCommit(tests.BaseTestCase): +class TestPackagingInGitRepoWithCommit(base.BaseTestCase): def setUp(self): super(TestPackagingInGitRepoWithCommit, self).setUp() @@ -71,7 +71,7 @@ class TestPackagingInGitRepoWithCommit(tests.BaseTestCase): self.assertNotEqual(body, '') -class TestPackagingInGitRepoWithoutCommit(tests.BaseTestCase): +class TestPackagingInGitRepoWithoutCommit(base.BaseTestCase): def setUp(self): super(TestPackagingInGitRepoWithoutCommit, self).setUp() @@ -93,7 +93,7 @@ class TestPackagingInGitRepoWithoutCommit(tests.BaseTestCase): self.assertEqual(body, '') -class TestPackagingInPlainDirectory(tests.BaseTestCase): +class TestPackagingInPlainDirectory(base.BaseTestCase): def setUp(self): super(TestPackagingInPlainDirectory, self).setUp() diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py index 189bd51..93d3cdf 100644 --- a/pbr/tests/test_setup.py +++ b/pbr/tests/test_setup.py @@ -33,10 +33,10 @@ import fixtures import testscenarios from pbr import packaging -from pbr import tests +from pbr.tests import base -class EmailTestCase(tests.BaseTestCase): +class EmailTestCase(base.BaseTestCase): def test_str_dict_replace(self): string = 'Johnnie T. Hozer' @@ -45,7 +45,7 @@ class EmailTestCase(tests.BaseTestCase): packaging.canonicalize_emails(string, mapping)) -class MailmapTestCase(tests.BaseTestCase): +class MailmapTestCase(base.BaseTestCase): def setUp(self): super(MailmapTestCase, self).setUp() @@ -71,7 +71,7 @@ class MailmapTestCase(tests.BaseTestCase): packaging.read_git_mailmap(self.root_dir)) -class SkipFileWrites(tests.BaseTestCase): +class SkipFileWrites(base.BaseTestCase): scenarios = [ ('changelog_option_true', @@ -135,7 +135,7 @@ class SkipFileWrites(tests.BaseTestCase): or self.env_value is not None)) -class GitLogsTest(tests.BaseTestCase): +class GitLogsTest(base.BaseTestCase): def setUp(self): super(GitLogsTest, self).setUp() @@ -212,7 +212,7 @@ class GitLogsTest(tests.BaseTestCase): self.assertTrue(co_author in authors) -class BuildSphinxTest(tests.BaseTestCase): +class BuildSphinxTest(base.BaseTestCase): scenarios = [ ('true_autodoc_caps', @@ -238,7 +238,7 @@ class BuildSphinxTest(tests.BaseTestCase): pkg_fixture = fixtures.PythonPackage( "fake_package", [("fake_module.py", b"")]) self.useFixture(pkg_fixture) - self.useFixture(tests.DiveDir(pkg_fixture.base)) + self.useFixture(base.DiveDir(pkg_fixture.base)) def test_build_doc(self): if self.has_opt: @@ -254,7 +254,7 @@ class BuildSphinxTest(tests.BaseTestCase): "api/fake_package.fake_module.rst") == self.has_autodoc) -class ParseRequirementsTest(tests.BaseTestCase): +class ParseRequirementsTest(base.BaseTestCase): def setUp(self): super(ParseRequirementsTest, self).setUp() @@ -331,7 +331,7 @@ class ParseRequirementsTest(tests.BaseTestCase): packaging.parse_requirements([self.tmp_file])) -class ParseDependencyLinksTest(tests.BaseTestCase): +class ParseDependencyLinksTest(base.BaseTestCase): def setUp(self): super(ParseDependencyLinksTest, self).setUp() diff --git a/pbr/tests/test_version.py b/pbr/tests/test_version.py index 7ef908b..e220d03 100644 --- a/pbr/tests/test_version.py +++ b/pbr/tests/test_version.py @@ -15,11 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -from pbr import tests +from pbr.tests import base from pbr import version -class DeferredVersionTestCase(tests.BaseTestCase): +class DeferredVersionTestCase(base.BaseTestCase): def test_cached_version(self): class MyVersionInfo(version.VersionInfo): |