Skip to content

Commit 5c9db40

Browse files
tulinkryVladimir Kotal
authored andcommitted
reusing code in fixtures
1 parent c47b7e7 commit 5c9db40

File tree

3 files changed

+42
-98
lines changed

3 files changed

+42
-98
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import pytest
3+
4+
5+
@pytest.fixture(
6+
params=[
7+
pytest.param('/bin/true', marks=pytest.mark.skipif(not os.path.exists('/bin/true'), reason="requires /bin binaries")),
8+
pytest.param('/usr/bin/true', marks=pytest.mark.skipif(not os.path.exists('/usr/bin/true'), reason="requires /usr/bin binaries"))
9+
]
10+
)
11+
def true_binary(request):
12+
return request.param
13+
14+
15+
@pytest.fixture(
16+
params=[
17+
pytest.param('/bin/false', marks=pytest.mark.skipif(not os.path.exists('/bin/false'), reason="requires /bin binaries")),
18+
pytest.param('/usr/bin/false', marks=pytest.mark.skipif(not os.path.exists('/usr/bin/false'), reason="requires /usr/bin binaries"))
19+
]
20+
)
21+
def false_binary(request):
22+
return request.param
23+
24+
25+
@pytest.fixture(
26+
params=[
27+
pytest.param('/bin/touch', marks=pytest.mark.skipif(not os.path.exists('/bin/touch'), reason="requires /bin binaries")),
28+
pytest.param('/usr/bin/touch', marks=pytest.mark.skipif(not os.path.exists('/usr/bin/touch'), reason="requires /usr/bin binaries"))
29+
]
30+
)
31+
def touch_binary(request):
32+
return request.param
33+
34+
35+
@pytest.fixture(
36+
params=[
37+
pytest.param('/bin/echo', marks=pytest.mark.skipif(not os.path.exists('/bin/echo'), reason="requires /bin binaries")),
38+
pytest.param('/usr/bin/echo', marks=pytest.mark.skipif(not os.path.exists('/usr/bin/echo'), reason="requires /usr/bin binaries"))
39+
]
40+
)
41+
def echo_binary(request):
42+
return request.param

opengrok-tools/src/test/python/test_command.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,6 @@ def test_env():
101101
assert "FOO=BAR\n" in cmd.getoutput()
102102

103103

104-
@pytest.mark.parametrize(
105-
('true_binary', 'false_binary'), [
106-
pytest.param('/bin/true', '/bin/false',
107-
marks=pytest.mark.skipif(
108-
not os.path.exists('/bin/true') or
109-
not os.path.exists('/bin/false'),
110-
reason="requires /bin binaries")),
111-
pytest.param('/usr/bin/true', '/usr/bin/false',
112-
marks=pytest.mark.skipif(
113-
not os.path.exists('/usr/bin/true') or
114-
not os.path.exists('/usr/bin/false'),
115-
reason="requires /usr/bin binaries")),
116-
]
117-
)
118104
def test_retcode(true_binary, false_binary):
119105
cmd = Command([false_binary])
120106
cmd.execute()

opengrok-tools/src/test/python/test_mirror.py

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,6 @@ def test_mirroring_custom_repository_command(expected_command, config):
359359
assert expected_command == Repository._repository_command(config, lambda: DEFAULT_COMMAND)
360360

361361

362-
@pytest.mark.parametrize(
363-
('touch_binary'), [
364-
pytest.param('/bin/touch',
365-
marks=pytest.mark.skipif(
366-
not os.path.exists('/bin/touch'),
367-
reason="requires /bin binaries")),
368-
pytest.param('/usr/bin/touch',
369-
marks=pytest.mark.skipif(
370-
not os.path.exists('/usr/bin/touch'),
371-
reason="requires /usr/bin binaries")),
372-
]
373-
)
374362
def test_mirroring_custom_incoming_invoke_command(touch_binary):
375363
checking_file = 'incoming.txt'
376364
with tempfile.TemporaryDirectory() as repository_root:
@@ -381,18 +369,6 @@ def test_mirroring_custom_incoming_invoke_command(touch_binary):
381369
assert checking_file in os.listdir(repository_root)
382370

383371

384-
@pytest.mark.parametrize(
385-
('echo_binary'), [
386-
pytest.param('/bin/echo',
387-
marks=pytest.mark.skipif(
388-
not os.path.exists('/bin/echo'),
389-
reason="requires /bin binaries")),
390-
pytest.param('/usr/bin/echo',
391-
marks=pytest.mark.skipif(
392-
not os.path.exists('/usr/bin/echo'),
393-
reason="requires /usr/bin binaries")),
394-
]
395-
)
396372
def test_mirroring_custom_incoming_changes(echo_binary):
397373
with tempfile.TemporaryDirectory() as repository_root:
398374
repository = GitRepository(mock(), repository_root, 'test-1', {
@@ -401,18 +377,6 @@ def test_mirroring_custom_incoming_changes(echo_binary):
401377
assert repository.incoming() is True
402378

403379

404-
@pytest.mark.parametrize(
405-
('true_binary'), [
406-
pytest.param('/bin/true',
407-
marks=pytest.mark.skipif(
408-
not os.path.exists('/bin/true'),
409-
reason="requires /bin binaries")),
410-
pytest.param('/usr/bin/true',
411-
marks=pytest.mark.skipif(
412-
not os.path.exists('/usr/bin/true'),
413-
reason="requires /usr/bin binaries")),
414-
]
415-
)
416380
def test_mirroring_custom_incoming_no_changes(true_binary):
417381
with tempfile.TemporaryDirectory() as repository_root:
418382
repository = GitRepository(mock(), repository_root, 'test-1', {
@@ -421,18 +385,6 @@ def test_mirroring_custom_incoming_no_changes(true_binary):
421385
assert repository.incoming() is False
422386

423387

424-
@pytest.mark.parametrize(
425-
('false_binary'), [
426-
pytest.param('/bin/false',
427-
marks=pytest.mark.skipif(
428-
not os.path.exists('/bin/false'),
429-
reason="requires /bin binaries")),
430-
pytest.param('/usr/bin/false',
431-
marks=pytest.mark.skipif(
432-
not os.path.exists('/usr/bin/false'),
433-
reason="requires /usr/bin binaries")),
434-
]
435-
)
436388
def test_mirroring_custom_incoming_error(false_binary):
437389
with pytest.raises(RepositoryException):
438390
with tempfile.TemporaryDirectory() as repository_root:
@@ -451,18 +403,6 @@ def test_mirroring_incoming_invoke_original_command():
451403
verify(repository).incoming_check()
452404

453405

454-
@pytest.mark.parametrize(
455-
('touch_binary'), [
456-
pytest.param('/bin/touch',
457-
marks=pytest.mark.skipif(
458-
not os.path.exists('/bin/touch'),
459-
reason="requires /bin binaries")),
460-
pytest.param('/usr/bin/touch',
461-
marks=pytest.mark.skipif(
462-
not os.path.exists('/usr/bin/touch'),
463-
reason="requires /usr/bin binaries")),
464-
]
465-
)
466406
def test_mirroring_custom_sync_invoke_command(touch_binary):
467407
checking_file = 'sync.txt'
468408
with tempfile.TemporaryDirectory() as repository_root:
@@ -473,18 +413,6 @@ def test_mirroring_custom_sync_invoke_command(touch_binary):
473413
assert checking_file in os.listdir(repository_root)
474414

475415

476-
@pytest.mark.parametrize(
477-
('true_binary'), [
478-
pytest.param('/bin/true',
479-
marks=pytest.mark.skipif(
480-
not os.path.exists('/bin/true'),
481-
reason="requires /bin binaries")),
482-
pytest.param('/usr/bin/true',
483-
marks=pytest.mark.skipif(
484-
not os.path.exists('/usr/bin/true'),
485-
reason="requires /usr/bin binaries")),
486-
]
487-
)
488416
def test_mirroring_custom_sync_success(true_binary):
489417
with tempfile.TemporaryDirectory() as repository_root:
490418
repository = GitRepository(mock(), repository_root, 'test-1', {
@@ -493,18 +421,6 @@ def test_mirroring_custom_sync_success(true_binary):
493421
assert 0 == repository.sync()
494422

495423

496-
@pytest.mark.parametrize(
497-
('false_binary'), [
498-
pytest.param('/bin/false',
499-
marks=pytest.mark.skipif(
500-
not os.path.exists('/bin/false'),
501-
reason="requires /bin binaries")),
502-
pytest.param('/usr/bin/false',
503-
marks=pytest.mark.skipif(
504-
not os.path.exists('/usr/bin/false'),
505-
reason="requires /usr/bin binaries")),
506-
]
507-
)
508424
def test_mirroring_custom_sync_error(false_binary):
509425
with tempfile.TemporaryDirectory() as repository_root:
510426
repository = GitRepository(mock(), repository_root, 'test-1', {

0 commit comments

Comments
 (0)