Skip to content

Commit 06f3109

Browse files
committed
wrap long lines
1 parent e1c337d commit 06f3109

3 files changed

Lines changed: 172 additions & 38 deletions

File tree

tests/pypi/hub_builder/hub_builder_tests.bzl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ load("//tests/support/mocks:mocks.bzl", "mocks")
2727

2828
_tests = []
2929

30-
def _mock_mctx(os_name = "unittest", arch_name = "exotic", environ = {}, mock_files = {}):
31-
# Because mocks.mctx no longer accepts read lambda directly, we rely on mock_files.
32-
# We will populate mock_files if read is not passed.
33-
# Wait, earlier I reverted `mocks.mctx` to NOT accept read/download/report_progress args.
34-
# Ah, let's just make it use mock_files appropriately.
35-
# For tests that pass read=, they're already failing, I should just fix how they call it!
36-
# Ah! I see the issue. `test_err_duplicate_repos` is trying to pass `mock_files=` to `_mock_mctx`.
37-
# Let's just pass `mock_files=mock_files` down to `mocks.mctx`.
38-
30+
def _mock_mctx(os_name = "unittest", arch_name = "exotic", environ = {}, mock_files = None):
3931
return mocks.mctx(
4032
os_name = os_name,
4133
arch_name = arch_name,

tests/support/mocks/mocks.bzl

Lines changed: 154 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def _file_new(short_path, *, path = None, is_source = True, owner = None):
2323
2424
Args:
2525
short_path: {type}`string` The short path to the file.
26-
path: {type}`string` The full path to the file. Defaults to a made up exec-root path or the short path if is_source.
26+
path: {type}`string` The full path to the file. Defaults to a made
27+
up exec-root path or the short path if is_source.
2728
is_source: {type}`bool` Whether the file is a source file.
2829
owner: {type}`Label|string` The owner label of the file.
2930
@@ -53,7 +54,10 @@ def _file_new(short_path, *, path = None, is_source = True, owner = None):
5354
if is_source:
5455
path = "external/{}/{}".format(repo_name, rel_path)
5556
else:
56-
path = "bazel-out/k9-deadbeef/bin/external/{}/{}".format(repo_name, rel_path)
57+
path = "bazel-out/k9-deadbeef/bin/external/{}/{}".format(
58+
repo_name,
59+
rel_path,
60+
)
5761
elif path == None:
5862
if is_source:
5963
path = short_path
@@ -108,8 +112,28 @@ def _mctx_read(self, x, watch = None):
108112
def _mctx_path(self, x):
109113
return _path_new(str(x), self.mock_files)
110114

111-
def _mctx_download(self, url, output = "", sha256 = "", executable = False, allow_fail = False, canonical_id = "", auth = {}, headers = {}, integrity = "", block = True):
112-
_ = sha256, executable, allow_fail, canonical_id, auth, headers, integrity, block # @unused
115+
def _mctx_download(
116+
self,
117+
url,
118+
output = "",
119+
sha256 = "",
120+
executable = False,
121+
allow_fail = False,
122+
canonical_id = "",
123+
auth = {},
124+
headers = {},
125+
integrity = "",
126+
block = True):
127+
_ = (
128+
sha256,
129+
executable,
130+
allow_fail,
131+
canonical_id,
132+
auth,
133+
headers,
134+
integrity,
135+
block,
136+
) # @unused
113137
urls = url if type(url) == "list" else [url]
114138
for u in urls:
115139
content = None
@@ -122,9 +146,23 @@ def _mctx_download(self, url, output = "", sha256 = "", executable = False, allo
122146
if type(content) == "string":
123147
out = str(output) if output else u.split("/")[-1]
124148
self.mock_files[out] = content
125-
return struct(success = True, wait = lambda: struct(success = True))
149+
return struct(
150+
success = True,
151+
wait = lambda: struct(success = True),
152+
)
126153
else:
127-
return content(self, u, output, sha256, executable, allow_fail, canonical_id, auth, headers, integrity)
154+
return content(
155+
self,
156+
u,
157+
output,
158+
sha256,
159+
executable,
160+
allow_fail,
161+
canonical_id,
162+
auth,
163+
headers,
164+
integrity,
165+
)
128166

129167
if not self.mock_downloads:
130168
return struct(success = True, wait = lambda: struct(success = True))
@@ -146,7 +184,8 @@ def _mctx_add_module(self, **kwargs):
146184
"""
147185
module = _module_new(**kwargs)
148186
if module.is_root and len(self.modules) > 0:
149-
fail("is_root=True can only be set on the first module in the modules list.")
187+
fail("is_root=True can only be set on the first module in the " +
188+
"modules list.")
150189
self.modules.append(module)
151190
return self
152191

@@ -163,10 +202,13 @@ def _mctx_new(
163202
164203
Args:
165204
*args: {type}`list[MockModule]` Mock modules passed positionally.
166-
modules: {type}`list[MockModule]` List of mock modules (alternative to positional args).
205+
modules: {type}`list[MockModule]` List of mock modules (alternative
206+
to positional args).
167207
environ: {type}`dict[string, string]` Dict of environment variables.
168-
mock_files: {type}`dict[string, string]` Dict mapping path strings to content.
169-
mock_downloads: {type}`dict[string, string|callable]` Dict mapping url to string or callable.
208+
mock_files: {type}`dict[string, string]` Dict mapping path strings
209+
to content.
210+
mock_downloads: {type}`dict[string, string|callable]` Dict mapping
211+
url to string or callable.
170212
os_name: {type}`string` The OS name.
171213
arch_name: {type}`string` The architecture name.
172214
facts: {type}`dict` Optional facts dict.
@@ -178,7 +220,8 @@ def _mctx_new(
178220

179221
for i, mod in enumerate(modules):
180222
if getattr(mod, "is_root", False) and i != 0:
181-
fail("is_root=True can only be set on the first module in the modules list.")
223+
fail("is_root=True can only be set on the first module in the " +
224+
"modules list.")
182225

183226
environ = environ or {}
184227
mock_files = mock_files or {}
@@ -260,8 +303,26 @@ def _rctx_which(self, program):
260303
return _path_new(res, self.mock_files)
261304
return None
262305

263-
def _rctx_download(self, url, output = "", sha256 = "", executable = False, allow_fail = False, canonical_id = "", auth = {}, headers = {}, integrity = ""):
264-
_ = sha256, executable, allow_fail, canonical_id, auth, headers, integrity # @unused
306+
def _rctx_download(
307+
self,
308+
url,
309+
output = "",
310+
sha256 = "",
311+
executable = False,
312+
allow_fail = False,
313+
canonical_id = "",
314+
auth = {},
315+
headers = {},
316+
integrity = ""):
317+
_ = (
318+
sha256,
319+
executable,
320+
allow_fail,
321+
canonical_id,
322+
auth,
323+
headers,
324+
integrity,
325+
) # @unused
265326

266327
urls = url if type(url) == "list" else [url]
267328

@@ -273,14 +334,47 @@ def _rctx_download(self, url, output = "", sha256 = "", executable = False, allo
273334
self.mock_files[str(output)] = res
274335
return struct(success = True, sha256 = "mocksha256")
275336
else:
276-
return res(self, u, output, sha256, executable, allow_fail, canonical_id, auth, headers, integrity)
337+
return res(
338+
self,
339+
u,
340+
output,
341+
sha256,
342+
executable,
343+
allow_fail,
344+
canonical_id,
345+
auth,
346+
headers,
347+
integrity,
348+
)
277349

278350
if not allow_fail:
279351
fail("Download not mocked for url: " + str(urls))
280352
return struct(success = False)
281353

282-
def _rctx_download_and_extract(self, url, output = "", sha256 = "", type = "", stripPrefix = "", allow_fail = False, canonical_id = "", auth = {}, headers = {}, integrity = "", rename_files = {}):
283-
_ = sha256, type, stripPrefix, allow_fail, canonical_id, auth, headers, integrity, rename_files # @unused
354+
def _rctx_download_and_extract(
355+
self,
356+
url,
357+
output = "",
358+
sha256 = "",
359+
type = "",
360+
stripPrefix = "",
361+
allow_fail = False,
362+
canonical_id = "",
363+
auth = {},
364+
headers = {},
365+
integrity = "",
366+
rename_files = {}):
367+
_ = (
368+
sha256,
369+
type,
370+
stripPrefix,
371+
allow_fail,
372+
canonical_id,
373+
auth,
374+
headers,
375+
integrity,
376+
rename_files,
377+
) # @unused
284378

285379
urls = url if type(url) == "list" else [url]
286380

@@ -290,14 +384,42 @@ def _rctx_download_and_extract(self, url, output = "", sha256 = "", type = "", s
290384
if type(res) == "string":
291385
pass
292386
else:
293-
return res(self, u, output, sha256, type, stripPrefix, allow_fail, canonical_id, auth, headers, integrity, rename_files)
387+
return res(
388+
self,
389+
u,
390+
output,
391+
sha256,
392+
type,
393+
stripPrefix,
394+
allow_fail,
395+
canonical_id,
396+
auth,
397+
headers,
398+
integrity,
399+
rename_files,
400+
)
294401

295402
if not allow_fail:
296403
fail("Download and extract not mocked for url: " + str(urls))
297404
return struct(success = False)
298405

299-
def _rctx_execute(self, arguments, timeout = 600, quiet = True, working_directory = "", environment = {}, custom_reporter = ""):
300-
_ = self, arguments, timeout, quiet, working_directory, environment, custom_reporter # @unused
406+
def _rctx_execute(
407+
self,
408+
arguments,
409+
timeout = 600,
410+
quiet = True,
411+
working_directory = "",
412+
environment = {},
413+
custom_reporter = ""):
414+
_ = (
415+
self,
416+
arguments,
417+
timeout,
418+
quiet,
419+
working_directory,
420+
environment,
421+
custom_reporter,
422+
) # @unused
301423
return struct(return_code = 0, stdout = "", stderr = "")
302424

303425
def _rctx_symlink(self, target, link_name):
@@ -316,9 +438,12 @@ def _rctx_new(
316438
Args:
317439
attr: {type}`dict` Dict of attributes.
318440
environ: {type}`dict[string, string]` Dict of environment variables.
319-
mock_files: {type}`dict[string, string]` Dict mapping path strings to content.
320-
mock_which: {type}`dict[string, string]` Dict mapping program name to path string.
321-
mock_downloads: {type}`dict[string, string|callable]` Dict mapping url to string or callable.
441+
mock_files: {type}`dict[string, string]` Dict mapping path strings
442+
to content.
443+
mock_which: {type}`dict[string, string]` Dict mapping program
444+
name to path string.
445+
mock_downloads: {type}`dict[string, string|callable]` Dict mapping
446+
url to string or callable.
322447
os_name: {type}`string` The OS name.
323448
arch_name: {type}`string` The architecture name.
324449
@@ -348,7 +473,11 @@ def _rctx_new(
348473
template = lambda *a, **k: _rctx_template(self, *a, **k),
349474
which = lambda *a, **k: _rctx_which(self, *a, **k),
350475
download = lambda *a, **k: _rctx_download(self, *a, **k),
351-
download_and_extract = lambda *a, **k: _rctx_download_and_extract(self, *a, **k),
476+
download_and_extract = lambda *a, **k: _rctx_download_and_extract(
477+
self,
478+
*a,
479+
**k
480+
),
352481
execute = lambda *a, **k: _rctx_execute(self, *a, **k),
353482
symlink = lambda *a, **k: _rctx_symlink(self, *a, **k),
354483
)
@@ -374,7 +503,8 @@ def _glob_new():
374503
"""Create a mock glob object.
375504
376505
Returns:
377-
{type}`MockGlob` A struct with calls and results lists, and a glob function.
506+
{type}`MockGlob` A struct with calls and results lists, and a
507+
glob function.
378508
"""
379509
calls = []
380510
results = []

tests/support/mocks/mocks_tests.bzl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def _test_file(env):
3535

3636
# External repo generated file
3737
f3 = mocks.file("a/b.txt", is_source = False, owner = "@foo//:mock")
38-
env.expect.that_str(f3.path).equals("bazel-out/k9-deadbeef/bin/external/foo/a/b.txt")
38+
env.expect.that_str(f3.path).equals(
39+
"bazel-out/k9-deadbeef/bin/external/foo/a/b.txt",
40+
)
3941
env.expect.that_str(f3.short_path).equals("../foo/a/b.txt")
4042

4143
_tests.append(_test_file)
@@ -60,7 +62,9 @@ def _test_mctx(env):
6062

6163
# Test report progress
6264
mctx.report_progress("doing something")
63-
env.expect.that_collection(mctx.report_progress_calls).contains_exactly(["doing something"])
65+
env.expect.that_collection(mctx.report_progress_calls).contains_exactly([
66+
"doing something",
67+
])
6468

6569
_tests.append(_test_mctx)
6670

@@ -85,7 +89,9 @@ def _test_rctx(env):
8589
# Test template
8690
rctx.file("template.txt", "Hello {name}")
8791
rctx.template("rendered.txt", "template.txt", {"{name}": "World"})
88-
env.expect.that_str(rctx.read(mocks.path("rendered.txt"))).equals("Hello World")
92+
env.expect.that_str(rctx.read(mocks.path("rendered.txt"))).equals(
93+
"Hello World",
94+
)
8995

9096
# Test symlink reading
9197
rctx.symlink("rendered.txt", "link.txt")
@@ -100,12 +106,18 @@ def _test_glob(env):
100106
env.expect.that_collection(res).contains_exactly(["a.txt", "b.txt"])
101107
env.expect.that_collection(g.calls).has_size(1)
102108
env.expect.that_collection(g.calls[0].glob[0]).contains_exactly(["*.txt"])
103-
env.expect.that_collection(g.calls[0].kwargs["exclude"]).contains_exactly(["c.txt"])
109+
env.expect.that_collection(g.calls[0].kwargs["exclude"]).contains_exactly([
110+
"c.txt",
111+
])
104112

105113
_tests.append(_test_glob)
106114

107115
def _test_module_and_tags(env):
108-
mod = mocks.module("my_mod", is_root = True, my_tag = [mocks.tag(attr1 = "val1")])
116+
mod = mocks.module(
117+
"my_mod",
118+
is_root = True,
119+
my_tag = [mocks.tag(attr1 = "val1")],
120+
)
109121
env.expect.that_str(mod.name).equals("my_mod")
110122
env.expect.that_bool(mod.is_root).equals(True)
111123
env.expect.that_str(mod.tags.my_tag[0].attr1).equals("val1")

0 commit comments

Comments
 (0)