Skip to content

Commit 8398272

Browse files
committed
fiddled some more with cli tests; fixed linter error
1 parent 69b721e commit 8398272

File tree

5 files changed

+14
-34
lines changed

5 files changed

+14
-34
lines changed

tests/cli/cff_1_0_3/test_cli.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import os
21
import pytest
32
from click.testing import CliRunner
43
from cffconvert.cli.cli import cli as cffconvert
54
from tests.cli.helpers import get_formats
5+
from tests.cli.helpers import read_sibling_file
66

77

88
@pytest.fixture(scope="module")
99
def cffstr():
10-
return read_sibling_file("CITATION.cff")
11-
12-
13-
def read_sibling_file(filename):
14-
mydir = os.path.dirname(__file__)
15-
fixture = os.path.join(mydir, filename)
16-
with open(fixture, "rt", encoding="utf-8") as fid:
17-
return fid.read()
10+
return read_sibling_file(__file__, "CITATION.cff")
1811

1912

2013
def test_local_cff_file_does_not_exist():
@@ -42,9 +35,9 @@ def test_printing_of_version():
4235
assert result.output == "3.0.0a0\n"
4336

4437

45-
@pytest.mark.parametrize("fmt,fname", get_formats())
38+
@pytest.mark.parametrize("fmt, fname", get_formats())
4639
def test_printing_on_stdout(fmt, fname, cffstr):
47-
expected = read_sibling_file(fname)
40+
expected = read_sibling_file(__file__, fname)
4841
runner = CliRunner()
4942
with runner.isolated_filesystem():
5043
with open("CITATION.cff", "wt", encoding="utf-8") as fid:
@@ -55,8 +48,7 @@ def test_printing_on_stdout(fmt, fname, cffstr):
5548
assert expected == actual
5649

5750

58-
def test_raising_error_on_unsupported_format():
59-
cffstr = read_sibling_file("CITATION.cff")
51+
def test_raising_error_on_unsupported_format(cffstr):
6052
runner = CliRunner()
6153
with runner.isolated_filesystem():
6254
with open("CITATION.cff", "wt", encoding="utf-8") as fid:
@@ -75,9 +67,9 @@ def test_without_arguments():
7567
assert result.exception.strerror == "No such file or directory"
7668

7769

78-
@pytest.mark.parametrize("fmt,fname", get_formats())
70+
@pytest.mark.parametrize("fmt, fname", get_formats())
7971
def test_writing_to_file(fmt, fname, cffstr):
80-
expected = read_sibling_file(fname)
72+
expected = read_sibling_file(__file__, fname)
8173
runner = CliRunner()
8274
with runner.isolated_filesystem():
8375
with open("CITATION.cff", "wt", encoding="utf-8") as fid:

tests/cli/cff_1_1_0/test_cli.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def test_printing_on_stdout(fmt, fname, cffstr):
4848
assert expected == actual
4949

5050

51-
def test_raising_error_on_unsupported_format():
52-
cffstr = read_sibling_file(__file__, "CITATION.cff")
51+
def test_raising_error_on_unsupported_format(cffstr):
5352
runner = CliRunner()
5453
with runner.isolated_filesystem():
5554
with open("CITATION.cff", "wt", encoding="utf-8") as fid:

tests/cli/cff_1_2_0/test_cli.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import os
21
import pytest
32
from click.testing import CliRunner
43
from cffconvert.cli.cli import cli as cffconvert
54
from tests.cli.helpers import get_formats
5+
from tests.cli.helpers import read_sibling_file
66

77

88
@pytest.fixture(scope="module")
99
def cffstr():
10-
return read_sibling_file("CITATION.cff")
11-
12-
13-
def read_sibling_file(filename):
14-
mydir = os.path.dirname(__file__)
15-
fixture = os.path.join(mydir, filename)
16-
with open(fixture, "rt", encoding="utf-8") as fid:
17-
return fid.read()
10+
return read_sibling_file(__file__, "CITATION.cff")
1811

1912

2013
def test_local_cff_file_does_not_exist():
@@ -44,7 +37,7 @@ def test_printing_of_version():
4437

4538
@pytest.mark.parametrize("fmt, fname", get_formats())
4639
def test_printing_on_stdout(fmt, fname, cffstr):
47-
expected = read_sibling_file(fname)
40+
expected = read_sibling_file(__file__, fname)
4841
runner = CliRunner()
4942
with runner.isolated_filesystem():
5043
with open("CITATION.cff", "wt", encoding="utf-8") as fid:
@@ -55,8 +48,7 @@ def test_printing_on_stdout(fmt, fname, cffstr):
5548
assert expected == actual
5649

5750

58-
def test_raising_error_on_unsupported_format():
59-
cffstr = read_sibling_file("CITATION.cff")
51+
def test_raising_error_on_unsupported_format(cffstr):
6052
runner = CliRunner()
6153
with runner.isolated_filesystem():
6254
with open("CITATION.cff", "wt", encoding="utf-8") as fid:
@@ -77,7 +69,7 @@ def test_without_arguments():
7769

7870
@pytest.mark.parametrize("fmt, fname", get_formats())
7971
def test_writing_to_file(fmt, fname, cffstr):
80-
expected = read_sibling_file(fname)
72+
expected = read_sibling_file(__file__, fname)
8173
runner = CliRunner()
8274
with runner.isolated_filesystem():
8375
with open("CITATION.cff", "wt", encoding="utf-8") as fid:

tests/cli/cff_1_3_0/test_cli.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def test_printing_on_stdout(fmt, fname, cffstr):
4848
assert expected == actual
4949

5050

51-
def test_raising_error_on_unsupported_format():
52-
cffstr = read_sibling_file(__file__, "CITATION.cff")
51+
def test_raising_error_on_unsupported_format(cffstr):
5352
runner = CliRunner()
5453
with runner.isolated_filesystem():
5554
with open("CITATION.cff", "wt", encoding="utf-8") as fid:

tests/cli/helpers.py

-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ def read_sibling_file(myfile, filename):
2020
fixture = os.path.join(mydir, filename)
2121
with open(fixture, "rt", encoding="utf-8") as fid:
2222
return fid.read()
23-
24-

0 commit comments

Comments
 (0)