summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-03 21:04:20 +0000
committerGerrit Code Review <review@openstack.org>2017-01-03 21:04:20 +0000
commit4c8bd90846bf4864f98c526659de5a7311ae192a (patch)
tree2efff2b83466f57ecec1423ec5019e7ff10e10b3
parent9fd7aa2cc7fe50f68bd9c86c3db7a8f7ae710c05 (diff)
parent8f1e6dc73fc4c1b119ad3b54ed317ca08b05994d (diff)
downloadpbr-4c8bd90846bf4864f98c526659de5a7311ae192a.tar.gz
Merge "Clean imports in code"
-rw-r--r--pbr/tests/test_hooks.py10
-rw-r--r--pbr/tests/test_integration.py46
-rw-r--r--pbr/util.py27
3 files changed, 44 insertions, 39 deletions
diff --git a/pbr/tests/test_hooks.py b/pbr/tests/test_hooks.py
index e355408..0759706 100644
--- a/pbr/tests/test_hooks.py
+++ b/pbr/tests/test_hooks.py
@@ -41,8 +41,8 @@
import os
import textwrap
-from testtools.content import text_content
-from testtools.matchers import Contains, EndsWith
+from testtools import content
+from testtools import matchers
from pbr.tests import base
from pbr.tests import util
@@ -85,16 +85,16 @@ class TestHooks(base.BaseTestCase):
assert return_code == 0
stdout, stderr, return_code = self.run_setup('build_ext')
- self.addDetailUniqueName('stderr', text_content(stderr))
+ self.addDetailUniqueName('stderr', content.text_content(stderr))
assert textwrap.dedent("""
running build_ext
running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext
build_ext pre-hook
""") in stdout # flake8: noqa
- self.expectThat(stdout, EndsWith('build_ext post-hook'))
+ self.expectThat(stdout, matchers.EndsWith('build_ext post-hook'))
assert return_code == 0
def test_custom_commands_known(self):
stdout, _, return_code = self.run_setup('--help-commands')
self.assertFalse(return_code)
- self.assertThat(stdout, Contains(" testr "))
+ self.assertThat(stdout, matchers.Contains(" testr "))
diff --git a/pbr/tests/test_integration.py b/pbr/tests/test_integration.py
index a3d393e..4a4d230 100644
--- a/pbr/tests/test_integration.py
+++ b/pbr/tests/test_integration.py
@@ -20,8 +20,7 @@ import testtools
import textwrap
from pbr.tests import base
-from pbr.tests.test_packaging import CreatePackages
-from pbr.tests.test_packaging import Venv
+from pbr.tests import test_packaging
PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', ''))
PIPVERSION = os.environ.get('PIPVERSION', 'pip')
@@ -91,23 +90,26 @@ class TestIntegration(base.BaseTestCase):
self.useFixture(base.CapturedSubprocess(
'clone',
['git', 'clone', os.path.join(REPODIR, self.short_name), path]))
- venv = self.useFixture(Venv('sdist',
- modules=['pip', 'wheel', PBRVERSION],
- pip_cmd=PIP_CMD))
+ venv = self.useFixture(
+ test_packaging.Venv('sdist',
+ modules=['pip', 'wheel', PBRVERSION],
+ pip_cmd=PIP_CMD))
python = venv.python
self.useFixture(base.CapturedSubprocess(
'sdist', [python, 'setup.py', 'sdist'], cwd=path))
- venv = self.useFixture(Venv('tarball',
- modules=['pip', 'wheel', PBRVERSION],
- pip_cmd=PIP_CMD))
+ venv = self.useFixture(
+ test_packaging.Venv('tarball',
+ modules=['pip', 'wheel', PBRVERSION],
+ pip_cmd=PIP_CMD))
python = venv.python
filename = os.path.join(
path, 'dist', os.listdir(os.path.join(path, 'dist'))[0])
self.useFixture(base.CapturedSubprocess(
'tarball', [python] + PIP_CMD + [filename]))
- venv = self.useFixture(Venv('install-git',
- modules=['pip', 'wheel', PBRVERSION],
- pip_cmd=PIP_CMD))
+ venv = self.useFixture(
+ test_packaging.Venv('install-git',
+ modules=['pip', 'wheel', PBRVERSION],
+ pip_cmd=PIP_CMD))
root = venv.path
python = venv.python
self.useFixture(base.CapturedSubprocess(
@@ -118,9 +120,10 @@ class TestIntegration(base.BaseTestCase):
if 'migrate.cfg' in filenames:
found = True
self.assertTrue(found)
- venv = self.useFixture(Venv('install-e',
- modules=['pip', 'wheel', PBRVERSION],
- pip_cmd=PIP_CMD))
+ venv = self.useFixture(
+ test_packaging.Venv('install-e',
+ modules=['pip', 'wheel', PBRVERSION],
+ pip_cmd=PIP_CMD))
root = venv.path
python = venv.python
self.useFixture(base.CapturedSubprocess(
@@ -167,14 +170,15 @@ class TestInstallWithoutPbr(base.BaseTestCase):
print("FakeTest loaded and ran")
""")},
}
- pkg_dirs = self.useFixture(CreatePackages(pkgs)).package_dirs
+ pkg_dirs = self.useFixture(
+ test_packaging.CreatePackages(pkgs)).package_dirs
test_pkg_dir = pkg_dirs['pkgTest']
req_pkg_dir = pkg_dirs['pkgReq']
self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
allow_fail=False, cwd=req_pkg_dir)
# A venv to test within
- venv = self.useFixture(Venv('nopbr', ['pip', 'wheel']))
+ venv = self.useFixture(test_packaging.Venv('nopbr', ['pip', 'wheel']))
python = venv.python
# Run the depending script
self.useFixture(base.CapturedSubprocess(
@@ -205,10 +209,11 @@ class TestMarkersPip(base.BaseTestCase):
'pkg_a': {},
'pkg_b': {},
}
- pkg_dirs = self.useFixture(CreatePackages(pkgs)).package_dirs
+ pkg_dirs = self.useFixture(
+ test_packaging.CreatePackages(pkgs)).package_dirs
temp_dir = self.useFixture(fixtures.TempDir()).path
repo_dir = os.path.join(temp_dir, 'repo')
- venv = self.useFixture(Venv('markers'))
+ venv = self.useFixture(test_packaging.Venv('markers'))
bin_python = venv.python
os.mkdir(repo_dir)
for module in self.modules:
@@ -254,7 +259,8 @@ class TestLTSSupport(base.BaseTestCase):
if (sys.version_info[0] == 3 and not self.py3support):
self.skipTest('This combination will not install with py3, '
'skipping test')
- venv = self.useFixture(Venv('setuptools', modules=self.modules))
+ venv = self.useFixture(
+ test_packaging.Venv('setuptools', modules=self.modules))
bin_python = venv.python
pbr = 'file://%s#egg=pbr' % PBR_ROOT
# Installing PBR is a reasonable indication that we are not broken on
@@ -281,7 +287,7 @@ class TestSphinxWarnErrors(base.BaseTestCase):
os.environ.get('PBR_INTEGRATION', None) == '1',
'integration tests not enabled')
def test_sphinx_runs(self):
- venv = self.useFixture(Venv('sphinx'))
+ venv = self.useFixture(test_packaging.Venv('sphinx'))
bin_python = venv.python
self._run_cmd(bin_python, ['-m', 'pip', 'install', self.module],
cwd=venv.path, allow_fail=False)
diff --git a/pbr/util.py b/pbr/util.py
index 22f83b6..a117785 100644
--- a/pbr/util.py
+++ b/pbr/util.py
@@ -72,11 +72,10 @@ import distutils.ccompiler
import pkg_resources
from distutils import log
-from distutils.errors import (DistutilsOptionError, DistutilsModuleError,
- DistutilsFileError)
+from distutils import errors
from setuptools.command.egg_info import manifest_maker
-from setuptools.dist import Distribution
-from setuptools.extension import Extension
+from setuptools import dist as st_dist
+from setuptools import extension
try:
import ConfigParser as configparser
@@ -208,8 +207,8 @@ def cfg_to_args(path='setup.cfg', script_args=()):
else:
parser = configparser.SafeConfigParser()
if not os.path.exists(path):
- raise DistutilsFileError("file '%s' does not exist" %
- os.path.abspath(path))
+ raise errors.DistutilsFileError("file '%s' does not exist" %
+ os.path.abspath(path))
parser.read(path)
config = {}
for section in parser.sections():
@@ -367,7 +366,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()):
else:
prev = data_files[key.strip()] = value.split()
elif firstline:
- raise DistutilsOptionError(
+ raise errors.DistutilsOptionError(
'malformed package_data first line %r (misses '
'"=")' % line)
else:
@@ -380,7 +379,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()):
in_cfg_value = data_files
elif arg == 'cmdclass':
cmdclass = {}
- dist = Distribution()
+ dist = st_dist.Distribution()
for cls_name in in_cfg_value:
cls = resolve_name(cls_name)
cmd = cls(dist)
@@ -534,8 +533,8 @@ def get_extension_modules(config):
if ext_args:
if 'name' not in ext_args:
ext_args['name'] = labels[1]
- ext_modules.append(Extension(ext_args.pop('name'),
- **ext_args))
+ ext_modules.append(extension.Extension(ext_args.pop('name'),
+ **ext_args))
return ext_modules
@@ -554,7 +553,7 @@ def get_entry_points(config):
def wrap_commands(kwargs):
- dist = Distribution()
+ dist = st_dist.Distribution()
# This should suffice to get the same config values and command classes
# that the actual Distribution will see (not counting cmdclass, which is
@@ -630,13 +629,13 @@ def run_command_hooks(cmd_obj, hook_kind):
hook_obj = resolve_name(hook)
except ImportError:
err = sys.exc_info()[1] # For py3k
- raise DistutilsModuleError('cannot find hook %s: %s' %
- (hook,err))
+ raise errors.DistutilsModuleError('cannot find hook %s: %s' %
+ (hook,err))
else:
hook_obj = hook
if not hasattr(hook_obj, '__call__'):
- raise DistutilsOptionError('hook %r is not callable' % hook)
+ raise errors.DistutilsOptionError('hook %r is not callable' % hook)
log.info('running %s %s for command %s',
hook_kind, hook, cmd_obj.get_command_name())