Skip to content

Commit 8a02b3a

Browse files
Merge pull request #81 from BenjamenMeyer/enhancement_python-environment-updates
Enhancement: Update test environment and dependencies
2 parents 63ee457 + 61842e2 commit 8a02b3a

File tree

22 files changed

+156
-79
lines changed

22 files changed

+156
-79
lines changed

.travis.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
language: python
22
matrix:
33
include:
4-
- python: "2.7"
5-
env: TEST_SUITE=suite_2_7 TOX_ENV=py27
6-
- python: "pypy"
7-
env: TEST_SUITE=suite_pypy TOX_ENV=pypy
8-
- python: "3.4"
9-
env: TEST_SUITE=suite_3_4 TOX_ENV=py34
4+
- python: "pypy3"
5+
env: TEST_SUITE=suite_pypy3 TOX_ENV=pypy3
6+
- python: "3.6"
7+
env: TEST_SUITE=suite_3_6 TOX_ENV=pep8
8+
- python: "3.6"
9+
env: TEST_SUITE=suite_3_6 TOX_ENV=docs
1010
- python: "3.5"
11-
env: TEST_SUITE=suite_3_4 TOX_ENV=py35
11+
env: TEST_SUITE=suite_3_5 TOX_ENV=py35
12+
- python: "3.7"
13+
env: TEST_SUITE=suite_3_7 TOX_ENV=py37
14+
- python: "3.8"
15+
env: TEST_SUITE=suite_3_8 TOX_ENV=py38
16+
- python: "3.6"
17+
env: TEST_SUITE=suite_3_6 TOX_ENV=py36
18+
- python: "3.6"
19+
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-httpretty
20+
- python: "3.6"
21+
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-requests-mock
1222
- python: "3.6"
13-
env: TEST_SUITE=suite_3_4 TOX_ENV=py36
14-
- python: "3.4"
15-
env: TEST_SUITE=suite_3_4 TOX_ENV=pep8
23+
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-responses
1624
- python: "2.7"
17-
env: TEST_SUITE=suite_2_7 TOX_ENV=docs
25+
env: TEST_SUITE=suite_2_7 TOX_ENV=py27
1826
- python: "2.7"
1927
env: TEST_SUITE=suite_2_7 TOX_ENV=py27-httpretty
20-
- python: "3.6"
21-
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-httpretty
2228
- python: "2.7"
2329
env: TEST_SUITE=suite_2_7 TOX_ENV=py27-requests-mock
24-
- python: "3.6"
25-
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-requests-mock
2630
- python: "2.7"
2731
env: TEST_SUITE=suite_2_7 TOX_ENV=py27-responses
28-
- python: "3.6"
29-
env: TEST_SUITE=suite_3_6 TOX_ENV=py36-responses
32+
- python: "pypy"
33+
env: TEST_SUITE=suite_pypy TOX_ENV=pypy
3034

3135
sudo: required
3236
before_install:

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Out-of-the-box it supports the following frameworks:
8989

9090
You can use any of them, and you must pull them in via your own test requirements.
9191

92+
.. note:: HTTPretty has some version and Python limitations. Version 0.8.6 works fine; however, version 0.9.x which supports
93+
Python3 seems to have a breaking change that is causing problems. Only 0.8.6 is supported by StackInABox under Python2
94+
for the time being. That is not to say you may not get it to work; just that the StackInABox Unit Tests cannot verify it
95+
will work. PRs are welcome to help resolve this. See Issue #80 for status.
96+
9297
-----------
9398
Error Codes
9499
-----------

stackinabox/services/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def request(self, method, request, uri, headers):
383383
return self.try_handle_route(uri, method, request, uri, headers)
384384

385385
def sub_request(self, method, request, uri, headers):
386-
"""Handle the supplied sub-service request on the specified routing URI.
386+
"""Handle the supplied sub-service request on the specified routing URI
387387
388388
:param method: string - HTTP Verb
389389
:param request: request object describing the HTTP request

stackinabox/stack.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,42 @@ class StackInABox(object):
3535
3636
"""
3737

38+
@classmethod
39+
def get_thread_instance(cls):
40+
"""
41+
Interface to the thread storage to ensure the instance properly exists
42+
"""
43+
create = False
44+
45+
# if the `instance` property doesn't exist
46+
if not hasattr(local_store, 'instance'):
47+
local_store.instance = None
48+
create = True
49+
50+
# if the instance doesn't exist at all
51+
elif local_store.instance is None:
52+
create = True
53+
54+
# if it's something else entirely...
55+
elif not isinstance(local_store.instance, cls):
56+
local_store.instance = None
57+
create = True
58+
59+
# if the above conditions are met, create it
60+
if create:
61+
logger.debug('Creating new StackInABox instance...')
62+
local_store.instance = cls()
63+
logger.debug(
64+
'Created StackInABox({0})'.format(local_store.instance.__id)
65+
)
66+
67+
return local_store.instance
68+
3869
@classmethod
3970
def reset_services(cls):
4071
"""Reset the thread's StackInABox instance."""
4172
logger.debug('Resetting services')
42-
return local_store.instance.reset()
73+
return cls.get_thread_instance().reset()
4374

4475
@classmethod
4576
def register_service(cls, service):
@@ -51,7 +82,7 @@ def register_service(cls, service):
5182
5283
"""
5384
logger.debug('Registering service {0}'.format(service.name))
54-
return local_store.instance.register(service)
85+
return cls.get_thread_instance().register(service)
5586

5687
@classmethod
5788
def call_into(cls, method, request, uri, headers):
@@ -66,7 +97,7 @@ def call_into(cls, method, request, uri, headers):
6697
6798
"""
6899
logger.debug('Request: {0} - {1}'.format(method, uri))
69-
return local_store.instance.call(method,
100+
return cls.get_thread_instance().call(method,
70101
request,
71102
uri,
72103
headers)
@@ -85,7 +116,7 @@ def hold_onto(cls, name, obj):
85116
"""
86117
logger.debug('Holding on {0} of type {1} with id {2}'
87118
.format(name, type(obj), id(obj)))
88-
local_store.instance.into_hold(name, obj)
119+
cls.get_thread_instance().into_hold(name, obj)
89120

90121
@classmethod
91122
def hold_out(cls, name):
@@ -102,7 +133,7 @@ def hold_out(cls, name):
102133
"""
103134
logger.debug('Retreiving {0} from hold'
104135
.format(name))
105-
obj = local_store.instance.from_hold(name)
136+
obj = cls.get_thread_instance().from_hold(name)
106137
logger.debug('Retrieved {0} of type {1} with id {2} from hold'
107138
.format(name, type(obj), id(obj)))
108139
return obj
@@ -115,7 +146,7 @@ def update_uri(cls, uri):
115146
116147
"""
117148
logger.debug('Request: Update URI to {0}'.format(uri))
118-
local_store.instance.base_url = uri
149+
cls.get_thread_instance().base_url = uri
119150

120151
def __init__(self):
121152
"""Initialize the StackInABox instance.
@@ -307,4 +338,3 @@ def from_hold(self, name):
307338

308339
# Thread local instance of StackInABox
309340
local_store = threading.local()
310-
local_store.instance = StackInABox()

stackinabox/util/httpretty/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def registration(uri):
7979

8080
# build the regex for the uri and register all http verbs
8181
# with httpretty
82-
regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
82+
regex = re.compile(r'(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
8383
re.I)
8484
for method in HttpBaseClass.METHODS:
8585
register_uri(method, regex, body=httpretty_callback)

stackinabox/util/httpretty/decorator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""
22
Stack-In-A-Box: HTTPretty Support via decorator
33
"""
4-
import collections
4+
try:
5+
import collections.abc as collections
6+
except ImportError:
7+
# Py2.7 Support
8+
import collections
59
import functools
610
import logging
711
import re

stackinabox/util/requests_mock/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, uri):
4141
:param uri: URI to match against
4242
"""
4343
self.regex = re.compile(
44-
'(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I)
44+
r'(http)?s?(://)?{0}:?(\d+)?/'.format(uri), re.I)
4545

4646
def __call__(self, request):
4747
"""object callable interface.

stackinabox/util/requests_mock/decorator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""
22
Stack-In-A-Box: Requests-Mock Support via Decorator
33
"""
4-
import collections
4+
try:
5+
import collections.abc as collections
6+
except ImportError:
7+
# Py2.7 Support
8+
import collections
59
import functools
610
import logging
711
import re

stackinabox/util/responses/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def registration(uri):
6161

6262
# Build the regex for the URI and register all HTTP verbs
6363
# with Responses
64-
regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
64+
regex = re.compile(r'(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
6565
re.I)
6666
METHODS = [
6767
responses.DELETE,

stackinabox/util/responses/decorator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"""
22
Stack-In-A-Box: Responses Support via decorator
33
"""
4-
import collections
4+
try:
5+
import collections.abc as collections
6+
except ImportError:
7+
# Py2.7 Support
8+
import collections
9+
510
import functools
611
import logging
712
import re

0 commit comments

Comments
 (0)