More python3 compatibility.
* pbr/packaging.py: Properly convert bytes into unicode strings and back to bytes again. Replace os.path.walk() with os.walk(). * pbr/tests/__init__.py: Remove use of mox. * pbr/tests/moxstubout.py: Remove use of mox. * pbr/tests/test_setup.py: Use bytestrings instead of str or unicode when performing IO. * pbr/tests/test_version.py: Remove use of oslo.config. * requirements.txt: Pin jinja2 to version compatible with python3.2. * test-requirements.txt: Remove oslo.config and mox. Change-Id: I9b5a32d7204fa2af56ecf4fdcf6b6da3bbb03200
This commit is contained in:
parent
e7b90361b9
commit
b18913e577
@ -136,7 +136,7 @@ def _run_shell_command(cmd, throw_on_error=False):
|
||||
return None
|
||||
if len(out[0].strip()) == 0:
|
||||
return None
|
||||
return out[0].strip()
|
||||
return out[0].strip().decode('utf-8')
|
||||
|
||||
|
||||
def _get_git_directory():
|
||||
@ -163,8 +163,9 @@ def write_git_changelog(git_dir=None, dest_dir=os.path.curdir,
|
||||
git_log_cmd = 'git --git-dir=%s log' % git_dir
|
||||
changelog = _run_shell_command(git_log_cmd)
|
||||
mailmap = read_git_mailmap(git_dir)
|
||||
with open(new_changelog, "w") as changelog_file:
|
||||
changelog_file.write(canonicalize_emails(changelog, mailmap))
|
||||
with open(new_changelog, "wb") as changelog_file:
|
||||
changelog_file.write(canonicalize_emails(
|
||||
changelog, mailmap).encode('utf-8'))
|
||||
|
||||
|
||||
def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()):
|
||||
@ -194,11 +195,12 @@ def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()):
|
||||
changelog = "\n".join((changelog, new_entries))
|
||||
|
||||
mailmap = read_git_mailmap(git_dir)
|
||||
with open(new_authors, 'w') as new_authors_fh:
|
||||
new_authors_fh.write(canonicalize_emails(changelog, mailmap))
|
||||
with open(new_authors, 'wb') as new_authors_fh:
|
||||
new_authors_fh.write(canonicalize_emails(
|
||||
changelog, mailmap).encode('utf-8'))
|
||||
if os.path.exists(old_authors):
|
||||
with open(old_authors, "r") as old_authors_fh:
|
||||
new_authors_fh.write('\n' + old_authors_fh.read())
|
||||
with open(old_authors, "rb") as old_authors_fh:
|
||||
new_authors_fh.write(b'\n' + old_authors_fh.read())
|
||||
|
||||
|
||||
_rst_template = """%(heading)s
|
||||
@ -262,8 +264,9 @@ try:
|
||||
os.makedirs(source_dir)
|
||||
for pkg in self.distribution.packages:
|
||||
if '.' not in pkg:
|
||||
os.path.walk(pkg, _find_modules, modules)
|
||||
module_list = modules.keys()
|
||||
for dirpath, dirnames, files in os.walk(pkg):
|
||||
_find_modules(modules, dirpath, files)
|
||||
module_list = list(modules.keys())
|
||||
module_list.sort()
|
||||
autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
|
||||
with open(autoindex_filename, 'w') as autoindex:
|
||||
|
@ -23,7 +23,6 @@ import testresources
|
||||
import testtools
|
||||
|
||||
from pbr import packaging
|
||||
from pbr.tests import moxstubout
|
||||
|
||||
|
||||
class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
||||
@ -52,4 +51,3 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
||||
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
self.useFixture(fixtures.FakeLogger())
|
||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
||||
|
@ -1,37 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import fixtures
|
||||
import mox
|
||||
import stubout
|
||||
|
||||
|
||||
class MoxStubout(fixtures.Fixture):
|
||||
"""Deal with code around mox and stubout as a fixture."""
|
||||
|
||||
def setUp(self):
|
||||
super(MoxStubout, self).setUp()
|
||||
# emulate some of the mox stuff, we can't use the metaclass
|
||||
# because it screws with our generators
|
||||
self.mox = mox.Mox()
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
self.addCleanup(self.mox.UnsetStubs)
|
||||
self.addCleanup(self.stubs.UnsetAll)
|
||||
self.addCleanup(self.stubs.SmartUnsetAll)
|
||||
self.addCleanup(self.mox.VerifyAll)
|
@ -160,7 +160,8 @@ class GitLogsTest(tests.BaseTestCase):
|
||||
"os.path.exists",
|
||||
lambda path: os.path.abspath(path) in exist_files))
|
||||
self.useFixture(fixtures.FakePopen(lambda _: {
|
||||
"stdout": six.StringIO("Author: Foo Bar <email@bar.com>\n")
|
||||
"stdout": six.BytesIO("Author: Foo Bar "
|
||||
"<email@bar.com>\n".encode('utf-8'))
|
||||
}))
|
||||
|
||||
def _fake_read_git_mailmap(*args):
|
||||
@ -178,8 +179,8 @@ class GitLogsTest(tests.BaseTestCase):
|
||||
def _fake_log_output(self, cmd, mapping):
|
||||
for (k, v) in mapping.items():
|
||||
if cmd.startswith(k):
|
||||
return v
|
||||
return ""
|
||||
return v.encode('utf-8')
|
||||
return b""
|
||||
|
||||
def test_generate_authors(self):
|
||||
author_old = "Foo Foo <email@foo.com>"
|
||||
@ -201,7 +202,7 @@ class GitLogsTest(tests.BaseTestCase):
|
||||
lambda path: os.path.abspath(path) in exist_files))
|
||||
|
||||
self.useFixture(fixtures.FakePopen(lambda proc_args: {
|
||||
"stdout": six.StringIO(
|
||||
"stdout": six.BytesIO(
|
||||
self._fake_log_output(proc_args["args"][2], cmd_map))
|
||||
}))
|
||||
|
||||
@ -242,7 +243,7 @@ class BuildSphinxTest(tests.BaseTestCase):
|
||||
self.distr.command_options["build_sphinx"] = {
|
||||
"source_dir": ["a", "."]}
|
||||
pkg_fixture = fixtures.PythonPackage(
|
||||
"fake_package", [("fake_module.py", "")])
|
||||
"fake_package", [("fake_module.py", b"")])
|
||||
self.useFixture(pkg_fixture)
|
||||
self.useFixture(DiveDir(pkg_fixture.base))
|
||||
|
||||
|
@ -15,21 +15,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from d2to1.extern import six
|
||||
from oslo.config import cfg
|
||||
|
||||
from pbr import tests
|
||||
from pbr import version
|
||||
|
||||
|
||||
class DeferredVersionTestCase(tests.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DeferredVersionTestCase, self).setUp()
|
||||
self.conf = cfg.ConfigOpts()
|
||||
|
||||
def test_cached_version(self):
|
||||
class MyVersionInfo(version.VersionInfo):
|
||||
def _get_version_from_pkg_resources(self):
|
||||
@ -37,39 +28,4 @@ class DeferredVersionTestCase(tests.BaseTestCase):
|
||||
|
||||
deferred_string = MyVersionInfo("openstack").\
|
||||
cached_version_string()
|
||||
self.conf([], project="project", prog="prog", version=deferred_string)
|
||||
self.assertEquals("5.5.5.5", str(self.conf.version))
|
||||
|
||||
def test_print_cached_version(self):
|
||||
class MyVersionInfo(version.VersionInfo):
|
||||
def _get_version_from_pkg_resources(self):
|
||||
return "5.5.5.5"
|
||||
|
||||
deferred_string = MyVersionInfo("openstack")\
|
||||
.cached_version_string()
|
||||
self.stubs.Set(sys, 'stderr', six.StringIO())
|
||||
self.assertRaises(SystemExit,
|
||||
self.conf, ['--version'],
|
||||
project="project",
|
||||
prog="prog",
|
||||
version=deferred_string)
|
||||
self.assertEquals("5.5.5.5", sys.stderr.getvalue().strip())
|
||||
|
||||
def test_print_cached_version_with_long_string(self):
|
||||
my_version = "11111222223333344444555556666677777888889999900000"
|
||||
|
||||
class MyVersionInfo(version.VersionInfo):
|
||||
def _get_version_from_pkg_resources(self):
|
||||
return my_version
|
||||
|
||||
deferred_string = MyVersionInfo("openstack")\
|
||||
.cached_version_string()
|
||||
|
||||
for i in range(50):
|
||||
self.stubs.Set(sys, 'stderr', six.StringIO())
|
||||
self.assertRaises(SystemExit,
|
||||
self.conf, ['--version'],
|
||||
project="project",
|
||||
prog="prog",
|
||||
version=deferred_string)
|
||||
self.assertEquals(my_version, sys.stderr.getvalue().strip())
|
||||
self.assertEquals("5.5.5.5", deferred_string)
|
||||
|
@ -1,3 +1,4 @@
|
||||
jinja2<2.7
|
||||
d2to1>=0.2.10,<0.3
|
||||
distribute
|
||||
setuptools_git>=0.4
|
||||
|
@ -2,8 +2,6 @@ coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.12
|
||||
flake8
|
||||
mox
|
||||
oslo.config
|
||||
python-subunit
|
||||
sphinx>=1.1.2
|
||||
testrepository>=0.0.13
|
||||
|
Loading…
x
Reference in New Issue
Block a user