Пример #1
0
 def test_custom_move_module(self):
     attr = six.MovedModule('spam', 'six', 'six')
     six.add_move(attr)
     six.remove_move('spam')
     assert not hasattr(six.moves, 'spam')
     attr = six.MovedModule('spam', 'six', 'six')
     six.add_move(attr)
     from six.moves import spam
     assert spam is six
     six.remove_move('spam')
     assert not hasattr(six.moves, 'spam')
Пример #2
0
 def test_moved_module(self):
     attr = six.MovedModule("spam", "foo")
     if six.PY3:
         assert attr.mod == "spam"
     else:
         assert attr.mod == "foo"
     attr = six.MovedModule("spam", "foo", "bar")
     if six.PY3:
         assert attr.mod == "bar"
     else:
         assert attr.mod == "foo"
Пример #3
0
 def test_moved_module(self):
     attr = six.MovedModule('spam', 'foo')
     if six.PY3:
         assert attr.mod == 'spam'
     else:
         assert attr.mod == 'foo'
     attr = six.MovedModule('spam', 'foo', 'bar')
     if six.PY3:
         assert attr.mod == 'bar'
     else:
         assert attr.mod == 'foo'
Пример #4
0
 def test_custom_move_module(self):
     attr = six.MovedModule("spam", "six", "six")
     six.add_move(attr)
     six.remove_move("spam")
     assert not hasattr(six.moves, "spam")
     attr = six.MovedModule("spam", "six", "six")
     six.add_move(attr)
     from six.moves import spam
     assert spam is six
     six.remove_move("spam")
     assert not hasattr(six.moves, "spam")
Пример #5
0
Example of used of renamed modules

>>> from pyhetdex.tools.six_ext import mock
>>> # or if :mod:`~pyhetdex.tools.six_ext` has already been imported somewhere
>>> # in the code
>>> from six.moves import mock  # doctest: +SKIP
"""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import six

# === Exception definitions
if six.PY3:
    FileOpenError = FileNotFoundError
    SubprocessExeError = FileNotFoundError
    ConfigFileError = FileNotFoundError
else:
    FileOpenError = IOError
    SubprocessExeError = OSError

    class ConfigFileError(OSError):
        """Configuration file not found"""
        pass


# === module definitions
mock = six.MovedModule("mock", "mock", "unittest.mock")
six.add_move(mock)  # move to six.moves
Пример #6
0
import sys
import unittest

from collections import namedtuple

import pytest
import six

from convert2rhel import logger, systeminfo, unit_tests, utils  # Imports unit_tests/__init__.py
from convert2rhel.systeminfo import RELEASE_VER_MAPPING, system_info
from convert2rhel.toolopts import tool_opts
from convert2rhel.unit_tests import is_rpm_based_os
from convert2rhel.unit_tests.conftest import all_systems, centos8


six.add_move(six.MovedModule("mock", "mock", "unittest.mock"))
from six.moves import mock


class TestSysteminfo(unittest.TestCase):
    class RunSubprocessMocked(unit_tests.MockFunction):
        def __init__(self, output_tuple=("output", 0)):
            self.output_tuple = output_tuple
            self.called = 0
            self.used_args = []

        def __call__(self, *args, **kwargs):
            self.called += 1
            self.used_args.append(args)
            return self.output_tuple
Пример #7
0
import sys
import six
""" Custom 'moves' extensions for 'six' module.
Just import this module ('_six') to install custom moves to global namespace 'six.moves.clckwrkbdgr.*':
Also handles all available backports (like shutil_get_terminal_size, functools_lru_cache),
again automatically just by importing this module.
"""

six.add_move(
    six.MovedModule('clckwrkbdgr', 'clckwrkbdgr._six', 'clckwrkbdgr._six'))


def _backport(
        module,
        backport_name):  # pragma: no cover -- TODO need some way to test this.
    """ Applies backport patch for the module.
	`backport_name` should be in form `<module_name>_<function_name>,
	e.g.: shutil_get_terminal_size.
	If `shutil.get_terminal_size` is not defined,
	it tries to import `get_terminal_size` from `backports.shutil_get_terminal_size` into `shutil` module.
	"""
    backport_module_name, function_name = backport_name.split('_', 1)
    if hasattr(module, function_name):
        return
    if module.__name__ in sys.modules and hasattr(sys.modules[module.__name__],
                                                  function_name):
        return
    backport_module = __import__('backports.' + backport_name,
                                 fromlist=(b'', ))
    function = getattr(backport_module, function_name)
    setattr(module, function_name, function)
Пример #8
0
# isort: STDLIB
import errno
import os
import re
import subprocess
import sys

# isort: THIRDPARTY
import six
from six.moves import collections_abc

six.add_move(
    six.MovedModule(
        "collections_abc",
        "collections",
        "collections.abc" if sys.version_info >= (3, 3) else "collections",
    ))


class UDevAdm(object):
    """
    Wrap ``udevadm`` utility.
    """

    CANDIDATES = ["/sbin/udevadm", "udevadm"]
    _adm = None

    @classmethod
    def find(cls):
        """
Пример #9
0
"""A series of modules for making Python packages Python-2 and 3 compatible."""

import six

six.add_move(six.MovedModule("io", "StringIO", "io"))
# Make mock importable in Python 2 and 3. `from six.moves import mock`
six.add_move(six.MovedModule("mock", "mock", "unittest.mock"))
Пример #10
0
"""Add Python 2 / 3 mapping for the io.StringIO class."""

import six

six.add_move(six.MovedModule("io", "StringIO", "io"))
Пример #11
0
# version. This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY expressed or implied, including the implied
# warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
# the GNU Lesser General Public License for more details.  You should have
# received a copy of the GNU Lesser General Public License along with this
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat trademarks
# that are incorporated in the source code or documentation are not subject
# to the GNU Lesser General Public License and may only be used or
# replicated with the express permission of Red Hat, Inc.
#
# Red Hat Author(s): David Lehman <*****@*****.**>
#

import six as _six

mock_move = _six.MovedModule('mock', 'mock', 'unittest.mock')


def add_move(mod):
    _six.add_move(mod)
    # https://bitbucket.org/gutworth/six/issues/116/enable-importing-from-within-custom
    _six._importer._add_module(mod, "moves." + mod.name)


def setup():
    add_move(mock_move)


setup()
Пример #12
0
# from http://stackoverflow.com/questions/28215214/how-to-add-custom-renames-in-six

import six
mod = six.MovedModule('mock', 'mock', 'unittest.mock')
six.add_move(mod)
six._importer._add_module(mod, "moves." + mod.name)

# issue open at https://bitbucket.org/gutworth/six/issue/116/enable-importing-from-within-custom
Пример #13
0
from __future__ import absolute_import

import six

moves = [
    six.MovedModule("gobject", "gobject", "gi.repository.GObject"),
    six.MovedAttribute("getoutput", "commands", "subprocess"),
]

for m in moves:
    six.add_move(m)

# Here, we can't use six.Moved* methods because being able to import asyncio vs
# trollius is not strictly Py 2 vs Py 3, but rather asyncio for >=3.4, and
# possibly 3.3 with Tulip, and trollius for 2 and <=3.2, and 3.3 without Tulip.
# Despite this, six.moves.asyncio makes a convenient place to store this so we
# don't need to keep try/except importing asyncio.
try:
    import asyncio
except ImportError:
    import trollius as asyncio

six.moves.asyncio = asyncio
Пример #14
0
        * Symbol : contains a constant, a variable or a predicate. Instantiated before executing the datalog program
    * Function : represents f[X]
    * Operation : made of an operator and 2 operands. Instantiated when an operator is applied to a symbol while executing the datalog program
    * Lambda : represents a lambda function, used in expressions
* Aggregate : represents calls to aggregation method, e.g. min(X)

"""

import ast
from collections import defaultdict, OrderedDict
import inspect
import os
import re
import string
import six
six.add_move(six.MovedModule('UserList', 'UserList', 'collections'))
from six.moves import builtins, xrange, UserList
import sys
import weakref

PY3 = sys.version_info[0] == 3
func_code = '__code__' if PY3 else 'func_code'

try:
    from . import pyEngine
except ValueError:
    import pyEngine
pyDatalog = None  #circ: later set by pyDatalog to avoid circular import
""" global variable to differentiate between in-line queries and pyDatalog program / ask"""
ProgramMode = False
Пример #15
0
#!/usr/bin/env python

import datetime
import json
import six
import unittest
from unittest import TestCase

six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock'))
from six.moves import mock

import github
import pytz

from tests.utils.issue_mock import IssueMock
from tests.utils.repo_mock import RepoMock
from tests.utils.helpers import get_issue
from ansibullbot.triagers.plugins.needs_revision import _changes_requested_by, get_needs_revision_facts, _get_review_state
from ansibullbot.wrappers.issuewrapper import IssueWrapper
from ansibullbot.wrappers.historywrapper import HistoryWrapper

class ComponentMatcherMock(object):

    expected_results = []

    def match(self, issuewrapper):
        return self.expected_results


class ModuleIndexerMock(object):
Пример #16
0
#
#    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 six

six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
Пример #17
0
'''A collection of all of the tests for Ways.

In this module, we set up the mock imports needed to run all of our tests.

'''

# IMPORT THIRD-PARTY LIBRARIES
import six

six.add_move(six.MovedModule('io', 'StringIO', 'io'))
six.add_move(six.MovedModule('mock', 'mock', 'unittest.mock'))
Пример #18
0
def pkg_root():
    """Return the pathlib.Path of the convert2rhel package root."""
    six.add_move(six.MovedModule("pathlib", "pathlib2", "pathlib"))
    from six.moves import pathlib

    return pathlib.Path(__file__).parents[2]
Пример #19
0
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from __future__ import absolute_import

import six

moves = [
    six.MovedAttribute("getoutput", "commands", "subprocess"),
    six.MovedModule("asyncio", "trollius", "asyncio"),
]

for m in moves:
    six.add_move(m)

# Keep supporting the deprecated misspelled subpackage "extention"
# TODO: Remove in the future
from . import extension as extention  # noqa