Skip to content

Commit e76a2e1

Browse files
committed
fix formatting for black for tests
1 parent 531004d commit e76a2e1

File tree

8 files changed

+52
-68
lines changed

8 files changed

+52
-68
lines changed

src/etcd/tests/integration/helpers.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ def __init__(
3333

3434
def check_compat_args(self):
3535
version_re = re.compile(r"^etcd version:\s+(\d)\.(\d)", re.I)
36-
version_data = subprocess.check_output(
37-
[self.proc_name, "--version"]
38-
).decode("utf-8")
36+
version_data = subprocess.check_output([self.proc_name, "--version"]).decode("utf-8")
3937
match = version_re.match(version_data)
4038
if match is not None:
4139
etcd_version = (int(match.group(1)), int(match.group(2)))
4240
else:
4341
etcd_version = (0, 0)
44-
if etcd_version[0] < 3 or (
45-
etcd_version[0] == 3 and etcd_version[1] < 4
46-
):
42+
if etcd_version[0] < 3 or (etcd_version[0] == 3 and etcd_version[1] < 4):
4743
return []
4844
else:
4945
return ["--enable-v2=true"]
@@ -70,9 +66,7 @@ def run(self, number=1, proc_args=[]):
7066
proc_args.extend(
7167
[
7268
"-initial-cluster",
73-
"test-node-0=http://127.0.0.1:{}".format(
74-
self.internal_port_range_start
75-
),
69+
"test-node-0=http://127.0.0.1:{}".format(self.internal_port_range_start),
7670
"-initial-cluster-state",
7771
"new",
7872
]
@@ -88,9 +82,7 @@ def stop(self):
8882

8983
def add_one(self, slot, proc_args=None):
9084
log = logging.getLogger()
91-
directory = tempfile.mkdtemp(
92-
dir=self.base_directory, prefix="python-etcd.%d-" % slot
93-
)
85+
directory = tempfile.mkdtemp(dir=self.base_directory, prefix="python-etcd.%d-" % slot)
9486

9587
log.debug("Created directory %s" % directory)
9688
client = "%s127.0.0.1:%d" % (self.schema, self.port_range_start + slot)
@@ -193,16 +185,10 @@ def create_test_ca_certificate(cls, cert_path, key_path, cn=None):
193185
cert.sign(k, "sha1")
194186

195187
with open(cert_path, "w") as f:
196-
f.write(
197-
crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode(
198-
"utf-8"
199-
)
200-
)
188+
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
201189

202190
with open(key_path, "w") as f:
203-
f.write(
204-
crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8")
205-
)
191+
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))
206192

207193
return cert, k
208194

@@ -231,9 +217,7 @@ def create_test_certificate(cls, ca, ca_key, cert_path, key_path, cn=None):
231217
crypto.X509Extension(
232218
"keyUsage".encode("ascii"),
233219
False,
234-
"nonRepudiation,digitalSignature,keyEncipherment".encode(
235-
"ascii"
236-
),
220+
"nonRepudiation,digitalSignature,keyEncipherment".encode("ascii"),
237221
),
238222
crypto.X509Extension(
239223
"extendedKeyUsage".encode("ascii"),
@@ -257,13 +241,7 @@ def create_test_certificate(cls, ca, ca_key, cert_path, key_path, cn=None):
257241
cert.sign(ca_key, "sha1")
258242

259243
with open(cert_path, "w") as f:
260-
f.write(
261-
crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode(
262-
"utf-8"
263-
)
264-
)
244+
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
265245

266246
with open(key_path, "w") as f:
267-
f.write(
268-
crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8")
269-
)
247+
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))

src/etcd/tests/integration/test_simple.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ def test_reconnect_with_several_hosts_passed(self):
205205
"""INTEGRATION: receive several hosts at connection setup."""
206206
self.processHelper.stop()
207207
self.processHelper.run(number=3)
208-
self.client = etcd.Client(host=(("127.0.0.1", 6004), ("127.0.0.1", 6001)), allow_reconnect=True)
208+
self.client = etcd.Client(
209+
host=(("127.0.0.1", 6004), ("127.0.0.1", 6001)), allow_reconnect=True
210+
)
209211
set_result = self.client.set("/test_set", "test-key1")
210212
get_result = self.client.get("/test_set")
211213

@@ -307,7 +309,9 @@ def watch_value(key, index, queue):
307309
),
308310
)
309311

310-
watcher = multiprocessing.Process(target=watch_value, args=("/test-key", original_index, queue))
312+
watcher = multiprocessing.Process(
313+
target=watch_value, args=("/test-key", original_index, queue)
314+
)
311315

312316
watcher.start()
313317
time.sleep(0.5)
@@ -387,7 +391,9 @@ def watch_value(key, index, queue):
387391
),
388392
)
389393

390-
watcher = multiprocessing.Process(target=watch_value, args=("/test-key", original_index, queue))
394+
watcher = multiprocessing.Process(
395+
target=watch_value, args=("/test-key", original_index, queue)
396+
)
391397

392398
watcher.start()
393399
time.sleep(0.5)

src/etcd/tests/integration/test_ssl.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def test_get_set_unauthenticated(self):
6767
# Since python 3 raises a MaxRetryError here, this gets caught in
6868
# different code blocks in python 2 and python 3, thus messages are
6969
# different. Python 3 does the right thing(TM), for the record
70-
self.assertRaises(
71-
etcd.EtcdException, client.set, "/test_set", "test-key"
72-
)
70+
self.assertRaises(etcd.EtcdException, client.set, "/test_set", "test-key")
7371

7472
self.assertRaises(etcd.EtcdException, client.get, "/test_set")
7573

@@ -82,13 +80,9 @@ def test_get_set_unauthenticated_missing_ca(self):
8280

8381
def test_get_set_unauthenticated_with_ca(self):
8482
"""INTEGRATION: try unauthenticated with validation (https->https)"""
85-
client = etcd.Client(
86-
protocol="https", port=6001, ca_cert=self.ca2_cert_path
87-
)
83+
client = etcd.Client(protocol="https", port=6001, ca_cert=self.ca2_cert_path)
8884

89-
self.assertRaises(
90-
etcd.EtcdConnectionFailed, client.set, "/test-set", "test-key"
91-
)
85+
self.assertRaises(etcd.EtcdConnectionFailed, client.set, "/test-set", "test-key")
9286
self.assertRaises(etcd.EtcdConnectionFailed, client.get, "/test-set")
9387

9488
def test_get_set_authenticated(self):
@@ -117,9 +111,7 @@ def setUpClass(cls):
117111

118112
cls.client_all_cert = os.path.join(cls.directory, "client-all.crt")
119113

120-
ca, ca_key = helpers.TestingCA.create_test_ca_certificate(
121-
cls.ca_cert_path, ca_key_path
122-
)
114+
ca, ca_key = helpers.TestingCA.create_test_ca_certificate(cls.ca_cert_path, ca_key_path)
123115

124116
helpers.TestingCA.create_test_certificate(
125117
ca, ca_key, server_cert_path, server_key_path, "127.0.0.1"
@@ -159,9 +151,7 @@ def test_get_set_unauthenticated(self):
159151
client = etcd.Client(port=6001)
160152

161153
# See above for the reason of this change
162-
self.assertRaises(
163-
etcd.EtcdException, client.set, "/test_set", "test-key"
164-
)
154+
self.assertRaises(etcd.EtcdException, client.set, "/test_set", "test-key")
165155
self.assertRaises(etcd.EtcdException, client.get, "/test_set")
166156

167157
@pytest.mark.skip(reason="We need non SHA1-signed certs and I won't implement it now.")

src/etcd/tests/test_auth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def test_read(self):
4848
self.assertEquals(u.roles, set(["root"]))
4949

5050
# The user is correctly rendered out
51-
self.assertEquals(
52-
u._to_net(), [{"user": "root", "password": None, "roles": ["root"]}]
53-
)
51+
self.assertEquals(u._to_net(), [{"user": "root", "password": None, "roles": ["root"]}])
5452

5553
# An inexistent user raises the appropriate exception
5654
u = auth.EtcdUser(self.client, "user.does.not.exist")

src/etcd/tests/unit/test_client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def test_set_username_password(self):
115115

116116
def test_get_headers_with_auth(self):
117117
client = etcd.Client(username="username", password="password")
118-
assert client._get_headers() == {
119-
"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
120-
}
118+
assert client._get_headers() == {"authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}
121119

122120
def test__set_version_info(self):
123121
"""Verify _set_version_info makes the proper call to the server"""
@@ -179,16 +177,12 @@ def test_discover(self):
179177
method = dns.name.from_text
180178
r.target = method("etcd{}.example.com".format(i))
181179
answers.append(r)
182-
dns.resolver.query = mock.create_autospec(
183-
dns.resolver.query, return_value=answers
184-
)
180+
dns.resolver.query = mock.create_autospec(dns.resolver.query, return_value=answers)
185181
self.machines = etcd.Client.machines
186182
etcd.Client.machines = mock.create_autospec(
187183
etcd.Client.machines, return_value=["https://etcd2.example.com:2379"]
188184
)
189-
c = etcd.Client(
190-
srv_domain="example.com", allow_reconnect=True, protocol="https"
191-
)
185+
c = etcd.Client(srv_domain="example.com", allow_reconnect=True, protocol="https")
192186
etcd.Client.machines = self.machines
193187
self.assertEqual(c.host, "etcd1.example.com")
194188
self.assertEqual(c.port, 2379)

src/etcd/tests/unit/test_lock.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def side_effect():
149149
}
150150
self._mock_api(200, d)
151151

152-
self.locker._get_locker = mock.create_autospec(self.locker._get_locker, side_effect=side_effect)
152+
self.locker._get_locker = mock.create_autospec(
153+
self.locker._get_locker, side_effect=side_effect
154+
)
153155
self.assertTrue(self.locker._acquired())
154156

155157
def test_lock_key(self):

src/etcd/tests/unit/test_old_request.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def test_test_and_test_failure(self):
9898

9999
client = etcd.Client()
100100
client.api_execute = mock.Mock(
101-
side_effect=ValueError("The given PrevValue is not equal" " to the value of the key : TestAndSet: 1!=3")
101+
side_effect=ValueError(
102+
"The given PrevValue is not equal" " to the value of the key : TestAndSet: 1!=3"
103+
)
102104
)
103105
try:
104106
result = client.test_and_set("/testkey", "newvalue", "test", ttl=19)
@@ -145,7 +147,11 @@ def test_get(self):
145147
client.api_execute = mock.Mock(
146148
return_value=FakeHTTPResponse(
147149
200,
148-
'{"action":"GET",' '"node": {' '"key":"/testkey",' '"value":"test",' '"modifiedIndex":190}}',
150+
'{"action":"GET",'
151+
'"node": {'
152+
'"key":"/testkey",'
153+
'"value":"test",'
154+
'"modifiedIndex":190}}',
149155
)
150156
)
151157

@@ -181,7 +187,11 @@ def test_in(self):
181187
client.api_execute = mock.Mock(
182188
return_value=FakeHTTPResponse(
183189
200,
184-
'{"action":"GET",' '"node": {' '"key":"/testkey",' '"value":"test",' '"modifiedIndex":190}}',
190+
'{"action":"GET",'
191+
'"node": {'
192+
'"key":"/testkey",'
193+
'"value":"test",'
194+
'"modifiedIndex":190}}',
185195
)
186196
)
187197
result = "/testkey" in client

src/etcd/tests/unit/test_request.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ def _mock_api(self, status, d, cluster_id=None):
386386
self.client.http.request = mock.MagicMock(return_value=resp)
387387

388388
def _mock_error(self, error_code, msg, cause, method="PUT", fields=None, cluster_id=None):
389-
resp = self._prepare_response(500, {"errorCode": error_code, "message": msg, "cause": cause})
389+
resp = self._prepare_response(
390+
500, {"errorCode": error_code, "message": msg, "cause": cause}
391+
)
390392
resp.getheader.return_value = cluster_id or "abcdef1234"
391393
self.client.http.request_encode_body = mock.create_autospec(
392394
self.client.http.request_encode_body, return_value=resp
@@ -402,7 +404,9 @@ def test_watch_timeout(self):
402404
"""Exception will be raised if prevValue != value in test_set"""
403405
self.client.http.request = mock.create_autospec(
404406
self.client.http.request,
405-
side_effect=urllib3.exceptions.ReadTimeoutError(self.client.http, "foo", "Read timed out"),
407+
side_effect=urllib3.exceptions.ReadTimeoutError(
408+
self.client.http, "foo", "Read timed out"
409+
),
406410
)
407411
self.assertRaises(
408412
etcd.EtcdWatchTimedOut,
@@ -435,7 +439,9 @@ def test_read_cluster_id_changed(self):
435439
self.client.read("/testkey")
436440

437441
def test_read_connection_error(self):
438-
self.client.http.request = mock.create_autospec(self.client.http.request, side_effect=socket.error())
442+
self.client.http.request = mock.create_autospec(
443+
self.client.http.request, side_effect=socket.error()
444+
)
439445
self.assertRaises(etcd.EtcdConnectionFailed, self.client.read, "/something")
440446
# Direct GET request
441447
self.assertRaises(etcd.EtcdConnectionFailed, self.client.api_execute, "/a", "GET")

0 commit comments

Comments
 (0)