Exemple #1
0
    
    Provide what is *not* in 'six' already
    You should just do "import ...backport" and then use the new imports as
    six.moves.<name>
"""

__all__ = ['utf8_cat']

from six import PY3
from six import MovedModule
from six import MovedAttribute
from six import add_move


attributes = [
    MovedModule('xmlrpc_client', 'xmlrpclib', 'xmlrpc.client'),
    MovedAttribute('HTTPError', 'urllib2', 'urllib.error'),
    MovedAttribute('URLError', 'urllib2', 'urllib.error'),
    MovedAttribute('Request', 'urllib2', 'urllib.request'),
    MovedAttribute('urlopen', 'urllib2', 'urllib.request'),
    MovedAttribute('urllib_version', 'urllib2', 'urllib.request', '__version__'),
    MovedAttribute('urlparse', 'urlparse', 'urllib.parse'),
]
for attr in attributes:
    add_move(attr)
del attr
del attributes

if PY3:
    def utf8_cat(f):
        """Read the given file in utf8 encoding"""
Exemple #2
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.iot.hub.devicesdk.internal_client import InternalClient
from azure.iot.hub.devicesdk.device_client import DeviceClient
from azure.iot.hub.devicesdk.module_client import ModuleClient
from azure.iot.hub.devicesdk.auth.authentication_provider_factory import from_connection_string
from azure.iot.hub.devicesdk.transport.mqtt.mqtt_transport import MQTTTransport
import pytest

from six import add_move, MovedModule

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

connection_string_format = "HostName={};DeviceId={};SharedAccessKey={}"
shared_access_key = "Zm9vYmFy"
hostname = "beauxbatons.academy-net"
device_id = "MyPensieve"


@pytest.fixture
def connection_string():
    connection_string = connection_string_format.format(
        hostname, device_id, shared_access_key)
    return connection_string

from gslib.utils import posix_util
from gslib.utils import system_util
from gslib.utils import hashing_helper
from gslib.utils.copy_helper import _DelegateUploadFileToObject
from gslib.utils.copy_helper import _GetPartitionInfo
from gslib.utils.copy_helper import _SelectUploadCompressionStrategy
from gslib.utils.copy_helper import _SetContentTypeFromFile
from gslib.utils.copy_helper import ExpandUrlToSingleBlr
from gslib.utils.copy_helper import FilterExistingComponents
from gslib.utils.copy_helper import GZIP_ALL_FILES
from gslib.utils.copy_helper import PerformParallelUploadFileToObjectArgs
from gslib.utils.copy_helper import WarnIfMvEarlyDeletionChargeApplies

from six import add_move, MovedModule

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

_CalculateB64EncodedMd5FromContents = (
    hashing_helper.CalculateB64EncodedMd5FromContents)


class TestCpFuncs(GsUtilUnitTestCase):
  """Unit tests for parallel upload functions in cp command."""

  def testGetPartitionInfo(self):
    """Tests the _GetPartitionInfo function."""
    # Simplest case - threshold divides file_size.
    (num_components, component_size) = _GetPartitionInfo(300, 200, 10)
    self.assertEqual(30, num_components)
    self.assertEqual(10, component_size)
import sys

from puck.backend import (PYPI_URL, echo_backend, high_version_backend,
                          pypi_backend)
from six import MovedModule, add_move

import pytest

add_move(MovedModule('mock', 'mock', 'unittest.mock'))  # isort:skip
from six.moves import mock  # noqa isort:skip


def test_high_version_backend():
    assert high_version_backend('foo') == '99.99.99'


def test_echo_backend():
    assert echo_backend('foo') == 'foo'


@pytest.mark.skipif(sys.version_info < (3, 3), reason="requires python3.3")
@mock.patch('xmlrpc.client.ServerProxy')
def test_pypi_backend_py3(server_mock):
    expected = None
    pypi_mock = server_mock.return_value
    pypi_mock.package_releases.return_value = [expected]

    return_val = pypi_backend('foo')

    server_mock.assert_called_with(PYPI_URL)
    pypi_mock.package_releases.assert_called_once()