@@ -168,19 +168,53 @@ def test_script_custom(command):
168
168
169
169
@pytest .mark .parametrize ("command" , test_commands )
170
170
def test_add_preamble (command ):
171
+
171
172
PREAMBLE_TEXT = """
172
173
# this is some test code
173
174
# to be added to the file
174
175
175
176
176
177
# let's see if it works
177
- """
178
178
179
- command += ' --preamble "' + PREAMBLE_TEXT + '"'
180
- stdout = execute_test (command )
179
+
180
+ """
181
+ stdout = execute_test (command + ' --preamble "' + PREAMBLE_TEXT + '"' )
181
182
assert "let's see if it works" in stdout
182
183
183
184
185
+ @pytest .mark .parametrize ("command" , test_commands )
186
+ def test_add_trim_preamble (command ):
187
+
188
+ def trim_header (line_string ):
189
+ """remove the quoted command and everything from the first class declaration onwards"""
190
+ lines = line_string .splitlines ()
191
+ start = 0
192
+ end = 0
193
+ line_no = 0
194
+ for l in lines :
195
+ if l .startswith ('"""' ):
196
+ start = line_no
197
+ if l .startswith ('class ' ):
198
+ end = line_no
199
+ break
200
+ line_no += 1
201
+
202
+ return lines [start :end ]
203
+
204
+ expected_result = execute_test (command )
205
+
206
+ BLANK_SPACE = """
207
+
208
+
209
+
210
+
211
+ """
212
+ # ensure blank space does not get propagated
213
+ stdout = execute_test (command + ' --preamble "' + BLANK_SPACE + '"' )
214
+
215
+ assert trim_header (expected_result ) == trim_header (stdout )
216
+
217
+
184
218
wrong_arguments_commands = [
185
219
pytest .param (f"""{ executable } -l Model items "{ test_data_path / 'photos.json' } " \
186
220
-l Model - "{ test_data_path / 'users.json' } " """ , id = "duplicate_name" ),
0 commit comments