Skip to content

Commit d4235f9

Browse files
tuan-phamwilliaminfante
authored andcommitted
chore: flake8, clean up deadcode
1 parent 19827d0 commit d4235f9

File tree

4 files changed

+18
-43
lines changed

4 files changed

+18
-43
lines changed

pact/broker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,4 @@ def publish(self, consumer_name, version, pact_dir=None,
7070
if publish_process.returncode != 0:
7171
url = self._get_broker_base_url()
7272
raise RuntimeError(
73-
"There was an error while publishing to the "
74-
+ "pact broker at {}."
75-
.format(url))
73+
f"There was an error while publishing to the pact broker at {url}.")

pact/message_pact.py

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,22 @@
88
from .broker import Broker
99
from .constants import MESSAGE_PATH
1010

11-
import logging
12-
13-
log = logging.getLogger(__name__)
14-
logging.basicConfig(level=logging.INFO)
15-
1611

1712
class MessagePact(Broker):
1813
"""
1914
Represents a contract between a consumer and provider using messages.
2015
21-
Provides Python context handlers to configure the Pact mock service to
22-
perform tests on a Python consumer. For example:
16+
Provides Python context handler to perform tests on a Python consumer. For example:
2317
24-
>>> from pact import Consumer, Provider
18+
>>> from pact import MessageConsumer, Provider
2519
>>> pact = MessageConsumer('MyMessageConsumer').has_pact_with(Provider('provider'))
2620
>>> (pact
2721
... .given({"name": "Test provider"}])
2822
... .expects_to_receive('Test description')
2923
... .with_content({'name': 'John', 'document_name': 'sample_document.doc'})
3024
... .with_metadata({'contentType': 'application/json'}))
3125
>>> with pact:
32-
... log.info("In Python context")
26+
... handler(event, context)
3327
"""
3428

3529
MANDATORY_FIELDS = {"providerStates", "description", "contents", "metaData"}
@@ -44,14 +38,14 @@ def __init__(
4438
broker_password=None,
4539
broker_token=None,
4640
pact_dir=None,
47-
version="3.0.0",
41+
version='3.0.0',
4842
file_write_mode="merge",
4943
):
5044
"""
5145
Create a Pact instance using messages.
5246
:param consumer: A consumer for this contract that uses messages.
53-
:type consumer: pact.Consumer
54-
:param provider: The provider for this contract.
47+
:type consumer: pact.MessageConsumer
48+
:param provider: The generic provider for this contract.
5549
:type provider: pact.Provider
5650
:param publish_to_broker: Flag to control automatic publishing of
5751
pacts to a pact broker. Defaults to False.
@@ -117,40 +111,33 @@ def given(self, provider_states):
117111
self._insert_message_if_complete()
118112

119113
state = [{"name": "{}".format(provider_states)}]
120-
self._messages[0]["providerStates"] = state
114+
self._messages[0]['providerStates'] = state
121115
return self
122116

123117
def with_metadata(self, metadata):
124118
self._insert_message_if_complete()
125-
self._messages[0]["metaData"] = metadata
119+
self._messages[0]['metaData'] = metadata
126120
return self
127121

128122
def with_content(self, contents):
129123
self._insert_message_if_complete()
130-
self._messages[0]["contents"] = contents
124+
self._messages[0]['contents'] = contents
131125
return self
132126

133127
def expects_to_receive(self, description):
134128
self._insert_message_if_complete()
135-
self._messages[0]["description"] = description
129+
self._messages[0]['description'] = description
136130
return self
137131

138-
@staticmethod
139-
def _normalize_consumer_name(name):
140-
return name.lower().replace(" ", "_")
141-
142132
def write_to_pact_file(self):
143133
command = [
144134
MESSAGE_PATH,
145135
"update",
146136
json.dumps(self._messages[0]),
147-
"--pact-dir",
148-
self.pact_dir,
149-
"--pact-specification-version={}".format(self.version),
150-
"--consumer",
151-
self.consumer.name + "_message",
152-
"--provider",
153-
self.provider.name + "_message",
137+
"--pact-dir", self.pact_dir,
138+
f"--pact-specification-version={self.version}",
139+
"--consumer", f"{self.consumer.name}_message",
140+
"--provider", f"{self.provider.name}_message",
154141
]
155142

156143
self._message_process = Popen(command)
@@ -169,18 +156,15 @@ def _insert_message_if_complete(self):
169156

170157
def __enter__(self):
171158
"""
172-
Enter a Python context.
173-
174-
Sets up the mock service to expect the client requests.
159+
Enter a Python context. This function is required for context manager to work.
175160
"""
176-
log.info("__enter__ context")
161+
pass
177162

178163
def __exit__(self, exc_type, exc_val, exc_tb):
179164
"""
180165
Exit a Python context.
181166
182-
Calls the mock service to verify the message occurred as
183-
expected, and has it write out the contracts to disk.
167+
Calls pact-message to write out the contracts to disk.
184168
"""
185169
if (exc_type, exc_val, exc_tb) != (None, None, None):
186170
return

pact/pact.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ def given(self, provider_state):
162162
self._interactions[0]['provider_state'] = provider_state
163163
return self
164164

165-
@staticmethod
166-
def _normalize_consumer_name(name):
167-
return name.lower().replace(" ", "_")
168-
169165
def setup(self):
170166
"""Configure the Mock Service to ready it for a test."""
171167
try:

tests/test_broker.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ def setUp(self):
2121
broker.fnmatch, 'filter', autospec=True).start()
2222
self.mock_fnmatch.return_value = ['TestConsumer-TestProvider.json']
2323

24-
def tearDown(self):
25-
print("TearDown")
26-
2724
def test_publish_without_broker_url(self):
2825
broker = Broker()
2926

0 commit comments

Comments
 (0)