Skip to content

Commit d7d12c8

Browse files
committed
fix: Move tests under ld_eventsource namespace
Previous distributions of this package included two packages -- ld_eventsource and testing. This top level testing namespace can conflict with other packages. In fact, it conflicts with our own SDK. In general this doesn't matter, but it may if: 1. You are using a build process that warns about conflicts (see [this issue][1]) 2. You want to install the sdist on an unsupported platform and would like to be able to verify the tests. To resolve this issue, we are moving the testing folder into the ld_eventsource package. These testing files will only be included in the sdist format. This allows for a smaller wheel size while also allowing for flexibility with consumers. [1]: launchdarkly/python-server-sdk#281
1 parent 4372af2 commit d7d12c8

14 files changed

+32
-33
lines changed

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ test: install
3131
.PHONY: lint
3232
lint: #! Run type analysis and linting checks
3333
lint: install
34-
poetry run python --version
35-
poetry run mypy ld_eventsource testing
34+
poetry run mypy ld_eventsource
3635

3736
#
3837
# Documentation generation

ld_eventsource/config/connect_strategy.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class ConnectStrategy:
1010
"""
1111
An abstraction for how :class:`.SSEClient` should obtain an input stream.
12-
12+
1313
The default implementation is :meth:`http()`, which makes HTTP requests with ``urllib3``.
1414
Or, if you want to consume an input stream from some other source, you can create your own
1515
subclass of :class:`ConnectStrategy`.
@@ -29,7 +29,7 @@ def create_client(self, logger: Logger) -> ConnectionClient:
2929
:param logger: the logger being used by the SSEClient
3030
"""
3131
raise NotImplementedError("ConnectStrategy base class cannot be used by itself")
32-
32+
3333
@staticmethod
3434
def http(
3535
url: str,
@@ -62,11 +62,11 @@ def connect(self, last_event_id: Optional[str]) -> ConnectionResult:
6262
Attempts to connect to a stream. Raises an exception if unsuccessful.
6363
6464
:param last_event_id: the current value of :attr:`SSEClient.last_event_id`
65-
(should be sent to the server to support resuming an interrupted stream)
65+
(should be sent to the server to support resuming an interrupted stream)
6666
:return: a :class:`ConnectionResult` representing the stream
6767
"""
6868
raise NotImplementedError("ConnectionClient base class cannot be used by itself")
69-
69+
7070
def close(self):
7171
"""
7272
Does whatever is necessary to release resources when the SSEClient is closed.
@@ -92,7 +92,7 @@ def __init__(
9292
):
9393
self.__stream = stream
9494
self.__closer = closer
95-
95+
9696
@property
9797
def stream(self) -> Iterator[bytes]:
9898
"""
@@ -121,7 +121,7 @@ def __exit__(self, type, value, traceback):
121121
class _HttpConnectStrategy(ConnectStrategy):
122122
def __init__(self, params: _HttpConnectParams):
123123
self.__params = params
124-
124+
125125
def create_client(self, logger: Logger) -> ConnectionClient:
126126
return _HttpConnectionClient(self.__params, logger)
127127

ld_eventsource/config/retry_delay_strategy.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class RetryDelayStrategy:
88
"""Base class of strategies for computing how long to wait before retrying a connection.
9-
9+
1010
The default behavior, provided by :meth:`default()`, provides customizable exponential backoff
1111
and jitter. Applications may also create their own subclasses of RetryDelayStrategy if they
1212
desire different behavior. It is generally a best practice to use backoff and jitter, to avoid
@@ -51,12 +51,12 @@ def default(
5151
equal to the current base delay minus a pseudo-random number equal to that ratio times itself.
5252
For instance, a jitter multiplier of 0.25 would mean that a base delay of 1000 is changed to a
5353
value in the range [750, 1000].
54-
55-
54+
55+
5656
:param max_delay: the maximum possible delay value, in seconds; default is 30 seconds
5757
:param backoff_multiplier: the exponential backoff factor
5858
:param jitter_multiplier: a fraction from 0.0 to 1.0 for how much of the delay may be
59-
pseudo-randomly subtracted
59+
pseudo-randomly subtracted
6060
"""
6161
return _DefaultRetryDelayStrategy(max_delay or 0, backoff_multiplier, jitter_multiplier or 0,
6262
0, _ReusableRandom(time.time()))
@@ -66,7 +66,7 @@ def from_lambda(fn: Callable[[float], Tuple[float, Optional[RetryDelayStrategy]]
6666
"""
6767
Convenience method for creating a RetryDelayStrategy whose ``apply`` method is equivalent to
6868
the given lambda.
69-
69+
7070
The one difference is that the second return value is an ``Optional[RetryDelayStrategy]`` which
7171
can be None to mean "no change", since the lambda cannot reference the strategy's ``self``.
7272
"""
@@ -101,7 +101,7 @@ def apply(self, base_delay: float) -> Tuple[float, RetryDelayStrategy]:
101101
# state as our previous Random before using it.
102102
random = random.clone()
103103
adjusted_delay -= (random.random() * self.__jitter_multiplier * adjusted_delay)
104-
104+
105105
next_strategy = _DefaultRetryDelayStrategy(
106106
self.__max_delay,
107107
self.__backoff_multiplier,
@@ -114,7 +114,7 @@ def apply(self, base_delay: float) -> Tuple[float, RetryDelayStrategy]:
114114
class _LambdaRetryDelayStrategy(RetryDelayStrategy):
115115
def __init__(self, fn: Callable[[float], Tuple[float, Optional[RetryDelayStrategy]]]):
116116
self.__fn = fn
117-
117+
118118
def apply(self, base_delay: float) -> Tuple[float, RetryDelayStrategy]:
119119
delay, maybe_next = self.__fn(base_delay)
120120
return (delay, maybe_next or self)
@@ -123,7 +123,7 @@ class _ReusableRandom:
123123
def __init__(self, seed: float):
124124
self.__seed = seed
125125
self.__random = Random(seed)
126-
126+
127127
def clone(self):
128128
state = self.__random.getstate()
129129
ret = _ReusableRandom(self.__seed)
File renamed without changes.

testing/helpers.py ld_eventsource/testing/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ld_eventsource.config import *
55
from ld_eventsource.errors import *
66

7-
from testing.http_util import *
7+
from ld_eventsource.testing.http_util import *
88

99
from logging import Logger
1010
from typing import Iterable, Iterator, List, Optional

testing/http_util.py ld_eventsource/testing/http_util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def __init__(self, port, secure):
4848
if secure:
4949
self.server.socket = ssl.wrap_socket(
5050
self.server.socket,
51-
certfile='./testing/selfsigned.pem', # this is a pre-generated self-signed cert that is valid for 100 years
52-
keyfile='./testing/selfsigned.key',
51+
certfile='./ld_eventsource/testing/selfsigned.pem', # this is a pre-generated self-signed cert that is valid for 100 years
52+
keyfile='./ld_eventsource/testing/selfsigned.key',
5353
server_side=True
5454
)
5555
self.server.server_wrapper = self
@@ -76,7 +76,7 @@ def require_request(self):
7676
def wait_until_request_received(self):
7777
req = self.requests.get()
7878
self.requests.put(req)
79-
79+
8080
def should_have_requests(self, count):
8181
if self.requests.qsize() != count:
8282
rs = []
File renamed without changes.

testing/test_http_connect_strategy.py ld_eventsource/testing/test_http_connect_strategy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ld_eventsource.config.connect_strategy import *
22

3-
from testing.helpers import *
4-
from testing.http_util import *
3+
from ld_eventsource.testing.helpers import *
4+
from ld_eventsource.testing.http_util import *
55

66
import logging
77
from urllib3.exceptions import ProtocolError
@@ -87,7 +87,7 @@ def test_http_io_error():
8787
raise Exception("expected exception, did not get one")
8888
except ProtocolError as e:
8989
pass
90-
90+
9191
def test_auto_redirect_301():
9292
with start_server() as server:
9393
with make_stream() as stream:

testing/test_http_connect_strategy_with_sse_client.py ld_eventsource/testing/test_http_connect_strategy_with_sse_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from ld_eventsource import *
22
from ld_eventsource.config import *
33

4-
from testing.helpers import *
5-
from testing.http_util import *
4+
from ld_eventsource.testing.helpers import *
5+
from ld_eventsource.testing.http_util import *
66

77
# Tests of basic SSEClient behavior using real HTTP requests.
88

File renamed without changes.

testing/test_sse_client_basic.py ld_eventsource/testing/test_sse_client_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ld_eventsource.actions import *
33
from ld_eventsource.config import *
44

5-
from testing.helpers import *
5+
from ld_eventsource.testing.helpers import *
66

77
import pytest
88

testing/test_sse_client_retry.py ld_eventsource/testing/test_sse_client_retry.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ld_eventsource.actions import *
33
from ld_eventsource.config import *
44

5-
from testing.helpers import *
5+
from ld_eventsource.testing.helpers import *
66

77

88
def test_retry_during_initial_connect_succeeds():
@@ -88,7 +88,7 @@ def test_all_iterator_continues_after_retry():
8888

8989
item4 = next(all)
9090
assert isinstance(item4, Start)
91-
91+
9292
item5 = next(all)
9393
assert isinstance(item5, Event)
9494
assert item5.data == 'data2'
@@ -125,10 +125,10 @@ def test_can_interrupt_and_restart_stream():
125125

126126
item3 = next(all)
127127
assert isinstance(item3, Fault)
128-
128+
129129
item4 = next(all)
130130
assert isinstance(item4, Start)
131-
131+
132132
item5 = next(all)
133133
assert isinstance(item5, Event)
134134
assert item5.data == 'data3'

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ classifiers = [
2121
"Topic :: Software Development",
2222
"Topic :: Software Development :: Libraries",
2323
]
24-
packages = [
25-
{ include = "ld_eventsource" },
26-
{ include = "testing" },
24+
packages = [ { include = "ld_eventsource" } ]
25+
exclude = [
26+
{ path = "ld_eventsource/testing", format = "wheel" }
2727
]
2828

2929
[tool.poetry.dependencies]

0 commit comments

Comments
 (0)