generated from robalexdev/marp-to-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_test_snippets.json
234 lines (219 loc) · 5.84 KB
/
python_test_snippets.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Import from": {
"prefix": "from",
"body": "from ${1:module} import ${2:func}",
"description": "Import object from module"
},
"Quick run main": {
"prefix": "ifname",
"body": [
"if __name__ == \"__main__\":",
"\tdf = main($1)",
"\tprint(df)",
"\t$0"
],
"description": "Quick run module main function."
},
"Test imports for DataFrames": {
"prefix": "pytest_frames",
"body": [
"${BLOCK_COMMENT_START}A set of unit tests for $1.${BLOCK_COMMENT_END}",
"$3# from numpy import nan",
"import pandas as pd",
"$4# from pandas import Timestamp",
"from pandas._testing import assert_frame_equal $5#, assert_series_equal",
"import pytest",
"",
"from$2",
"from tests.conftest import (",
"\tcreate_dataframe,",
"\t$6# Case,",
"\t$7# parametrize_cases,",
")",
"",
"",
"$0"
],
"description": "Standard import block for testing dataframes with pytest."
},
"Test structure": {
"prefix": "test",
"body": [
"def test_${1:name}(${2:args}):",
"\t${BLOCK_COMMENT_START}Test $3.${BLOCK_COMMENT_END}",
"\t$LINE_COMMENT GIVEN $4",
"\t$LINE_COMMENT WHEN $5",
"\t$LINE_COMMENT THEN $6",
"\t${0:pass}"
],
"description": "Quck test structure."
},
"Test shell function": {
"prefix": "test_shell_func",
"body": [
"@pytest.mark.skip(reason=\"test shell\")",
"def test_${1:name}():",
"\t${BLOCK_COMMENT_START}Test for this.${BLOCK_COMMENT_END}",
"\tpass",
"",
"$0"
],
"description": "An empty test function shell."
},
"Test shell method": {
"prefix": "test_shell_method",
"body": [
"@pytest.mark.skip(reason=\"test shell\")",
"def test_${1:name}(self):",
"\t${BLOCK_COMMENT_START}Test for this.${BLOCK_COMMENT_END}",
"\tpass",
"",
"$0"
],
"description": "An empty test method shell."
},
"Test class shell": {
"prefix": "test_shell_class",
"body": [
"class Test${1/(?:^|_)([a-z])/${1:/capitalize}/g}:",
"\t${BLOCK_COMMENT_START}Group of tests for $1.${BLOCK_COMMENT_END}",
"",
"\[email protected](reason=\"test shell\")",
"\tdef test_${1:func_name_in_snake_case}(self):",
"\t\t${BLOCK_COMMENT_START}Test for $1.${BLOCK_COMMENT_END}",
"\t\tpass",
"",
"$0"
],
"description": "An empty test class shell."
},
"Test fixture": {
"prefix": "fixture",
"body": [
"@pytest.fixture",
"def ${1:fixture_name}(${2:args}):",
"\t${BLOCK_COMMENT_START}Return $3.${BLOCK_COMMENT_END}",
"\t${0:pass}"
],
"description": "Basic fixture."
},
"Simple DataFrame test fixture": {
"prefix": "dfixture",
"body": [
"@pytest.fixture",
"def ${1:fixture_name}(${2:args}):",
"\t${BLOCK_COMMENT_START}Return $3.${BLOCK_COMMENT_END}",
"\treturn create_dataframe([",
"\t\t${CLIPBOARD}",
"\t])"
],
"description": "Simple DataFrame test fixture."
},
"Complex DataFrame test fixture": {
"prefix": "cdfixture",
"body": [
"@pytest.fixture",
"def ${1:fixture_name}(${2:args}):",
"\t${BLOCK_COMMENT_START}Return $3.${BLOCK_COMMENT_END}",
"\tdf = create_dataframe([",
"\t\t${CLIPBOARD}",
"\t])",
"\t${5:additional_steps}",
"\treturn df"
],
"description": "Complex DataFrame test fixture."
},
"Test Case": {
"prefix": "Case",
"body": [
"Case(",
"\tlabel=\"$1\",",
"\t$LINE_COMMENT GIVEN $2",
"\t$LINE_COMMENT WHEN $3",
"\t$LINE_COMMENT THEN $4",
"\t${5:kwargs}",
"\texpout=$6,",
"),"
],
"description": "Test case class."
},
"Parametrise cases": {
"prefix": "param_cases",
"body": [
"@parametrize_cases(",
"\tCase$1",
")",
"def test_$2cases(${3:args}):",
"\t${BLOCK_COMMENT_START}Test $4.${BLOCK_COMMENT_END}",
"\t${0:pass}"
],
"description": "Parametrise test cases without fixtures."
},
"Parametrise fixtures": {
"prefix": "param_fixtures",
"body": [
"@pytest.fixture(",
"\tparams=[",
"\t\tCase$1",
"\t],",
"\tids=lambda x: x.label,",
")",
"def case_parameters(${2:self, }request):",
"\t${BLOCK_COMMENT_START}Return the parameters for each test given by params.${BLOCK_COMMENT_END}",
"\treturn get_case_parameters(request)",
"",
"def test_${3:name}(${2}${4}case_parameters):",
"\t${BLOCK_COMMENT_START}${5:test_docstring}.${BLOCK_COMMENT_END}",
"\texpected_output = case_parameters.pop('${6:expout_label}')",
"\t${7:pass}"
],
"description": "Parametrise any number of parameters or fixtures using Case."
},
"Slice Case": {
"prefix": "Casesl",
"body": [
"Case(",
"\tlabel=$1,",
"\t$LINE_COMMENT GIVEN $2",
"\t$LINE_COMMENT WHEN $3",
"\t$LINE_COMMENT THEN $4",
"\t${5:kwargs}",
"\texpout=$6,",
"),"
],
"description": "Test case class."
},
"Parametrise DataFrame slices": {
"prefix": "param_slices",
"body": [
"@pytest.fixture(",
"\tparams=[",
"\t\tCase$1",
"\t],",
"\tids=lambda x: x.label,",
")",
"def case_parameters(${2:self, }request):",
"\t${BLOCK_COMMENT_START}Return the parameters for each test given by params.${BLOCK_COMMENT_END}",
"\treturn get_case_parameters(request)",
"",
"def test_${3:name}(${2}${4}case_parameters):",
"\t${BLOCK_COMMENT_START}${5:test_docstring}.${BLOCK_COMMENT_END}",
"\texpected_output = case_parameters.pop('${6:expout_label}')",
"\t${7:pass}"
],
"description": "Parametrise any number of parameters or fixtures using Case."
}
}