set default python to python3

Set the default python to python3 except for the py27 environment. We
have to set that explicitly to override the new default.

Because flake8 now runs under python 3 there is no built-in name
'file'. Instead we can use the same symbols from the io module to
build the spec for mocking out the open() call. The old version of
that code that used to only run under python 3 used a private version
of the io module, so that is also corrected.

Change-Id: I2491e65736d2c79f1134eec6371967c39873891b
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-04-13 16:12:50 -04:00
parent a943629f85
commit cda1daf83c
2 changed files with 10 additions and 9 deletions

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import mock
import requests
import six
@ -500,16 +502,12 @@ class RequestsTransportTest(base.TestCase):
if six.PY3:
builtin_open = 'builtins.open'
open_mock = mock.MagicMock(name='file_handle',
spec=open)
import _io
file_spec = list(set(dir(_io.TextIOWrapper)).union(
set(dir(_io.BytesIO))))
else:
builtin_open = '__builtin__.open'
open_mock = mock.MagicMock(name='file_handle',
spec=file)
file_spec = file
open_mock = mock.MagicMock(name='file_handle',
spec=open)
file_spec = list(set(dir(io.TextIOWrapper)).union(
set(dir(io.BytesIO))))
file_handle = mock.MagicMock(spec=file_spec)
file_handle.write.return_value = None

View File

@ -3,6 +3,7 @@ minversion = 2.0
envlist = py35,py27,pep8
[testenv]
basepython = python3
install_command = pip install {opts} {packages}
whitelist_externals = find
rm
@ -12,6 +13,9 @@ deps =
-r{toxinidir}/requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:py27]
basepython = python2.7
[testenv:pep8]
commands =
flake8
@ -64,7 +68,6 @@ commands = pip-missing-reqs -d --ignore-module=oslo_vmware* --ignore-file=oslo_v
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
[testenv:lower-constraints]
basepython = python3
deps =
-c{toxinidir}/lower-constraints.txt
-r{toxinidir}/test-requirements.txt