1
- import os
2
1
import pytest
3
2
from click .testing import CliRunner
4
3
from cffconvert .cli .cli import cli as cffconvert
5
4
from tests .cli .helpers import get_formats
5
+ from tests .cli .helpers import read_sibling_file
6
6
7
7
8
8
@pytest .fixture (scope = "module" )
9
9
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" )
18
11
19
12
20
13
def test_local_cff_file_does_not_exist ():
@@ -42,9 +35,9 @@ def test_printing_of_version():
42
35
assert result .output == "3.0.0a0\n "
43
36
44
37
45
- @pytest .mark .parametrize ("fmt,fname" , get_formats ())
38
+ @pytest .mark .parametrize ("fmt, fname" , get_formats ())
46
39
def test_printing_on_stdout (fmt , fname , cffstr ):
47
- expected = read_sibling_file (fname )
40
+ expected = read_sibling_file (__file__ , fname )
48
41
runner = CliRunner ()
49
42
with runner .isolated_filesystem ():
50
43
with open ("CITATION.cff" , "wt" , encoding = "utf-8" ) as fid :
@@ -55,8 +48,7 @@ def test_printing_on_stdout(fmt, fname, cffstr):
55
48
assert expected == actual
56
49
57
50
58
- def test_raising_error_on_unsupported_format ():
59
- cffstr = read_sibling_file ("CITATION.cff" )
51
+ def test_raising_error_on_unsupported_format (cffstr ):
60
52
runner = CliRunner ()
61
53
with runner .isolated_filesystem ():
62
54
with open ("CITATION.cff" , "wt" , encoding = "utf-8" ) as fid :
@@ -75,9 +67,9 @@ def test_without_arguments():
75
67
assert result .exception .strerror == "No such file or directory"
76
68
77
69
78
- @pytest .mark .parametrize ("fmt,fname" , get_formats ())
70
+ @pytest .mark .parametrize ("fmt, fname" , get_formats ())
79
71
def test_writing_to_file (fmt , fname , cffstr ):
80
- expected = read_sibling_file (fname )
72
+ expected = read_sibling_file (__file__ , fname )
81
73
runner = CliRunner ()
82
74
with runner .isolated_filesystem ():
83
75
with open ("CITATION.cff" , "wt" , encoding = "utf-8" ) as fid :
0 commit comments