From 58de317f8487a20768da6deafe2d2a7aa3ebcc1d Mon Sep 17 00:00:00 2001 From: Victor Sergeyev Date: Thu, 13 Nov 2014 14:41:29 +0200 Subject: [PATCH] Improve testing in py3 environment Change-Id: I1d169f0a87d4251778b32e80b3627b407340fec8 --- oslo/concurrency/processutils.py | 2 +- tests/unit/test_processutils.py | 10 +++++----- tox.ini | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/oslo/concurrency/processutils.py b/oslo/concurrency/processutils.py index 4a388b6..1f8718b 100644 --- a/oslo/concurrency/processutils.py +++ b/oslo/concurrency/processutils.py @@ -181,7 +181,7 @@ def execute(*cmd, **kwargs): 'specify a root helper.')) cmd = shlex.split(root_helper) + list(cmd) - cmd = map(str, cmd) + cmd = [str(c) for c in cmd] sanitized_cmd = strutils.mask_password(' '.join(cmd)) while attempts > 0: diff --git a/tests/unit/test_processutils.py b/tests/unit/test_processutils.py index 17bec9e..d77e9ba 100644 --- a/tests/unit/test_processutils.py +++ b/tests/unit/test_processutils.py @@ -142,7 +142,7 @@ exit 1 self.assertRaises(processutils.ProcessExecutionError, processutils.execute, tmpfilename, tmpfilename2, attempts=10, - process_input='foo', + process_input=b'foo', delay_on_retry=False) fp = open(tmpfilename2, 'r') runs = fp.read() @@ -199,7 +199,7 @@ grep foo os.chmod(tmpfilename, 0o755) processutils.execute(tmpfilename, tmpfilename2, - process_input='foo', + process_input=b'foo', attempts=2) finally: os.unlink(tmpfilename) @@ -295,7 +295,7 @@ grep foo out, err = processutils.execute('/usr/bin/env', env_variables=env_vars) - self.assertIn('SUPER_UNIQUE_VAR=The answer is 42', out) + self.assertIn(b'SUPER_UNIQUE_VAR=The answer is 42', out) def test_exception_and_masking(self): tmpfilename = self.create_tempfiles( @@ -314,8 +314,8 @@ grep foo 'something') self.assertEqual(38, err.exit_code) - self.assertEqual(err.stdout, 'onstdout --password="***"\n') - self.assertEqual(err.stderr, 'onstderr --password="***"\n') + self.assertIn('onstdout --password="***"', err.stdout) + self.assertIn('onstderr --password="***"', err.stderr) self.assertEqual(err.cmd, ' '.join([tmpfilename, 'password="***"', 'something'])) diff --git a/tox.ini b/tox.ini index 2f1a852..fca4498 100644 --- a/tox.ini +++ b/tox.ini @@ -23,13 +23,13 @@ commands = deps = -r{toxinidir}/requirements-py3.txt -r{toxinidir}/test-requirements.txt commands = - lockutils-wrapper python -m testtools.run tests.unit.test_lockutils + lockutils-wrapper python setup.py testr --slowest --testr-args='{posargs}' [testenv:py34] deps = -r{toxinidir}/requirements-py3.txt -r{toxinidir}/test-requirements.txt commands = - lockutils-wrapper python -m testtools.run tests.unit.test_lockutils + lockutils-wrapper python setup.py testr --slowest --testr-args='{posargs}' [testenv:pep8] commands = flake8