Skip to content

Commit

Permalink
tests: No longer monkey patch httpretty for python 3.4.2
Browse files Browse the repository at this point in the history
No shipping ubuntu has a python 3.4 that is less than 3.4.2.
Remove this workaround to avoid unnecessary complexity.

This reverts 04a60cf.
  • Loading branch information
smoser committed Jan 24, 2017
1 parent 853df0a commit 8e9e47f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 40 deletions.
35 changes: 0 additions & 35 deletions tests/unittests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import print_function

import functools
import os
import shutil
import sys
Expand All @@ -29,7 +28,6 @@
PY26 = False
PY27 = False
PY3 = False
FIX_HTTPRETTY = False

_PY_VER = sys.version_info
_PY_MAJOR, _PY_MINOR, _PY_MICRO = _PY_VER[0:3]
Expand All @@ -44,8 +42,6 @@
PY2 = True
if (_PY_MAJOR, _PY_MINOR) >= (3, 0):
PY3 = True
if _PY_MINOR == 4 and _PY_MICRO < 3:
FIX_HTTPRETTY = True


# Makes the old path start
Expand Down Expand Up @@ -216,37 +212,6 @@ def reRoot(self, root=None):
return root


def import_httpretty():
"""Import HTTPretty and monkey patch Python 3.4 issue.
See https://github.com/gabrielfalcao/HTTPretty/pull/193 and
as well as https://github.com/gabrielfalcao/HTTPretty/issues/221.
Lifted from
https://github.com/inveniosoftware/datacite/blob/master/tests/helpers.py
"""
if not FIX_HTTPRETTY:
import httpretty
else:
import socket
old_SocketType = socket.SocketType

import httpretty
from httpretty import core

def sockettype_patch(f):
@functools.wraps(f)
def inner(*args, **kwargs):
f(*args, **kwargs)
socket.SocketType = old_SocketType
socket.__dict__['SocketType'] = old_SocketType
return inner

core.httpretty.disable = sockettype_patch(
httpretty.httpretty.disable
)
return httpretty


class HttprettyTestCase(TestCase):
# necessary as http_proxy gets in the way of httpretty
# https://github.com/gabrielfalcao/HTTPretty/issues/122
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_datasource/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

import httpretty
import re

from base64 import b64encode, b64decode
Expand All @@ -15,7 +16,6 @@

from .. import helpers as test_helpers

httpretty = test_helpers.import_httpretty()

GCE_META = {
'instance/id': '123',
Expand Down
3 changes: 1 addition & 2 deletions tests/unittests/test_datasource/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This file is part of cloud-init. See LICENSE file for license information.

import copy
import httpretty as hp
import json
import re

Expand All @@ -20,8 +21,6 @@
from cloudinit.sources.helpers import openstack
from cloudinit import util

hp = test_helpers.import_httpretty()

BASE_URL = "http://169.254.169.254"
PUBKEY = u'ssh-rsa AAAAB3NzaC1....sIkJhq8wdX+4I3A4cYbYP ubuntu@server-460\n'
EC2_META = {
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_ec2_util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This file is part of cloud-init. See LICENSE file for license information.

import httpretty as hp

from . import helpers

from cloudinit import ec2_utils as eu
from cloudinit import url_helper as uh

hp = helpers.import_httpretty()


class TestEc2Util(helpers.HttprettyTestCase):
VERSION = 'latest'
Expand Down

0 comments on commit 8e9e47f

Please sign in to comment.