forked from MetOffice/SimSys_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fortran_checks.py
More file actions
630 lines (515 loc) · 21 KB
/
Copy pathtest_fortran_checks.py
File metadata and controls
630 lines (515 loc) · 21 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# -----------------------------------------------------------------------------
# (C) Crown copyright Met Office. All rights reserved.
# The file LICENCE, distributed with this code, contains details of the terms
# under which the code may be used.
# -----------------------------------------------------------------------------
import pytest
import sys
from pathlib import Path
# Add the current directory to Python path
sys.path.insert(0, str(Path(__file__).parent.parent))
from umdp3_checker_rules import UMDP3Checker, TestResult
# Prevent pytest from trying to collect TestResult as more tests:
TestResult.__test__ = False # type: ignore
"""
ToDo :
THere has been a LOT of refactoring in the umdp3 module since these
tests were written. To persuade them to 'work' for now, only two
attributes of the TestResult class are used - failure_count and
errors.
Something more rigorous should be done to bring these tests up to
date. Especially as errors is (I think) only checking for the presence
of a given string in the keys of the error log dict.
"""
fake_code_block = ["PROGRAM test", "IMPLICIT NONE", "INTEGER :: i", "END PROGRAM"]
implicit_none_paramters = [
(
[line for line in fake_code_block if line != "IMPLICIT NONE"],
1,
"Missing IMPLICIT NONE",
),
(fake_code_block, 0, "With IMPLICIT NONE"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in implicit_none_paramters],
ids=[data[2] for data in implicit_none_paramters],
)
def test_implicit_none(lines, expected_result):
checker = UMDP3Checker()
result = checker.implicit_none(lines)
assert result.failure_count == expected_result
openmp_sentinels_parameters = [
(["!$OMP PARALLEL"], 0, "OpenMP sentinel in column one"),
([" !$OMP PARALLEL"], 1, "OpenMP sentinel not in column one"),
(
["!$OMP PARALLEL", " !$OMP END PARALLEL"],
1,
"One sentinel in column one, one not",
),
([" !$OMP PARALLEL", " !$OMP END PARALLEL"], 2, "No sentinels in column one"),
(
["! This is a comment", " !$OMP PARALLEL"],
1,
"Comment line and sentinel not in column one",
),
(["!$OMP PARALLEL", "!$OMP END PARALLEL"], 0, "Both sentinels in column one"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in openmp_sentinels_parameters],
ids=[data[2] for data in openmp_sentinels_parameters],
)
def test_openmp_sentinels_in_column_one(lines, expected_result):
checker = UMDP3Checker()
result = checker.openmp_sentinels_in_column_one(lines)
assert result.failure_count == expected_result
unseparated_keywords_parameters = [
(["ELSEIF", "ENDDO", "ENDSUBROUTINE"], 3, "All keywords unseparated"),
(["ELSE IF", "ENDMODULE", "ENDSUBROUTINE"], 2, "One keyword separated"),
(["ELSE IF", "END PARRALEL DO", "END IF"], 0, "All keywords separated"),
(["i=0", "i=i+1", "PRINT*,i"], 0, "No keywords"),
(["PROGRAM test", "i=0", "ENDIF"], 1, "One keyword unseparated"),
(["i=0", "ENDPARALLELDO", "END DO"], 1, "One keyword unseparated in middle"),
(["REAL, INTENT(IN OUT) :: lambda_pole !INOUT Longitude of pole",
"REAL, INTENT(OUT) :: Dave", "DO", "nothing", "END DO"], 0,
"unseparated keyword in comment"),
(["#endif", "i=i+1", "PRINT*,i"], 0, "Safely ignore cpp commands"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in unseparated_keywords_parameters],
ids=[data[2] for data in unseparated_keywords_parameters],
)
def test_unseparated_keywords(lines, expected_result):
checker = UMDP3Checker()
result = checker.unseparated_keywords(lines)
assert result.failure_count == expected_result
go_to_other_than_9999_parameters = [
(
[" GO TO 1000", " GO TO 2000"],
2,
"All GO TO statements to labels other than 9999",
),
(
[" GO TO 9999", " GO TO 2000"],
1,
"One GO TO statement to label other than 9999",
),
([" GO TO 9999", " GO TO 9999"], 0, "All GO TO statements to label 9999"),
([" PRINT *, 'Hello, World!'", " i = i + 1"], 0, "No GO TO statements"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in go_to_other_than_9999_parameters],
ids=[data[2] for data in go_to_other_than_9999_parameters],
)
def test_go_to_other_than_9999(lines, expected_result):
checker = UMDP3Checker()
result = checker.go_to_other_than_9999(lines)
assert result.failure_count == expected_result
write_using_default_format_parameters = [
([" WRITE(*,*) 'Hello, World!'"], 1, "WRITE using default format"),
([" WRITE(6,*) 'Hello, World!'"], 0, "WRITE using correct format"),
([" PRINT *, 'Hello, World!'"], 0, "PRINT statement"),
([" i = i + 1"], 0, "No WRITE statements"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in write_using_default_format_parameters],
ids=[data[2] for data in write_using_default_format_parameters],
)
def test_write_using_default_format(lines, expected_result):
checker = UMDP3Checker()
result = checker.write_using_default_format(lines)
assert result.failure_count == expected_result
test_dimension_forbidden_parameters = [
(["REAL :: array(ARR_LEN)"], 0, "Dimension specified in variable declaration"),
(["REAL :: array"], 0, "No dimension specified in variable declaration"),
(["DIMENSION matrix(5,5)"], 1, "Dimension specified for declared variable"),
(
["INTEGER, DIMENSION(10) :: array"],
1,
"Dimension specified in variable declaration with attributes",
),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_dimension_forbidden_parameters],
ids=[data[2] for data in test_dimension_forbidden_parameters],
)
def test_dimension_forbidden(lines, expected_result):
checker = UMDP3Checker()
result = checker.dimension_forbidden(lines)
assert result.failure_count == expected_result
test_ampersand_continuation_parameters = [
(
[" PRINT *, 'This is a long line &", " & that continues here'"],
1,
"Ampersand continuation on both lines",
),
(
[" PRINT *, 'This is a long line &", " that continues here'"],
0,
"Correct ampersand continuation",
),
(
[" PRINT *, 'This is a long line", "& that continues here'"],
1,
"Incorrect ampersand continuation",
),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_ampersand_continuation_parameters],
ids=[data[2] for data in test_ampersand_continuation_parameters],
)
def test_ampersand_continuation(lines, expected_result):
checker = UMDP3Checker()
result = checker.ampersand_continuation(lines)
assert result.failure_count == expected_result
test_forbidden_keywords_parameters = [
(["COMMON /BLOCK/ var1, var2"], 0, "Use of COMMON block"),
(["EQUIVALENCE (var1, var2)"], 1, "Use of EQUIVALENCE"),
(["PAUSE 1"], 1, "Use of PAUSE statement"),
(["REAL :: var1"], 0, "No forbidden keywords"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_forbidden_keywords_parameters],
ids=[data[2] for data in test_forbidden_keywords_parameters],
)
def test_forbidden_keywords(lines, expected_result):
checker = UMDP3Checker()
result = checker.forbidden_keywords(lines)
assert result.failure_count == expected_result
test_forbidden_operators_parameters = [
(["IF (x .GT. y) THEN"], 1, "Use of .GT. operator"),
(["IF (x > y) THEN"], 0, "Use of > operator"),
(["IF (x .GE. y) THEN"], 1, "Use of .GE. operator"),
(["IF (x .EQ. y) THEN"], 1, "Use of .EQ. operator"),
(["IF (x .NE. y) THEN"], 1, "Use of .NE. operator"),
(["IF (x >= y) THEN"], 0, "Use of >= operator"),
(["IF (x == y) THEN"], 0, "Use of == operator"),
(["IF (x >= y) .AND. (y <= z) THEN"], 0, "Use of >= operator"),
(["IF (x == y) .OR. (y .LE. z) THEN"], 1, "Use of .LE. operator"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_forbidden_operators_parameters],
ids=[data[2] for data in test_forbidden_operators_parameters],
)
def test_forbidden_operators(lines, expected_result):
checker = UMDP3Checker()
result = checker.forbidden_operators(lines)
assert result.failure_count == expected_result
test_tab_detection_parameters = [
([" PRINT *, 'This line has no tabs'"], 0, "No tabs"),
([" PRINT *, 'This line has a tab\tcharacter'"], 1, "Line with tab character"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_tab_detection_parameters],
ids=[data[2] for data in test_tab_detection_parameters],
)
def test_tab_detection(lines, expected_result):
checker = UMDP3Checker()
result = checker.tab_detection(lines)
assert result.failure_count == expected_result
test_printstatus_mod_parameters = [
([" USE PrintStatus_mod"], 1, "Use of PRINTSTATUS_Mod"),
([" USE umPrintMgr_mod"], 0, "Use of umPrintMgr_Mod"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_printstatus_mod_parameters],
ids=[data[2] for data in test_printstatus_mod_parameters],
)
def test_printstatus_mod(lines, expected_result):
checker = UMDP3Checker()
result = checker.printstatus_mod(lines)
assert result.failure_count == expected_result
test_printstar_parameters = [
([" PRINT *, 'Hello, World!'"], 1, "Use of PRINT *"),
([" PRINT '(A)', 'Hello, World!'"], 0, "Use of PRINT with format"),
([" umMessage = 'Hello, World!'"], 0, "Use of umMessage"),
([" umPrint(umMessage)"], 0, "Use of umPrint"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_printstar_parameters],
ids=[data[2] for data in test_printstar_parameters],
)
def test_printstar(lines, expected_result):
checker = UMDP3Checker()
result = checker.printstar(lines)
assert result.failure_count == expected_result
test_write6_parameters = [
([" WRITE(6,*) 'Hello, World!'"], 1, "Use of WRITE(6,*)"),
([" umPrint(umMessage)"], 0, "Use of umPrint"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_write6_parameters],
ids=[data[2] for data in test_write6_parameters],
)
def test_write6(lines, expected_result):
checker = UMDP3Checker()
result = checker.write6(lines)
assert result.failure_count == expected_result
test_um_fort_flush_parameters = [
([" CALL um_fort_flush()"], 1, "Use of um_fort_flush"),
([" CALL umPrintFlush()"], 0, "No use of um_fort_flush"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_um_fort_flush_parameters],
ids=[data[2] for data in test_um_fort_flush_parameters],
)
def test_um_fort_flush(lines, expected_result):
checker = UMDP3Checker()
result = checker.um_fort_flush(lines)
assert result.failure_count == expected_result
test_svn_keyword_subst_parameters = [
([" ! $Id$"], 1, "Use of SVN keyword substitution"),
([" ! This is a comment"], 0, "No SVN keyword substitution"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_svn_keyword_subst_parameters],
ids=[data[2] for data in test_svn_keyword_subst_parameters],
)
def test_svn_keyword_subst(lines, expected_result):
checker = UMDP3Checker()
result = checker.svn_keyword_subst(lines)
assert result.failure_count == expected_result
test_omp_missing_dollar_parameters = [
(["!$OMP PARALLEL"], 0, "Correct OpenMP sentinel"),
(["!OMP PARALLEL"], 1, "Missing $ in OpenMP sentinel"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_omp_missing_dollar_parameters],
ids=[data[2] for data in test_omp_missing_dollar_parameters],
)
def test_omp_missing_dollar(lines, expected_result):
checker = UMDP3Checker()
result = checker.omp_missing_dollar(lines)
assert result.failure_count == expected_result
test_cpp_ifdef_parameters = [
(["#ifndef DEBUG"], 1, "Incorrect #ifndef"),
(["#if defined(DEBUG)"], 0, "Correct #if defined"),
(["#if !defined(DEBUG)"], 0, "Correct #if !defined"),
(["#ifdef DEBUG"], 1, "Incorrect #ifdef"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_cpp_ifdef_parameters],
ids=[data[2] for data in test_cpp_ifdef_parameters],
)
def test_cpp_ifdef(lines, expected_result):
checker = UMDP3Checker()
result = checker.cpp_ifdef(lines)
assert result.failure_count == expected_result
test_cpp_comment_parameters = [
# This test fails because the test is wrong - it needs fixing
(["#if !defined(cpp)"], 0, "cpp directive without comment"),
(["! This is a comment"], 0, "Fortran style comment"),
(["#if defined(cpp) ! some comment"], 1, "Fortran comment after cpp directive"),
(["#else ! another comment"], 1, "Fortran comment after #else directive"),
(["#else"], 0, "#else directive without comment"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_cpp_comment_parameters],
ids=[data[2] for data in test_cpp_comment_parameters],
)
def test_cpp_comment(lines, expected_result):
checker = UMDP3Checker()
result = checker.cpp_comment(lines)
assert result.failure_count == expected_result
test_obsolescent_fortran_intrinsic_parameters = [
([" x = ALOG(2.0)"], 1, "Use of obsolescent intrinsic ALOG"),
([" y = DSIN(x)"], 1, "Use of obsolescent intrinsic DSIN"),
([" z = SIN(x)"], 0, "Use of non-obsolescent intrinsic SIN"),
([" x = ALOG10(2.0)", " y = DACOS(x)"], 2, "Use of two obsolescent intrinsics"),
([" x = FLOAT(2)", " z = SIN(x)"], 1, "Use of one obsolescent intrinsic"),
([" y = DMAX1(x)", " z = SIN(x)"], 1, "Use of one obsolescent intrinsic"),
(
[" a = DATAN2(2.0)", " b = DSIN(a)", " c = SIN(b)"],
2,
"Use of two obsolescent intrinsics",
),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_obsolescent_fortran_intrinsic_parameters],
ids=[data[2] for data in test_obsolescent_fortran_intrinsic_parameters],
)
def test_obsolescent_fortran_intrinsic(lines, expected_result):
checker = UMDP3Checker()
result = checker.obsolescent_fortran_intrinsic(lines)
assert result.failure_count == expected_result
test_exit_stmt_label_parameters = [
([" EXIT 10"], 0, "EXIT statement with label"),
([" EXIT"], 1, "EXIT statement without label"),
([" i = i + 1"], 0, "No EXIT statement"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_exit_stmt_label_parameters],
ids=[data[2] for data in test_exit_stmt_label_parameters],
)
def test_exit_stmt_label(lines, expected_result):
checker = UMDP3Checker()
result = checker.exit_stmt_label(lines)
assert result.failure_count == expected_result
test_intrinsic_modules_parameters = [
([" USE ISO_C_BINDING"], 1, "Incorrect Use of ISO_C_BINDING module"),
(
[" USE, INTRINSIC :: ISO_FORTRAN_ENV"],
0,
"Correct Use of ISO_FORTRAN_ENV module",
),
([" USE :: ISO_FORTRAN_ENV"], 1, "Incorrect Use of ISO_FORTRAN_ENV module"),
([" USE, INTRINSIC :: ISO_C_BINDING"], 0, "Correct Use of ISO_C_BINDING module"),
(
[" USE SOME_OTHER_MODULE"],
0,
"Use of non-intrinsic module without INTRINSIC keyword",
),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_intrinsic_modules_parameters],
ids=[data[2] for data in test_intrinsic_modules_parameters],
)
def test_intrinsic_modules(lines, expected_result):
checker = UMDP3Checker()
result = checker.intrinsic_modules(lines)
assert result.failure_count == expected_result
test_read_unit_args_parameters = [
([" READ(5,*) var"], 1, "READ without explicit UNIT="),
([" READ(UNIT=10) var"], 0, "READ with explicit UNIT="),
(
[" READ(UNIT=unit_in, NML=lustre_control_custom_files) var"],
0,
"READ with UNIT=variable",
),
([" READ(unit_in,*) var"], 1, "READ unit as variable, no UNIT="),
([" READ(*,*) var"], 1, "READ from default unit"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_read_unit_args_parameters],
ids=[data[2] for data in test_read_unit_args_parameters],
)
def test_read_unit_args(lines, expected_result):
checker = UMDP3Checker()
result = checker.read_unit_args(lines)
assert result.failure_count == expected_result
test_retire_if_def_parameters = [
(["#ifdef DEBUG"], 0, "Correct Use of #ifdef"),
(["#ifndef DEBUG"], 0, "Correct Use of #ifndef"),
(["#if defined(DEBUG)"], 0, "Correct Use of #if defined"),
(["#if !defined(DEBUG)"], 0, "Correct Use of #if !defined"),
(["#elif defined(DEBUG)"], 0, "Correct Use of #elif defined"),
(["#else"], 0, "Correct Use of #else"),
(["#ifdef VATPOLES"], 1, "Incorrect Use of VATPOLES"),
(["#ifndef A12_3A"], 1, "Incorrect Use of A12_3A"),
(["#if defined(A12_4A)"], 1, "Incorrect Use of A12_4A"),
(["#if !defined(UM_JULES)"], 1, "Incorrect Use of UM_JULES"),
(["#elif defined(VATPOLES)"], 1, "Incorrect Use of VATPOLES"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_retire_if_def_parameters],
ids=[data[2] for data in test_retire_if_def_parameters],
)
def test_retire_if_def(lines, expected_result):
checker = UMDP3Checker()
result = checker.retire_if_def(lines)
assert result.failure_count == expected_result
test_forbidden_stop_parameters = [
([" STOP 0"], 1, "Use of STOP statement"),
(["STOP"], 1, "Use of STOP statement without code"),
([" PRINT *, 'Hello, World!'"], 0, "No STOP statement"),
(["CALL ABORT"], 1, "Use of call abort statement"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_forbidden_stop_parameters],
ids=[data[2] for data in test_forbidden_stop_parameters],
)
def test_forbidden_stop(lines, expected_result):
checker = UMDP3Checker()
result = checker.forbidden_stop(lines)
assert result.failure_count == expected_result
test_intrinsic_as_variable_parameters = [
([" INTEGER :: SIN"], 1, "Use of intrinsic name as variable"),
([" REAL :: COS"], 1, "Use of intrinsic name as variable"),
([" REAL :: MYVAR"], 0, "No use of intrinsic name as variable"),
([" INTEGER :: TAN, MYVAR"], 1, "One intrinsic name as variable"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_intrinsic_as_variable_parameters],
ids=[data[2] for data in test_intrinsic_as_variable_parameters],
)
def test_intrinsic_as_variable(lines, expected_result):
checker = UMDP3Checker()
result = checker.intrinsic_as_variable(lines)
assert result.failure_count == expected_result
test_check_code_owner_parameters = [
(["! Code Owner: John Doe"], 0, "code owner statement"),
(["! Code Owner : John Doe"], 0, "Another code owner statement"),
(["! This is a comment"], 1, "No code owner statement"),
(["! Code Owner: "], 0, "Code owner statement with no name"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_check_code_owner_parameters],
ids=[data[2] for data in test_check_code_owner_parameters],
)
def test_check_code_owner(lines, expected_result):
checker = UMDP3Checker()
result = checker.check_code_owner(lines)
assert result.failure_count == expected_result
test_array_init_form_parameters = [
([" INTEGER, DIMENSION(10) :: array = 0"], 0, "Array initialized using '='"),
([" INTEGER, DIMENSION(10) :: array"], 0, "Array declared without initialization"),
(
[" INTEGER, DIMENSION(10) :: array = (/ (i, i=1,10) /)"],
1,
"Array initialized using array constructor",
),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_array_init_form_parameters],
ids=[data[2] for data in test_array_init_form_parameters],
)
def test_array_init_form(lines, expected_result):
checker = UMDP3Checker()
result = checker.array_init_form(lines)
assert result.failure_count == expected_result
test_line_trail_whitespace_parameters = [
([" PRINT *, 'Hello, World! '"], 0, "Line 1 without trailing whitespace"),
([" PRINT *, 'Hello, World!'"], 0, "Line 2 without trailing whitespace"),
([" PRINT *, 'Hello, World! ' "], 1, "Line 1 with trailing whitespace"),
(
[" something = sin(coeff /2.0_rdef) + & "],
1,
"Line 2 with trailing whitespace",
),
(["MODULE some_mod "], 1, "Line 3 with trailing whitespace"),
]
@pytest.mark.parametrize(
"lines, expected_result",
[data[:2] for data in test_line_trail_whitespace_parameters],
ids=[data[2] for data in test_line_trail_whitespace_parameters],
)
def test_line_trail_whitespace(lines, expected_result):
checker = UMDP3Checker()
result = checker.line_trail_whitespace(lines)
assert result.failure_count == expected_result