Skip to content

Commit 76ce3de

Browse files
Changes for black compliance
1 parent e704175 commit 76ce3de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1858
-2051
lines changed

test/conftest.py

Lines changed: 186 additions & 234 deletions
Large diffs are not rendered by default.

test/test_alt.py

Lines changed: 116 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
TEST_PATHS = [utils.ALT_FILE1, utils.ALT_FILE2, utils.ALT_DIR]
1010

1111

12-
@pytest.mark.usefixtures('ds1_copy')
13-
@pytest.mark.parametrize('yadm_alt', [True, False], ids=['alt', 'worktree'])
12+
@pytest.mark.usefixtures("ds1_copy")
13+
@pytest.mark.parametrize("yadm_alt", [True, False], ids=["alt", "worktree"])
1414
@pytest.mark.parametrize(
15-
'tracked,encrypt,exclude', [
15+
"tracked,encrypt,exclude",
16+
[
1617
(False, False, False),
1718
(True, False, False),
1819
(False, True, False),
1920
(False, True, True),
20-
], ids=['untracked', 'tracked', 'encrypted', 'excluded'])
21-
def test_alt_source(
22-
runner, paths,
23-
tracked, encrypt, exclude,
24-
yadm_alt):
21+
],
22+
ids=["untracked", "tracked", "encrypted", "excluded"],
23+
)
24+
def test_alt_source(runner, paths, tracked, encrypt, exclude, yadm_alt):
2525
"""Test yadm alt operates on all expected sources of alternates"""
2626
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
2727

2828
utils.create_alt_files(
29-
paths, '##default', tracked=tracked, encrypt=encrypt, exclude=exclude,
30-
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
31-
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
29+
paths, "##default", tracked=tracked, encrypt=encrypt, exclude=exclude, yadm_alt=yadm_alt, yadm_dir=yadm_dir
30+
)
31+
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
3232
assert run.success
33-
assert run.err == ''
33+
assert run.err == ""
3434
linked = utils.parse_alt_output(run.out)
3535

36-
basepath = yadm_dir.join('alt') if yadm_alt else paths.work
36+
basepath = yadm_dir.join("alt") if yadm_alt else paths.work
3737

3838
for link_path in TEST_PATHS:
39-
source_file_content = link_path + '##default'
39+
source_file_content = link_path + "##default"
4040
source_file = basepath.join(source_file_content)
4141
link_file = paths.work.join(link_path)
4242
if tracked or (encrypt and not exclude):
@@ -46,63 +46,69 @@ def test_alt_source(
4646
assert link_file.read() == source_file_content
4747
assert str(source_file) in linked
4848
else:
49-
assert link_file.join(
50-
utils.CONTAINED).read() == source_file_content
49+
assert link_file.join(utils.CONTAINED).read() == source_file_content
5150
assert str(source_file) in linked
5251
else:
5352
assert not link_file.exists()
5453
assert str(source_file) not in linked
5554

5655

57-
@pytest.mark.usefixtures('ds1_copy')
58-
@pytest.mark.parametrize('yadm_alt', [True, False], ids=['alt', 'worktree'])
56+
@pytest.mark.usefixtures("ds1_copy")
57+
@pytest.mark.parametrize("yadm_alt", [True, False], ids=["alt", "worktree"])
5958
def test_relative_link(runner, paths, yadm_alt):
6059
"""Confirm links created are relative"""
6160
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
6261

6362
utils.create_alt_files(
64-
paths, '##default', tracked=True, encrypt=False, exclude=False,
65-
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
66-
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
63+
paths, "##default", tracked=True, encrypt=False, exclude=False, yadm_alt=yadm_alt, yadm_dir=yadm_dir
64+
)
65+
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
6766
assert run.success
68-
assert run.err == ''
67+
assert run.err == ""
6968

70-
basepath = yadm_dir.join('alt') if yadm_alt else paths.work
69+
basepath = yadm_dir.join("alt") if yadm_alt else paths.work
7170

7271
for link_path in TEST_PATHS:
73-
source_file_content = link_path + '##default'
72+
source_file_content = link_path + "##default"
7473
source_file = basepath.join(source_file_content)
7574
link_file = paths.work.join(link_path)
7675
link = link_file.readlink()
77-
relpath = os.path.relpath(
78-
source_file, start=os.path.dirname(link_file))
76+
relpath = os.path.relpath(source_file, start=os.path.dirname(link_file))
7977
assert link == relpath
8078

8179

82-
@pytest.mark.usefixtures('ds1_copy')
83-
@pytest.mark.parametrize('suffix', [
84-
'##default',
85-
'##default,e.txt', '##default,extension.txt',
86-
'##a.$tst_arch', '##arch.$tst_arch',
87-
'##o.$tst_sys', '##os.$tst_sys',
88-
'##d.$tst_distro', '##distro.$tst_distro',
89-
'##f.$tst_distro_family', '##distro_family.$tst_distro_family',
90-
'##c.$tst_class', '##class.$tst_class',
91-
'##h.$tst_host', '##hostname.$tst_host',
92-
'##u.$tst_user', '##user.$tst_user',
93-
])
94-
def test_alt_conditions(
95-
runner, paths,
96-
tst_arch, tst_sys, tst_distro, tst_distro_family, tst_host, tst_user,
97-
suffix):
80+
@pytest.mark.usefixtures("ds1_copy")
81+
@pytest.mark.parametrize(
82+
"suffix",
83+
[
84+
"##default",
85+
"##default,e.txt",
86+
"##default,extension.txt",
87+
"##a.$tst_arch",
88+
"##arch.$tst_arch",
89+
"##o.$tst_sys",
90+
"##os.$tst_sys",
91+
"##d.$tst_distro",
92+
"##distro.$tst_distro",
93+
"##f.$tst_distro_family",
94+
"##distro_family.$tst_distro_family",
95+
"##c.$tst_class",
96+
"##class.$tst_class",
97+
"##h.$tst_host",
98+
"##hostname.$tst_host",
99+
"##u.$tst_user",
100+
"##user.$tst_user",
101+
],
102+
)
103+
def test_alt_conditions(runner, paths, tst_arch, tst_sys, tst_distro, tst_distro_family, tst_host, tst_user, suffix):
98104
"""Test conditions supported by yadm alt"""
99105
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
100106

101107
# set the class
102-
tst_class = 'testclass'
103-
utils.set_local(paths, 'class', tst_class + ".before")
104-
utils.set_local(paths, 'class', tst_class, add=True)
105-
utils.set_local(paths, 'class', tst_class + ".after", add=True)
108+
tst_class = "testclass"
109+
utils.set_local(paths, "class", tst_class + ".before")
110+
utils.set_local(paths, "class", tst_class, add=True)
111+
utils.set_local(paths, "class", tst_class + ".after", add=True)
106112

107113
suffix = string.Template(suffix).substitute(
108114
tst_arch=tst_arch,
@@ -115,9 +121,9 @@ def test_alt_conditions(
115121
)
116122

117123
utils.create_alt_files(paths, suffix)
118-
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
124+
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
119125
assert run.success
120-
assert run.err == ''
126+
assert run.err == ""
121127
linked = utils.parse_alt_output(run.out)
122128

123129
for link_path in TEST_PATHS:
@@ -128,27 +134,31 @@ def test_alt_conditions(
128134
assert paths.work.join(link_path).read() == source_file
129135
assert str(paths.work.join(source_file)) in linked
130136
else:
131-
assert paths.work.join(link_path).join(
132-
utils.CONTAINED).read() == source_file
137+
assert paths.work.join(link_path).join(utils.CONTAINED).read() == source_file
133138
assert str(paths.work.join(source_file)) in linked
134139

135140

136-
@pytest.mark.usefixtures('ds1_copy')
141+
@pytest.mark.usefixtures("ds1_copy")
142+
@pytest.mark.parametrize("kind", ["default", "", None, "envtpl", "j2cli", "j2", "esh"])
137143
@pytest.mark.parametrize(
138-
'kind', ['default', '', None, 'envtpl', 'j2cli', 'j2', 'esh'])
139-
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
140-
def test_alt_templates(
141-
runner, paths, kind, label):
144+
"label",
145+
[
146+
"t",
147+
"template",
148+
"yadm",
149+
],
150+
)
151+
def test_alt_templates(runner, paths, kind, label):
142152
"""Test templates supported by yadm alt"""
143153
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
144154

145-
suffix = f'##{label}.{kind}'
155+
suffix = f"##{label}.{kind}"
146156
if kind is None:
147-
suffix = f'##{label}'
157+
suffix = f"##{label}"
148158
utils.create_alt_files(paths, suffix)
149-
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
159+
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
150160
assert run.success
151-
assert run.err == ''
161+
assert run.err == ""
152162
created = utils.parse_alt_output(run.out, linked=False)
153163

154164
for created_path in TEST_PATHS:
@@ -159,41 +169,39 @@ def test_alt_templates(
159169
assert str(paths.work.join(source_file)) in created
160170

161171

162-
@pytest.mark.usefixtures('ds1_copy')
163-
@pytest.mark.parametrize('autoalt', [None, 'true', 'false'])
172+
@pytest.mark.usefixtures("ds1_copy")
173+
@pytest.mark.parametrize("autoalt", [None, "true", "false"])
164174
def test_auto_alt(runner, yadm_cmd, paths, autoalt):
165175
"""Test auto alt"""
166176

167177
# set the value of auto-alt
168178
if autoalt:
169-
os.system(' '.join(yadm_cmd('config', 'yadm.auto-alt', autoalt)))
179+
os.system(" ".join(yadm_cmd("config", "yadm.auto-alt", autoalt)))
170180

171-
utils.create_alt_files(paths, '##default')
172-
run = runner(yadm_cmd('status'))
181+
utils.create_alt_files(paths, "##default")
182+
run = runner(yadm_cmd("status"))
173183
assert run.success
174-
assert run.err == ''
184+
assert run.err == ""
175185
linked = utils.parse_alt_output(run.out)
176186

177187
for link_path in TEST_PATHS:
178-
source_file = link_path + '##default'
179-
if autoalt == 'false':
188+
source_file = link_path + "##default"
189+
if autoalt == "false":
180190
assert not paths.work.join(link_path).exists()
181191
else:
182192
assert paths.work.join(link_path).islink()
183-
target = py.path.local(
184-
os.path.realpath(paths.work.join(link_path)))
193+
target = py.path.local(os.path.realpath(paths.work.join(link_path)))
185194
if target.isfile():
186195
assert paths.work.join(link_path).read() == source_file
187196
# no linking output when run via auto-alt
188197
assert str(paths.work.join(source_file)) not in linked
189198
else:
190-
assert paths.work.join(link_path).join(
191-
utils.CONTAINED).read() == source_file
199+
assert paths.work.join(link_path).join(utils.CONTAINED).read() == source_file
192200
# no linking output when run via auto-alt
193201
assert str(paths.work.join(source_file)) not in linked
194202

195203

196-
@pytest.mark.usefixtures('ds1_copy')
204+
@pytest.mark.usefixtures("ds1_copy")
197205
def test_stale_link_removal(runner, yadm_cmd, paths):
198206
"""Stale links to alternative files are removed
199207
@@ -202,48 +210,47 @@ def test_stale_link_removal(runner, yadm_cmd, paths):
202210
"""
203211

204212
# set the class
205-
tst_class = 'testclass'
206-
utils.set_local(paths, 'class', tst_class)
213+
tst_class = "testclass"
214+
utils.set_local(paths, "class", tst_class)
207215

208216
# create files which match the test class
209-
utils.create_alt_files(paths, f'##class.{tst_class}')
217+
utils.create_alt_files(paths, f"##class.{tst_class}")
210218

211219
# run alt to trigger linking
212-
run = runner(yadm_cmd('alt'))
220+
run = runner(yadm_cmd("alt"))
213221
assert run.success
214-
assert run.err == ''
222+
assert run.err == ""
215223
linked = utils.parse_alt_output(run.out)
216224

217225
# assert the proper linking has occurred
218226
for stale_path in TEST_PATHS:
219-
source_file = stale_path + '##class.' + tst_class
227+
source_file = stale_path + "##class." + tst_class
220228
assert paths.work.join(stale_path).islink()
221229
target = py.path.local(os.path.realpath(paths.work.join(stale_path)))
222230
if target.isfile():
223231
assert paths.work.join(stale_path).read() == source_file
224232
assert str(paths.work.join(source_file)) in linked
225233
else:
226-
assert paths.work.join(stale_path).join(
227-
utils.CONTAINED).read() == source_file
234+
assert paths.work.join(stale_path).join(utils.CONTAINED).read() == source_file
228235
assert str(paths.work.join(source_file)) in linked
229236

230237
# change the class so there are no valid alternates
231-
utils.set_local(paths, 'class', 'changedclass')
238+
utils.set_local(paths, "class", "changedclass")
232239

233240
# run alt to trigger linking
234-
run = runner(yadm_cmd('alt'))
241+
run = runner(yadm_cmd("alt"))
235242
assert run.success
236-
assert run.err == ''
243+
assert run.err == ""
237244
linked = utils.parse_alt_output(run.out)
238245

239246
# assert the linking is removed
240247
for stale_path in TEST_PATHS:
241-
source_file = stale_path + '##class.' + tst_class
248+
source_file = stale_path + "##class." + tst_class
242249
assert not paths.work.join(stale_path).exists()
243250
assert str(paths.work.join(source_file)) not in linked
244251

245252

246-
@pytest.mark.usefixtures('ds1_repo_copy')
253+
@pytest.mark.usefixtures("ds1_repo_copy")
247254
def test_template_overwrite_symlink(runner, yadm_cmd, paths, tst_sys):
248255
"""Remove symlinks before processing a template
249256
@@ -252,45 +259,44 @@ def test_template_overwrite_symlink(runner, yadm_cmd, paths, tst_sys):
252259
be removed just before processing a template.
253260
"""
254261

255-
target = paths.work.join(f'test_link##os.{tst_sys}')
256-
target.write('target')
262+
target = paths.work.join(f"test_link##os.{tst_sys}")
263+
target.write("target")
257264

258-
link = paths.work.join('test_link')
265+
link = paths.work.join("test_link")
259266
link.mksymlinkto(target, absolute=1)
260267

261-
template = paths.work.join('test_link##template.default')
262-
template.write('test-data')
268+
template = paths.work.join("test_link##template.default")
269+
template.write("test-data")
263270

264-
run = runner(yadm_cmd('add', target, template))
271+
run = runner(yadm_cmd("add", target, template))
265272
assert run.success
266-
assert run.err == ''
267-
assert run.out == ''
273+
assert run.err == ""
274+
assert run.out == ""
268275
assert not link.islink()
269-
assert target.read().strip() == 'target'
270-
assert link.read().strip() == 'test-data'
276+
assert target.read().strip() == "target"
277+
assert link.read().strip() == "test-data"
271278

272279

273-
@pytest.mark.usefixtures('ds1_copy')
274-
@pytest.mark.parametrize('style', ['symlink', 'template'])
280+
@pytest.mark.usefixtures("ds1_copy")
281+
@pytest.mark.parametrize("style", ["symlink", "template"])
275282
def test_ensure_alt_path(runner, paths, style):
276283
"""Test that directories are created before making alternates"""
277284
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
278-
suffix = 'default' if style == 'symlink' else 'template'
279-
filename = 'a/b/c/file'
280-
source = yadm_dir.join(f'alt/{filename}##{suffix}')
281-
source.write('test-data', ensure=True)
282-
run = runner([
283-
paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'add', source])
285+
suffix = "default" if style == "symlink" else "template"
286+
filename = "a/b/c/file"
287+
source = yadm_dir.join(f"alt/{filename}##{suffix}")
288+
source.write("test-data", ensure=True)
289+
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "add", source])
284290
assert run.success
285-
assert run.err == ''
286-
assert run.out == ''
287-
assert paths.work.join(filename).read().strip() == 'test-data'
291+
assert run.err == ""
292+
assert run.out == ""
293+
assert paths.work.join(filename).read().strip() == "test-data"
288294

289295

290296
def setup_standard_yadm_dir(paths):
291297
"""Configure a yadm home within the work tree"""
292-
std_yadm_dir = paths.work.mkdir('.config').mkdir('yadm')
293-
std_yadm_data = paths.work.mkdir('.local').mkdir('share').mkdir('yadm')
294-
std_yadm_data.join('repo.git').mksymlinkto(paths.repo, absolute=1)
295-
std_yadm_dir.join('encrypt').mksymlinkto(paths.encrypt, absolute=1)
298+
std_yadm_dir = paths.work.mkdir(".config").mkdir("yadm")
299+
std_yadm_data = paths.work.mkdir(".local").mkdir("share").mkdir("yadm")
300+
std_yadm_data.join("repo.git").mksymlinkto(paths.repo, absolute=1)
301+
std_yadm_dir.join("encrypt").mksymlinkto(paths.encrypt, absolute=1)
296302
return std_yadm_dir, std_yadm_data

0 commit comments

Comments
 (0)