3
3
--------------------
4
4
"""
5
5
6
-
7
6
import os
8
7
import subprocess
9
8
@@ -16,34 +15,43 @@ def run_tox(plugin):
16
15
subprocess .check_call (
17
16
["tox" , "-c" , os .path .join (plugin , "tox.ini" ), "-e" , "py" , "--" , plugin ]
18
17
)
19
- except subprocess .CalledProcessError as e :
18
+ except subprocess .CalledProcessError :
20
19
pytest .fail ("Subprocess fail" , pytrace = True )
21
20
22
21
23
22
@pytest .mark .parametrize ("include_reader_plugin" , [True , False ])
24
23
@pytest .mark .parametrize ("include_writer_plugin" , [True , False ])
25
24
@pytest .mark .parametrize ("include_sample_data_plugin" , [True , False ])
26
25
@pytest .mark .parametrize ("include_widget_plugin" , [True , False ])
27
- def test_run_plugin_tests (copie , capsys , include_reader_plugin , include_writer_plugin , include_sample_data_plugin , include_widget_plugin ):
26
+ def test_run_plugin_tests (
27
+ copie ,
28
+ capsys ,
29
+ include_reader_plugin ,
30
+ include_writer_plugin ,
31
+ include_sample_data_plugin ,
32
+ include_widget_plugin ,
33
+ ):
28
34
"""Create a new plugin with the napari plugin template and run its tests."""
29
- result = copie .copy (extra_answers = {
30
- "plugin_name" : "foo-bar" ,
31
- "display_name" : "Foo Bar" ,
32
- "module_name" : "foo_bar" ,
33
- "short_description" : "Super fast foo for all the bars" ,
34
- "full_name" : "napari bot" ,
35
-
36
- "github_username_or_organization" : "napari" ,
37
- "include_reader_plugin" : include_reader_plugin ,
38
- "include_writer_plugin" : include_writer_plugin ,
39
- "include_sample_data_plugin" : include_sample_data_plugin ,
40
- "include_widget_plugin" : include_widget_plugin ,
41
- })
35
+ result = copie .copy (
36
+ extra_answers = {
37
+ "plugin_name" : "foo-bar" ,
38
+ "display_name" : "Foo Bar" ,
39
+ "module_name" : "foo_bar" ,
40
+ "short_description" : "Super fast foo for all the bars" ,
41
+ "full_name" : "napari bot" ,
42
+
43
+ "github_username_or_organization" : "napari" ,
44
+ "include_reader_plugin" : include_reader_plugin ,
45
+ "include_writer_plugin" : include_writer_plugin ,
46
+ "include_sample_data_plugin" : include_sample_data_plugin ,
47
+ "include_widget_plugin" : include_widget_plugin ,
48
+ }
49
+ )
42
50
43
51
assert result .exit_code == 0
44
52
assert result .exception is None
45
53
assert result .project_dir .is_dir ()
46
- with open (result .project_dir / "README.md" ) as f :
54
+ with open (result .project_dir / "README.md" ) as f :
47
55
assert f .readline () == "# foo-bar\n "
48
56
assert result .project_dir .joinpath ("src" ).is_dir ()
49
57
assert result .project_dir .joinpath ("src" , "foo_bar" , "__init__.py" ).is_file ()
@@ -59,31 +67,40 @@ def test_run_plugin_tests(copie, capsys, include_reader_plugin, include_writer_p
59
67
assert (test_path / "test_widget.py" ).is_file ()
60
68
61
69
# if all are False there are no modules or tests
62
- if True in {include_reader_plugin , include_writer_plugin , include_sample_data_plugin , include_widget_plugin }:
70
+ if True in {
71
+ include_reader_plugin ,
72
+ include_writer_plugin ,
73
+ include_sample_data_plugin ,
74
+ include_widget_plugin ,
75
+ }:
63
76
run_tox (str (result .project_dir ))
64
77
65
78
66
79
def test_run_plugin_tests_with_napari_prefix (copie , capsys ):
67
80
"""make sure it's also ok to use napari prefix."""
68
81
name = "napari-foo"
69
- result = copie .copy (extra_answers = {
70
- "plugin_name" : name ,
71
- "display_name" : "napari Foo" ,
72
- "module_name" : "napari_foo" ,
73
- "short_description" : "Super fast foo for all the bars" ,
74
- "full_name" : "napari bot" ,
75
-
76
- "github_username_or_organization" : "napari" ,
77
- })
82
+ result = copie .copy (
83
+ extra_answers = {
84
+ "plugin_name" : name ,
85
+ "display_name" : "napari Foo" ,
86
+ "module_name" : "napari_foo" ,
87
+ "short_description" : "Super fast foo for all the bars" ,
88
+ "full_name" : "napari bot" ,
89
+
90
+ "github_username_or_organization" : "napari" ,
91
+ }
92
+ )
78
93
79
94
assert result .exit_code == 0
80
95
assert result .exception is None
81
96
assert result .project_dir .is_dir ()
82
- with open (result .project_dir / "README.md" ) as f :
97
+ with open (result .project_dir / "README.md" ) as f :
83
98
assert f .readline () == f"# { name } \n "
84
99
assert result .project_dir .joinpath ("src" ).is_dir ()
85
100
assert result .project_dir .joinpath ("src" , "napari_foo" , "__init__.py" ).is_file ()
86
- assert result .project_dir .joinpath ("src" , "napari_foo" , "_tests" , "test_reader.py" ).is_file ()
101
+ assert result .project_dir .joinpath (
102
+ "src" , "napari_foo" , "_tests" , "test_reader.py"
103
+ ).is_file ()
87
104
88
105
89
106
def test_run_select_plugins (copie , capsys ):
@@ -106,11 +123,13 @@ def test_run_select_plugins(copie, capsys):
106
123
assert result .exit_code == 0
107
124
assert result .exception is None
108
125
assert result .project_dir .is_dir ()
109
- with open (result .project_dir / "README.md" ) as f :
126
+ with open (result .project_dir / "README.md" ) as f :
110
127
assert f .readline () == f"# { name } \n "
111
128
assert result .project_dir .joinpath ("src" ).is_dir ()
112
129
assert result .project_dir .joinpath ("src" , name , "__init__.py" ).is_file ()
113
- assert result .project_dir .joinpath ("src" , name , "_tests" , "test_reader.py" ).is_file ()
130
+ assert result .project_dir .joinpath (
131
+ "src" , name , "_tests" , "test_reader.py"
132
+ ).is_file ()
114
133
115
134
assert not result .project_dir .joinpath ("src" , "anything" , "_widget.py" ).is_file ()
116
135
assert not result .project_dir .joinpath (
@@ -126,7 +145,13 @@ def test_run_select_plugins(copie, capsys):
126
145
@pytest .mark .parametrize ("include_writer_plugin" , [True , False ])
127
146
@pytest .mark .parametrize ("include_sample_data_plugin" , [True , False ])
128
147
@pytest .mark .parametrize ("include_widget_plugin" , [True , False ])
129
- def test_pre_commit_validity (copie , include_reader_plugin , include_writer_plugin , include_sample_data_plugin , include_widget_plugin ):
148
+ def test_pre_commit_validity (
149
+ copie ,
150
+ include_reader_plugin ,
151
+ include_writer_plugin ,
152
+ include_sample_data_plugin ,
153
+ include_widget_plugin ,
154
+ ):
130
155
result = copie .copy (
131
156
extra_answers = {
132
157
"plugin_name" : "anything" ,
@@ -145,6 +170,13 @@ def test_pre_commit_validity(copie, include_reader_plugin, include_writer_plugin
145
170
)
146
171
result .project_dir .joinpath ("setup.cfg" ).is_file ()
147
172
try :
148
- subprocess .run (["pre-commit" , "run" , "--all" , "--show-diff-on-failure" ], cwd = str (result .project_dir ), check = True , capture_output = True )
173
+ subprocess .run (
174
+ ["pre-commit" , "run" , "--all" , "--show-diff-on-failure" ],
175
+ cwd = str (result .project_dir ),
176
+ check = True ,
177
+ capture_output = True ,
178
+ )
149
179
except subprocess .CalledProcessError as e :
150
- pytest .fail (f"pre-commit failed with output:\n { e .stdout .decode ()} \n error:\n { e .stderr .decode ()} " )
180
+ pytest .fail (
181
+ f"pre-commit failed with output:\n { e .stdout .decode ()} \n error:\n { e .stderr .decode ()} "
182
+ )
0 commit comments