mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 12:12:47 +00:00
Correct Python version incompatibilities.
This commit is contained in:
parent
06d82db0e4
commit
a8514c4dda
6 changed files with 33 additions and 9 deletions
|
@ -876,7 +876,9 @@ def get_script_path(scriptname):
|
|||
return scriptpath
|
||||
|
||||
|
||||
def mkdir_p(path, mode=0777):
|
||||
# 511 is 777 in octal. Python 2 and Python 3 disagree about the right
|
||||
# way to represent octal numbers.
|
||||
def mkdir_p(path, mode=511):
|
||||
try:
|
||||
os.makedirs(path, mode)
|
||||
except OSError as e:
|
||||
|
|
|
@ -61,7 +61,7 @@ def dictionary_override(d1, d2):
|
|||
if PY2:
|
||||
overrides = d1.items() + d2.items()
|
||||
else:
|
||||
overrides = d1.items() | d2.items()
|
||||
overrides = list(d1.items()) + list(d2.items())
|
||||
return dict(overrides)
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class Releaser(ConfigObject):
|
|||
ConfigObject.__init__(self, config=config)
|
||||
config_builder_args = self._parse_builder_args(releaser_config, target)
|
||||
if test:
|
||||
config_builder_args['test'] = True # builder must know to build from HEAD
|
||||
config_builder_args['test'] = [True] # builder must know to build from HEAD
|
||||
|
||||
# Override with builder args from command line if any were given:
|
||||
if 'builder_args' in kwargs:
|
||||
|
|
|
@ -22,7 +22,7 @@ import tempfile
|
|||
|
||||
from os.path import join
|
||||
|
||||
from tito.common import run_command, tito_config_dir
|
||||
from tito.common import run_command
|
||||
from tito.compat import * # NOQA
|
||||
from functional.fixture import TitoGitTestFixture, tito
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
# in this software or its documentation.
|
||||
|
||||
from contextlib import contextmanager
|
||||
from mock import mock_open, patch
|
||||
from StringIO import StringIO
|
||||
from mock import patch, MagicMock
|
||||
from tito.compat import PY2, StringIO
|
||||
|
||||
file_spec = None
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
@ -21,9 +23,29 @@ def open_mock(content, **kwargs):
|
|||
"""Mock's mock_open only supports read() and write() which is not very useful.
|
||||
This context manager adds support for getting the value of what was written out
|
||||
and for iterating through a file line by line."""
|
||||
|
||||
global file_spec
|
||||
if file_spec is None:
|
||||
# set on first use
|
||||
if PY2:
|
||||
file_spec = file
|
||||
else:
|
||||
import _io
|
||||
file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
|
||||
|
||||
m = MagicMock(name='open', spec=open)
|
||||
|
||||
handle = MagicMock(spec=file_spec)
|
||||
handle.__enter__.return_value = handle
|
||||
m.return_value = handle
|
||||
|
||||
content_out = StringIO()
|
||||
m = mock_open()
|
||||
with patch('__builtin__.open', m, create=True, **kwargs) as mo:
|
||||
|
||||
if PY2:
|
||||
patch_module = "__builtin__.open"
|
||||
else:
|
||||
patch_module = "builtins.open"
|
||||
with patch(patch_module, m, create=True, **kwargs) as mo:
|
||||
stream = StringIO(content)
|
||||
rv = mo.return_value
|
||||
rv.write = lambda x: content_out.write(bytes(x, "utf-8"))
|
||||
|
|
|
@ -2,7 +2,7 @@ import hashlib
|
|||
import os
|
||||
import unittest
|
||||
|
||||
from StringIO import StringIO
|
||||
from tito.compat import StringIO
|
||||
from tito.tar import TarFixer
|
||||
from mock import Mock
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue