| Conditions | 1 |
| Total Lines | 893 |
| Code Lines | 269 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | #!/usr/bin/python3 |
||
| 8 | def main(): |
||
| 9 | parser = argparse.ArgumentParser( |
||
| 10 | description="Test Jinja macros that Generate OVAL") |
||
| 11 | parser.add_argument( |
||
| 12 | "--verbose", action="store_true", default=False, |
||
| 13 | help="Show results of each test case") |
||
| 14 | args = parser.parse_args() |
||
| 15 | tester = oval_tester.OVALTester(args.verbose) |
||
| 16 | |||
| 17 | ####################################################### |
||
| 18 | # Test cases for whitespace separated files |
||
| 19 | ####################################################### |
||
| 20 | |||
| 21 | tester.test( |
||
| 22 | "correct value", |
||
| 23 | r"""{{{ oval_check_config_file( |
||
| 24 | path='CONFIG_FILE', |
||
| 25 | prefix_regex='^[ \t]*', |
||
| 26 | parameter='speed', |
||
| 27 | separator_regex='[ \t]+', |
||
| 28 | value='100', |
||
| 29 | missing_parameter_pass=false, |
||
| 30 | application='', |
||
| 31 | multi_value=false, |
||
| 32 | missing_config_file_fail=false, |
||
| 33 | section='' |
||
| 34 | ) }}}""", |
||
| 35 | "speed 100", |
||
| 36 | "true" |
||
| 37 | ) |
||
| 38 | tester.test( |
||
| 39 | "correct value and a comment", |
||
| 40 | r"""{{{ oval_check_config_file( |
||
| 41 | path='CONFIG_FILE', |
||
| 42 | prefix_regex='^[ \t]*', |
||
| 43 | parameter='speed', |
||
| 44 | separator_regex='[ \t]+', |
||
| 45 | value='100', |
||
| 46 | missing_parameter_pass=false, |
||
| 47 | application='', |
||
| 48 | multi_value=false, |
||
| 49 | missing_config_file_fail=false, |
||
| 50 | section='' |
||
| 51 | ) }}}""", |
||
| 52 | "speed 100 # be very fast", |
||
| 53 | "true" |
||
| 54 | ) |
||
| 55 | tester.test( |
||
| 56 | "correct value on a new line", |
||
| 57 | r"""{{{ oval_check_config_file( |
||
| 58 | path='CONFIG_FILE', |
||
| 59 | prefix_regex='^[ \t]*', |
||
| 60 | parameter='speed', |
||
| 61 | separator_regex='[ \t]+', |
||
| 62 | value='100', |
||
| 63 | missing_parameter_pass=false, |
||
| 64 | application='', |
||
| 65 | multi_value=false, |
||
| 66 | missing_config_file_fail=false, |
||
| 67 | section='' |
||
| 68 | ) }}}""", |
||
| 69 | "\n\n\n\n\n\nspeed 100", |
||
| 70 | "true" |
||
| 71 | ) |
||
| 72 | tester.test( |
||
| 73 | "correct value separated by a tab", |
||
| 74 | r"""{{{ oval_check_config_file( |
||
| 75 | path='CONFIG_FILE', |
||
| 76 | prefix_regex='^[ \t]*', |
||
| 77 | parameter='speed', |
||
| 78 | separator_regex='[ \t]+', |
||
| 79 | value='100', |
||
| 80 | missing_parameter_pass=false, |
||
| 81 | application='', |
||
| 82 | multi_value=false, |
||
| 83 | missing_config_file_fail=false, |
||
| 84 | section='' |
||
| 85 | ) }}}""", |
||
| 86 | "speed\t100", |
||
| 87 | "true" |
||
| 88 | ) |
||
| 89 | tester.test( |
||
| 90 | "wrong value", |
||
| 91 | r"""{{{ oval_check_config_file( |
||
| 92 | path='CONFIG_FILE', |
||
| 93 | prefix_regex='^[ \t]*', |
||
| 94 | parameter='speed', |
||
| 95 | separator_regex='[ \t]+', |
||
| 96 | value='100', |
||
| 97 | missing_parameter_pass=false, |
||
| 98 | application='', |
||
| 99 | multi_value=false, |
||
| 100 | missing_config_file_fail=false, |
||
| 101 | section='' |
||
| 102 | ) }}}""", |
||
| 103 | "speed 80", |
||
| 104 | "false" |
||
| 105 | ) |
||
| 106 | tester.test( |
||
| 107 | "wrong value which contains the correct value as a substring", |
||
| 108 | r"""{{{ oval_check_config_file( |
||
| 109 | path='CONFIG_FILE', |
||
| 110 | prefix_regex='^[ \t]*', |
||
| 111 | parameter='speed', |
||
| 112 | separator_regex='[ \t]+', |
||
| 113 | value='100', |
||
| 114 | missing_parameter_pass=false, |
||
| 115 | application='', |
||
| 116 | multi_value=false, |
||
| 117 | missing_config_file_fail=false, |
||
| 118 | section='' |
||
| 119 | ) }}}""", |
||
| 120 | "speed 1000", |
||
| 121 | "false" |
||
| 122 | ) |
||
| 123 | tester.test( |
||
| 124 | "commented value", |
||
| 125 | r"""{{{ oval_check_config_file( |
||
| 126 | path='CONFIG_FILE', |
||
| 127 | prefix_regex='^[ \t]*', |
||
| 128 | parameter='speed', |
||
| 129 | separator_regex='[ \t]+', |
||
| 130 | value='100', |
||
| 131 | missing_parameter_pass=false, |
||
| 132 | application='', |
||
| 133 | multi_value=false, |
||
| 134 | missing_config_file_fail=false, |
||
| 135 | section='' |
||
| 136 | ) }}}""", |
||
| 137 | "# speed 80", |
||
| 138 | "false" |
||
| 139 | ) |
||
| 140 | tester.test( |
||
| 141 | "missing whitespace", |
||
| 142 | r"""{{{ oval_check_config_file( |
||
| 143 | path='CONFIG_FILE', |
||
| 144 | prefix_regex='^[ \t]*', |
||
| 145 | parameter='speed', |
||
| 146 | separator_regex='[ \t]+', |
||
| 147 | value='100', |
||
| 148 | missing_parameter_pass=false, |
||
| 149 | application='', |
||
| 150 | multi_value=false, |
||
| 151 | missing_config_file_fail=false, |
||
| 152 | section='' |
||
| 153 | ) }}}""", |
||
| 154 | "speed100", |
||
| 155 | "false" |
||
| 156 | ) |
||
| 157 | tester.test( |
||
| 158 | "parameter without a value", |
||
| 159 | r"""{{{ oval_check_config_file( |
||
| 160 | path='CONFIG_FILE', |
||
| 161 | prefix_regex='^[ \t]*', |
||
| 162 | parameter='speed', |
||
| 163 | separator_regex='[ \t]+', |
||
| 164 | value='100', |
||
| 165 | missing_parameter_pass=false, |
||
| 166 | application='', |
||
| 167 | multi_value=false, |
||
| 168 | missing_config_file_fail=false, |
||
| 169 | section='' |
||
| 170 | ) }}}""", |
||
| 171 | "speed ", |
||
| 172 | "false" |
||
| 173 | ) |
||
| 174 | tester.test( |
||
| 175 | "misspelled parameter with a value", |
||
| 176 | r"""{{{ oval_check_config_file( |
||
| 177 | path='CONFIG_FILE', |
||
| 178 | prefix_regex='^[ \t]*', |
||
| 179 | parameter='speed', |
||
| 180 | separator_regex='[ \t]+', |
||
| 181 | value='100', |
||
| 182 | missing_parameter_pass=false, |
||
| 183 | application='', |
||
| 184 | multi_value=false, |
||
| 185 | missing_config_file_fail=false, |
||
| 186 | section='' |
||
| 187 | ) }}}""", |
||
| 188 | "sspeed 100", |
||
| 189 | "false" |
||
| 190 | ) |
||
| 191 | tester.test( |
||
| 192 | "parameter is on a different line than the value", |
||
| 193 | r"""{{{ oval_check_config_file( |
||
| 194 | path='CONFIG_FILE', |
||
| 195 | prefix_regex='^[ \t]*', |
||
| 196 | parameter='speed', |
||
| 197 | separator_regex='[ \t]+', |
||
| 198 | value='100', |
||
| 199 | missing_parameter_pass=false, |
||
| 200 | application='', |
||
| 201 | multi_value=false, |
||
| 202 | missing_config_file_fail=false, |
||
| 203 | section='' |
||
| 204 | ) }}}""", |
||
| 205 | "speed\n100", |
||
| 206 | "false" |
||
| 207 | ) |
||
| 208 | tester.test( |
||
| 209 | "multiple empty lines among parameter and value", |
||
| 210 | r"""{{{ oval_check_config_file( |
||
| 211 | path='CONFIG_FILE', |
||
| 212 | prefix_regex='^[ \t]*', |
||
| 213 | parameter='speed', |
||
| 214 | separator_regex='[ \t]+', |
||
| 215 | value='100', |
||
| 216 | missing_parameter_pass=false, |
||
| 217 | application='', |
||
| 218 | multi_value=false, |
||
| 219 | missing_config_file_fail=false, |
||
| 220 | section='' |
||
| 221 | ) }}}""", |
||
| 222 | "\n\nspeed\n\n\n100\n\n\n\n", |
||
| 223 | "false" |
||
| 224 | ) |
||
| 225 | tester.test( |
||
| 226 | "parameter with multiple values when multi_value disabled", |
||
| 227 | r"""{{{ oval_check_config_file( |
||
| 228 | path='CONFIG_FILE', |
||
| 229 | prefix_regex='^[ \t]*', |
||
| 230 | parameter='speed', |
||
| 231 | separator_regex='[ \t]+', |
||
| 232 | value='100', |
||
| 233 | missing_parameter_pass=false, |
||
| 234 | application='', |
||
| 235 | multi_value=false, |
||
| 236 | missing_config_file_fail=false, |
||
| 237 | section='' |
||
| 238 | ) }}}""", |
||
| 239 | "speed 100 50 8", |
||
| 240 | "false" |
||
| 241 | ) |
||
| 242 | tester.test( |
||
| 243 | "parameter with single value when multi_value enabled", |
||
| 244 | r"""{{{ oval_check_config_file( |
||
| 245 | path='CONFIG_FILE', |
||
| 246 | prefix_regex='^[ \t]*', |
||
| 247 | parameter='speed', |
||
| 248 | separator_regex='[ \t]+', |
||
| 249 | value='100', |
||
| 250 | missing_parameter_pass=false, |
||
| 251 | application='', |
||
| 252 | multi_value=true, |
||
| 253 | missing_config_file_fail=false, |
||
| 254 | section='' |
||
| 255 | ) }}}""", |
||
| 256 | "speed 100", |
||
| 257 | "true" |
||
| 258 | ) |
||
| 259 | tester.test( |
||
| 260 | "parameter, single value, trailing comment, multi_value enabled", |
||
| 261 | r"""{{{ oval_check_config_file( |
||
| 262 | path='CONFIG_FILE', |
||
| 263 | prefix_regex='^[ \t]*', |
||
| 264 | parameter='speed', |
||
| 265 | separator_regex='[ \t]+', |
||
| 266 | value='100', |
||
| 267 | missing_parameter_pass=false, |
||
| 268 | application='', |
||
| 269 | multi_value=true, |
||
| 270 | missing_config_file_fail=false, |
||
| 271 | section='' |
||
| 272 | ) }}}""", |
||
| 273 | "speed 100 #comment", |
||
| 274 | "true" |
||
| 275 | ) |
||
| 276 | tester.test( |
||
| 277 | "parameter with multiple values when multi_value enabled", |
||
| 278 | r"""{{{ oval_check_config_file( |
||
| 279 | path='CONFIG_FILE', |
||
| 280 | prefix_regex='^[ \t]*', |
||
| 281 | parameter='speed', |
||
| 282 | separator_regex='[ \t]+', |
||
| 283 | value='100', |
||
| 284 | missing_parameter_pass=false, |
||
| 285 | application='', |
||
| 286 | multi_value=true, |
||
| 287 | missing_config_file_fail=false, |
||
| 288 | section='' |
||
| 289 | ) }}}""", |
||
| 290 | "speed 100 50 8", |
||
| 291 | "true" |
||
| 292 | ) |
||
| 293 | tester.test( |
||
| 294 | "multiple values, multi_value enabled, value in the middle", |
||
| 295 | r"""{{{ oval_check_config_file( |
||
| 296 | path='CONFIG_FILE', |
||
| 297 | prefix_regex='^[ \t]*', |
||
| 298 | parameter='speed', |
||
| 299 | separator_regex='[ \t]+', |
||
| 300 | value='100', |
||
| 301 | missing_parameter_pass=false, |
||
| 302 | application='', |
||
| 303 | multi_value=true, |
||
| 304 | missing_config_file_fail=false, |
||
| 305 | section='' |
||
| 306 | ) }}}""", |
||
| 307 | "speed abcd 333 100 50 8", |
||
| 308 | "true" |
||
| 309 | ) |
||
| 310 | tester.test( |
||
| 311 | "multiple values, multi_value enabled, value is the last", |
||
| 312 | r"""{{{ oval_check_config_file( |
||
| 313 | path='CONFIG_FILE', |
||
| 314 | prefix_regex='^[ \t]*', |
||
| 315 | parameter='speed', |
||
| 316 | separator_regex='[ \t]+', |
||
| 317 | value='100', |
||
| 318 | missing_parameter_pass=false, |
||
| 319 | application='', |
||
| 320 | multi_value=true, |
||
| 321 | missing_config_file_fail=false, |
||
| 322 | section='' |
||
| 323 | ) }}}""", |
||
| 324 | "speed 2 4 6 8 10 14 100", |
||
| 325 | "true" |
||
| 326 | ) |
||
| 327 | tester.test( |
||
| 328 | "parameter with extra newlines, multi_value enabled", |
||
| 329 | r"""{{{ oval_check_config_file( |
||
| 330 | path='CONFIG_FILE', |
||
| 331 | prefix_regex='^[ \t]*', |
||
| 332 | parameter='speed', |
||
| 333 | separator_regex='[ \t]+', |
||
| 334 | value='100', |
||
| 335 | missing_parameter_pass=false, |
||
| 336 | application='', |
||
| 337 | multi_value=true, |
||
| 338 | missing_config_file_fail=false, |
||
| 339 | section='' |
||
| 340 | ) }}}""", |
||
| 341 | "speed\n\n100", |
||
| 342 | "false" |
||
| 343 | ) |
||
| 344 | tester.test( |
||
| 345 | "parameter with multiple values when multi_value enabled, comment", |
||
| 346 | r"""{{{ oval_check_config_file( |
||
| 347 | path='CONFIG_FILE', |
||
| 348 | prefix_regex='^[ \t]*', |
||
| 349 | parameter='speed', |
||
| 350 | separator_regex='[ \t]+', |
||
| 351 | value='100', |
||
| 352 | missing_parameter_pass=false, |
||
| 353 | application='', |
||
| 354 | multi_value=true, |
||
| 355 | missing_config_file_fail=false, |
||
| 356 | section='' |
||
| 357 | ) }}}""", |
||
| 358 | "speed 2 4 6 8 10 14 100 # astonishing", |
||
| 359 | "true" |
||
| 360 | ) |
||
| 361 | tester.test( |
||
| 362 | "multi_value is used and value is a suffix of a value", |
||
| 363 | r"""{{{ oval_check_config_file( |
||
| 364 | path='CONFIG_FILE', |
||
| 365 | prefix_regex='^[ \t]*', |
||
| 366 | parameter='speed', |
||
| 367 | separator_regex='[ \t]+', |
||
| 368 | value='100', |
||
| 369 | missing_parameter_pass=false, |
||
| 370 | application='', |
||
| 371 | multi_value=true, |
||
| 372 | missing_config_file_fail=false, |
||
| 373 | section='' |
||
| 374 | ) }}}""", |
||
| 375 | "speed 1001000", |
||
| 376 | "false" |
||
| 377 | ) |
||
| 378 | tester.test( |
||
| 379 | "parameter with a value commented out", |
||
| 380 | r"""{{{ oval_check_config_file( |
||
| 381 | path='CONFIG_FILE', |
||
| 382 | prefix_regex='^[ \t]*', |
||
| 383 | parameter='speed', |
||
| 384 | separator_regex='[ \t]+', |
||
| 385 | value='100', |
||
| 386 | missing_parameter_pass=false, |
||
| 387 | application='', |
||
| 388 | multi_value=false, |
||
| 389 | missing_config_file_fail=false, |
||
| 390 | section='' |
||
| 391 | ) }}}""", |
||
| 392 | "speed # 100", |
||
| 393 | "false" |
||
| 394 | ) |
||
| 395 | tester.test( |
||
| 396 | "missing parameter fails", |
||
| 397 | r"""{{{ oval_check_config_file( |
||
| 398 | path='CONFIG_FILE', |
||
| 399 | prefix_regex='^[ \t]*', |
||
| 400 | parameter='speed', |
||
| 401 | separator_regex='[ \t]+', |
||
| 402 | value='100', |
||
| 403 | missing_parameter_pass=false, |
||
| 404 | application='', |
||
| 405 | multi_value=false, |
||
| 406 | missing_config_file_fail=false, |
||
| 407 | section='' |
||
| 408 | ) }}}""", |
||
| 409 | "lights on", |
||
| 410 | "false" |
||
| 411 | ) |
||
| 412 | tester.test( |
||
| 413 | "missing parameter pass", |
||
| 414 | r"""{{{ oval_check_config_file( |
||
| 415 | path='CONFIG_FILE', |
||
| 416 | prefix_regex='^[ \t]*', |
||
| 417 | parameter='speed', |
||
| 418 | separator_regex='[ \t]+', |
||
| 419 | value='100', |
||
| 420 | missing_parameter_pass=true, |
||
| 421 | application='', |
||
| 422 | multi_value=false, |
||
| 423 | missing_config_file_fail=false, |
||
| 424 | section='' |
||
| 425 | ) }}}""", |
||
| 426 | "lights on", |
||
| 427 | "true" |
||
| 428 | ) |
||
| 429 | tester.test( |
||
| 430 | "overwriting", |
||
| 431 | r"""{{{ oval_check_config_file( |
||
| 432 | path='CONFIG_FILE', |
||
| 433 | prefix_regex='^[ \t]*', |
||
| 434 | parameter='speed', |
||
| 435 | separator_regex='[ \t]+', |
||
| 436 | value='100', |
||
| 437 | missing_parameter_pass=true, |
||
| 438 | application='', |
||
| 439 | multi_value=false, |
||
| 440 | missing_config_file_fail=false, |
||
| 441 | section='' |
||
| 442 | ) }}}""", |
||
| 443 | """speed 100 |
||
| 444 | speed 60""", |
||
| 445 | "false" |
||
| 446 | ) |
||
| 447 | tester.test( |
||
| 448 | "overwriting commented out", |
||
| 449 | r"""{{{ oval_check_config_file( |
||
| 450 | path='CONFIG_FILE', |
||
| 451 | prefix_regex='^[ \t]*', |
||
| 452 | parameter='speed', |
||
| 453 | separator_regex='[ \t]+', |
||
| 454 | value='100', |
||
| 455 | missing_parameter_pass=true, |
||
| 456 | application='', |
||
| 457 | multi_value=false, |
||
| 458 | missing_config_file_fail=false, |
||
| 459 | section='' |
||
| 460 | ) }}}""", |
||
| 461 | """speed 100 |
||
| 462 | #speed 60""", |
||
| 463 | "true" |
||
| 464 | ) |
||
| 465 | tester.test( |
||
| 466 | "config file missing should fail", |
||
| 467 | r"""{{{ oval_check_config_file( |
||
| 468 | path='CONFIG_FILE', |
||
| 469 | prefix_regex='^[ \t]*', |
||
| 470 | parameter='speed', |
||
| 471 | separator_regex='[ \t]+', |
||
| 472 | value='100', |
||
| 473 | missing_parameter_pass=true, |
||
| 474 | application='', |
||
| 475 | multi_value=false, |
||
| 476 | missing_config_file_fail=true, |
||
| 477 | section='' |
||
| 478 | ) }}}""", |
||
| 479 | None, |
||
| 480 | "false" |
||
| 481 | ) |
||
| 482 | tester.test( |
||
| 483 | "config file missing should pass", |
||
| 484 | r"""{{{ oval_check_config_file( |
||
| 485 | path='CONFIG_FILE', |
||
| 486 | prefix_regex='^[ \t]*', |
||
| 487 | parameter='speed', |
||
| 488 | separator_regex='[ \t]+', |
||
| 489 | value='100', |
||
| 490 | missing_parameter_pass=true, |
||
| 491 | application='', |
||
| 492 | multi_value=false, |
||
| 493 | missing_config_file_fail=false, |
||
| 494 | section='' |
||
| 495 | ) }}}""", |
||
| 496 | None, |
||
| 497 | "true" |
||
| 498 | ) |
||
| 499 | tester.test( |
||
| 500 | "config file missing should fail due to missing parameter", |
||
| 501 | r"""{{{ oval_check_config_file( |
||
| 502 | path='CONFIG_FILE', |
||
| 503 | prefix_regex='^[ \t]*', |
||
| 504 | parameter='speed', |
||
| 505 | separator_regex='[ \t]+', |
||
| 506 | value='100', |
||
| 507 | missing_parameter_pass=false, |
||
| 508 | application='', |
||
| 509 | multi_value=false, |
||
| 510 | missing_config_file_fail=true, |
||
| 511 | section='' |
||
| 512 | ) }}}""", |
||
| 513 | None, |
||
| 514 | "false" |
||
| 515 | ) |
||
| 516 | tester.test( |
||
| 517 | "config file missing but missing parameter isn't allowed", |
||
| 518 | r"""{{{ oval_check_config_file( |
||
| 519 | path='CONFIG_FILE', |
||
| 520 | prefix_regex='^[ \t]*', |
||
| 521 | parameter='speed', |
||
| 522 | separator_regex='[ \t]+', |
||
| 523 | value='100', |
||
| 524 | missing_parameter_pass=false, |
||
| 525 | application='', |
||
| 526 | multi_value=false, |
||
| 527 | missing_config_file_fail=false, |
||
| 528 | section='' |
||
| 529 | ) }}}""", |
||
| 530 | None, |
||
| 531 | "false" |
||
| 532 | ) |
||
| 533 | |||
| 534 | ####################################################### |
||
| 535 | # Test cases for equal sign separated files |
||
| 536 | ####################################################### |
||
| 537 | tester.test( |
||
| 538 | "correct value, no whitespace", |
||
| 539 | r"""{{{ oval_check_config_file( |
||
| 540 | path='CONFIG_FILE', |
||
| 541 | prefix_regex='^[ \t]*', |
||
| 542 | parameter='speed', |
||
| 543 | separator_regex='[ \t]*=[ \t]*', |
||
| 544 | value='100', |
||
| 545 | missing_parameter_pass=false, |
||
| 546 | application='', |
||
| 547 | multi_value=false, |
||
| 548 | missing_config_file_fail=false, |
||
| 549 | section='' |
||
| 550 | ) }}}""", |
||
| 551 | "speed=100", |
||
| 552 | "true" |
||
| 553 | ) |
||
| 554 | tester.test( |
||
| 555 | "correct value, some spaces in the middle", |
||
| 556 | r"""{{{ oval_check_config_file( |
||
| 557 | path='CONFIG_FILE', |
||
| 558 | prefix_regex='^[ \t]*', |
||
| 559 | parameter='speed', |
||
| 560 | separator_regex='[ \t]*=[ \t]*', |
||
| 561 | value='100', |
||
| 562 | missing_parameter_pass=false, |
||
| 563 | application='', |
||
| 564 | multi_value=false, |
||
| 565 | missing_config_file_fail=false, |
||
| 566 | section='' |
||
| 567 | ) }}}""", |
||
| 568 | "speed = 100", |
||
| 569 | "true" |
||
| 570 | ) |
||
| 571 | tester.test( |
||
| 572 | "correct value, many spaces everywhere", |
||
| 573 | r"""{{{ oval_check_config_file( |
||
| 574 | path='CONFIG_FILE', |
||
| 575 | prefix_regex='^[ \t]*', |
||
| 576 | parameter='speed', |
||
| 577 | separator_regex='[ \t]*=[ \t]*', |
||
| 578 | value='100', |
||
| 579 | missing_parameter_pass=false, |
||
| 580 | application='', |
||
| 581 | multi_value=false, |
||
| 582 | missing_config_file_fail=false, |
||
| 583 | section='' |
||
| 584 | ) }}}""", |
||
| 585 | " speed = 100 ", |
||
| 586 | "true" |
||
| 587 | ) |
||
| 588 | tester.test( |
||
| 589 | "correct value, tabs", |
||
| 590 | r"""{{{ oval_check_config_file( |
||
| 591 | path='CONFIG_FILE', |
||
| 592 | prefix_regex='^[ \t]*', |
||
| 593 | parameter='speed', |
||
| 594 | separator_regex='[ \t]*=[ \t]*', |
||
| 595 | value='100', |
||
| 596 | missing_parameter_pass=false, |
||
| 597 | application='', |
||
| 598 | multi_value=false, |
||
| 599 | missing_config_file_fail=false, |
||
| 600 | section='' |
||
| 601 | ) }}}""", |
||
| 602 | "\tspeed\t=\t100", |
||
| 603 | "true" |
||
| 604 | ) |
||
| 605 | tester.test( |
||
| 606 | "correct value, and a comment", |
||
| 607 | r"""{{{ oval_check_config_file( |
||
| 608 | path='CONFIG_FILE', |
||
| 609 | prefix_regex='^[ \t]*', |
||
| 610 | parameter='speed', |
||
| 611 | separator_regex='[ \t]*=[ \t]*', |
||
| 612 | value='100', |
||
| 613 | missing_parameter_pass=false, |
||
| 614 | application='', |
||
| 615 | multi_value=false, |
||
| 616 | missing_config_file_fail=false, |
||
| 617 | section='' |
||
| 618 | ) }}}""", |
||
| 619 | "speed=100 # be very fast", |
||
| 620 | "true" |
||
| 621 | ) |
||
| 622 | tester.test( |
||
| 623 | "wrong value, and a comment", |
||
| 624 | r"""{{{ oval_check_config_file( |
||
| 625 | path='CONFIG_FILE', |
||
| 626 | prefix_regex='^[ \t]*', |
||
| 627 | parameter='speed', |
||
| 628 | separator_regex='[ \t]*=[ \t]*', |
||
| 629 | value='100', |
||
| 630 | missing_parameter_pass=false, |
||
| 631 | application='', |
||
| 632 | multi_value=false, |
||
| 633 | missing_config_file_fail=false, |
||
| 634 | section='' |
||
| 635 | ) }}}""", |
||
| 636 | "speed=800 # be extremely fast", |
||
| 637 | "false" |
||
| 638 | ) |
||
| 639 | tester.test( |
||
| 640 | "no value, and a comment", |
||
| 641 | r"""{{{ oval_check_config_file( |
||
| 642 | path='CONFIG_FILE', |
||
| 643 | prefix_regex='^[ \t]*', |
||
| 644 | parameter='speed', |
||
| 645 | separator_regex='[ \t]*=[ \t]*', |
||
| 646 | value='100', |
||
| 647 | missing_parameter_pass=false, |
||
| 648 | application='', |
||
| 649 | multi_value=false, |
||
| 650 | missing_config_file_fail=false, |
||
| 651 | section='' |
||
| 652 | ) }}}""", |
||
| 653 | "speed= # 100", |
||
| 654 | "false" |
||
| 655 | ) |
||
| 656 | |||
| 657 | ###################################### |
||
| 658 | # Test cases for INI files |
||
| 659 | ###################################### |
||
| 660 | tester.test( |
||
| 661 | "INI correct value", |
||
| 662 | r"""{{{ oval_check_ini_file( |
||
| 663 | path='CONFIG_FILE', |
||
| 664 | section="vehicle", |
||
| 665 | parameter='speed', |
||
| 666 | value='100', |
||
| 667 | missing_parameter_pass=false, |
||
| 668 | application='', |
||
| 669 | multi_value=false, |
||
| 670 | missing_config_file_fail=false, |
||
| 671 | ) }}}""", |
||
| 672 | """[vehicle] |
||
| 673 | speed = 100""", |
||
| 674 | "true" |
||
| 675 | ) |
||
| 676 | tester.test( |
||
| 677 | "INI correct value trailing whitespace", |
||
| 678 | r"""{{{ oval_check_ini_file( |
||
| 679 | path='CONFIG_FILE', |
||
| 680 | section="vehicle", |
||
| 681 | parameter='speed', |
||
| 682 | value='100', |
||
| 683 | missing_parameter_pass=false, |
||
| 684 | application='', |
||
| 685 | multi_value=false, |
||
| 686 | missing_config_file_fail=false, |
||
| 687 | ) }}}""", |
||
| 688 | """[vehicle] |
||
| 689 | speed = 100 """, |
||
| 690 | "true" |
||
| 691 | ) |
||
| 692 | tester.test( |
||
| 693 | "INI correct value no whitespace", |
||
| 694 | r"""{{{ oval_check_ini_file( |
||
| 695 | path='CONFIG_FILE', |
||
| 696 | section="vehicle", |
||
| 697 | parameter='speed', |
||
| 698 | value='100', |
||
| 699 | missing_parameter_pass=false, |
||
| 700 | application='', |
||
| 701 | multi_value=false, |
||
| 702 | missing_config_file_fail=false, |
||
| 703 | ) }}}""", |
||
| 704 | "[vehicle]\nspeed=100", |
||
| 705 | "true" |
||
| 706 | ) |
||
| 707 | tester.test( |
||
| 708 | "INI correct value tabs", |
||
| 709 | r"""{{{ oval_check_ini_file( |
||
| 710 | path='CONFIG_FILE', |
||
| 711 | section="vehicle", |
||
| 712 | parameter='speed', |
||
| 713 | value='100', |
||
| 714 | missing_parameter_pass=false, |
||
| 715 | application='', |
||
| 716 | multi_value=false, |
||
| 717 | missing_config_file_fail=false, |
||
| 718 | ) }}}""", |
||
| 719 | "[vehicle]\n\tspeed\t=\t100", |
||
| 720 | "true" |
||
| 721 | ) |
||
| 722 | tester.test( |
||
| 723 | "INI correct value commented out", |
||
| 724 | r"""{{{ oval_check_ini_file( |
||
| 725 | path='CONFIG_FILE', |
||
| 726 | section="vehicle", |
||
| 727 | parameter='speed', |
||
| 728 | value='100', |
||
| 729 | missing_parameter_pass=false, |
||
| 730 | application='', |
||
| 731 | multi_value=false, |
||
| 732 | missing_config_file_fail=false, |
||
| 733 | ) }}}""", |
||
| 734 | """[vehicle] |
||
| 735 | #speed = 100""", |
||
| 736 | "false" |
||
| 737 | ) |
||
| 738 | tester.test( |
||
| 739 | "INI section commented out", |
||
| 740 | r"""{{{ oval_check_ini_file( |
||
| 741 | path='CONFIG_FILE', |
||
| 742 | section="vehicle", |
||
| 743 | parameter='speed', |
||
| 744 | value='100', |
||
| 745 | missing_parameter_pass=false, |
||
| 746 | application='', |
||
| 747 | multi_value=false, |
||
| 748 | missing_config_file_fail=false, |
||
| 749 | ) }}}""", |
||
| 750 | "#[vehicle]\nspeed = 100", |
||
| 751 | "false" |
||
| 752 | ) |
||
| 753 | tester.test( |
||
| 754 | "INI correct value among multiple values", |
||
| 755 | r"""{{{ oval_check_ini_file( |
||
| 756 | path='CONFIG_FILE', |
||
| 757 | section="vehicle", |
||
| 758 | parameter='speed', |
||
| 759 | value='100', |
||
| 760 | missing_parameter_pass=false, |
||
| 761 | application='', |
||
| 762 | multi_value=false, |
||
| 763 | missing_config_file_fail=false, |
||
| 764 | ) }}}""", |
||
| 765 | """[vehicle] |
||
| 766 | color = red |
||
| 767 | speed = 100 |
||
| 768 | doors = 5""", |
||
| 769 | "true" |
||
| 770 | ) |
||
| 771 | tester.test( |
||
| 772 | "INI correct value among multiple values commented out", |
||
| 773 | r"""{{{ oval_check_ini_file( |
||
| 774 | path='CONFIG_FILE', |
||
| 775 | section="vehicle", |
||
| 776 | parameter='speed', |
||
| 777 | value='100', |
||
| 778 | missing_parameter_pass=false, |
||
| 779 | application='', |
||
| 780 | multi_value=false, |
||
| 781 | missing_config_file_fail=false, |
||
| 782 | ) }}}""", |
||
| 783 | """[vehicle] |
||
| 784 | color = red |
||
| 785 | #speed = 100 |
||
| 786 | doors = 5""", |
||
| 787 | "false" |
||
| 788 | ) |
||
| 789 | tester.test( |
||
| 790 | "INI wrong value", |
||
| 791 | r"""{{{ oval_check_ini_file( |
||
| 792 | path='CONFIG_FILE', |
||
| 793 | section="vehicle", |
||
| 794 | parameter='speed', |
||
| 795 | value='100', |
||
| 796 | missing_parameter_pass=false, |
||
| 797 | application='', |
||
| 798 | multi_value=false, |
||
| 799 | missing_config_file_fail=false, |
||
| 800 | ) }}}""", |
||
| 801 | """[vehicle] |
||
| 802 | speed = 200""", |
||
| 803 | "false" |
||
| 804 | ) |
||
| 805 | tester.test( |
||
| 806 | "INI wrong value which is a substring", |
||
| 807 | r"""{{{ oval_check_ini_file( |
||
| 808 | path='CONFIG_FILE', |
||
| 809 | section="vehicle", |
||
| 810 | parameter='speed', |
||
| 811 | value='100', |
||
| 812 | missing_parameter_pass=false, |
||
| 813 | application='', |
||
| 814 | multi_value=false, |
||
| 815 | missing_config_file_fail=false, |
||
| 816 | ) }}}""", |
||
| 817 | """[vehicle] |
||
| 818 | speed = 10000""", |
||
| 819 | "false" |
||
| 820 | ) |
||
| 821 | tester.test( |
||
| 822 | "INI overwritten", |
||
| 823 | r"""{{{ oval_check_ini_file( |
||
| 824 | path='CONFIG_FILE', |
||
| 825 | section="vehicle", |
||
| 826 | parameter='speed', |
||
| 827 | value='100', |
||
| 828 | missing_parameter_pass=false, |
||
| 829 | application='', |
||
| 830 | multi_value=false, |
||
| 831 | missing_config_file_fail=false, |
||
| 832 | ) }}}""", |
||
| 833 | """[vehicle] |
||
| 834 | speed = 100 |
||
| 835 | speed = 200""", |
||
| 836 | "false" |
||
| 837 | ) |
||
| 838 | tester.test( |
||
| 839 | "INI correct value in a wrong section", |
||
| 840 | r"""{{{ oval_check_ini_file( |
||
| 841 | path='CONFIG_FILE', |
||
| 842 | section="vehicle", |
||
| 843 | parameter='speed', |
||
| 844 | value='100', |
||
| 845 | missing_parameter_pass=false, |
||
| 846 | application='', |
||
| 847 | multi_value=false, |
||
| 848 | missing_config_file_fail=false, |
||
| 849 | ) }}}""", |
||
| 850 | """[house] |
||
| 851 | speed = 100""", |
||
| 852 | "false" |
||
| 853 | ) |
||
| 854 | tester.test( |
||
| 855 | "INI section overwritten", |
||
| 856 | r"""{{{ oval_check_ini_file( |
||
| 857 | path='CONFIG_FILE', |
||
| 858 | section="vehicle", |
||
| 859 | parameter='speed', |
||
| 860 | value='100', |
||
| 861 | missing_parameter_pass=false, |
||
| 862 | application='', |
||
| 863 | multi_value=false, |
||
| 864 | missing_config_file_fail=false, |
||
| 865 | ) }}}""", |
||
| 866 | "[vehicle]\n[house]\nspeed = 100", |
||
| 867 | "false" |
||
| 868 | ) |
||
| 869 | tester.test( |
||
| 870 | "INI no section at all", |
||
| 871 | r"""{{{ oval_check_ini_file( |
||
| 872 | path='CONFIG_FILE', |
||
| 873 | section="vehicle", |
||
| 874 | parameter='speed', |
||
| 875 | value='100', |
||
| 876 | missing_parameter_pass=false, |
||
| 877 | application='', |
||
| 878 | multi_value=false, |
||
| 879 | missing_config_file_fail=false, |
||
| 880 | ) }}}""", |
||
| 881 | "speed = 100", |
||
| 882 | "false" |
||
| 883 | ) |
||
| 884 | tester.test( |
||
| 885 | "INI extra newlines", |
||
| 886 | r"""{{{ oval_check_ini_file( |
||
| 887 | path='CONFIG_FILE', |
||
| 888 | section="vehicle", |
||
| 889 | parameter='speed', |
||
| 890 | value='100', |
||
| 891 | missing_parameter_pass=false, |
||
| 892 | application='', |
||
| 893 | multi_value=false, |
||
| 894 | missing_config_file_fail=false, |
||
| 895 | ) }}}""", |
||
| 896 | "[vehicle]\nspeed =\n100", |
||
| 897 | "false" |
||
| 898 | ) |
||
| 899 | |||
| 900 | tester.finish() |
||
| 901 | |||
| 905 |