| Conditions | 1 |
| Total Lines | 387 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | # -*- coding: utf-8 -*- |
||
| 278 | def gen_context_data_inputs_expected(): |
||
| 279 | # Extra field ignored |
||
| 280 | context_with_valid_extra_0 = ( |
||
| 281 | { |
||
| 282 | 'context_file': 'tests/test-generate-context-v2/test.json', |
||
| 283 | 'extra_context': [ |
||
| 284 | { |
||
| 285 | 'name': 'email', |
||
| 286 | 'default': '[email protected]', |
||
| 287 | 'description': 'Enter jazzy email...', |
||
| 288 | 'extra_field': 'extra_field_value', |
||
| 289 | } |
||
| 290 | ] |
||
| 291 | }, |
||
| 292 | { |
||
| 293 | "test": OrderedDict([ |
||
| 294 | ("name", "cookiecutter-pytest-plugin"), |
||
| 295 | ("cookiecutter_version", "2.0.0"), |
||
| 296 | ("variables", [ |
||
| 297 | OrderedDict([ |
||
| 298 | ("name", "full_name"), |
||
| 299 | ("default", "J. Paul Getty"), |
||
| 300 | ("prompt", "What's your full name?"), |
||
| 301 | ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."), |
||
| 302 | ("type", "string")]), |
||
| 303 | OrderedDict([ |
||
| 304 | ("name", "email"), |
||
| 305 | ("default", "[email protected]"), |
||
| 306 | ("prompt", "What's your email?"), |
||
| 307 | ("description", "Enter jazzy email..."), |
||
| 308 | ("type", "string")]), |
||
| 309 | ]) |
||
| 310 | ]) |
||
| 311 | } |
||
| 312 | ) |
||
| 313 | # Empty extra context precipitates no ill effect |
||
| 314 | context_with_valid_extra_1 = ( |
||
| 315 | { |
||
| 316 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 317 | 'extra_context': [] |
||
| 318 | # 'extra_context': [ |
||
| 319 | # { |
||
| 320 | # 'name': 'email', |
||
| 321 | # 'default': '[email protected]', |
||
| 322 | # 'description': 'Enter jazzy email...', |
||
| 323 | # 'extra_field': 'extra_field_value', |
||
| 324 | # } |
||
| 325 | # ] |
||
| 326 | }, |
||
| 327 | { |
||
| 328 | "representative": OrderedDict([ |
||
| 329 | ("name", "cc-representative"), |
||
| 330 | ("cookiecutter_version", "2.0.0"), |
||
| 331 | ("variables", [ |
||
| 332 | OrderedDict([ |
||
| 333 | ("name", "director_credit"), |
||
| 334 | ("default", True), |
||
| 335 | ("prompt", "Is there a director credit on this film?"), |
||
| 336 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 337 | ("type", "boolean") |
||
| 338 | ]), |
||
| 339 | OrderedDict([ |
||
| 340 | ("name", "director_name"), |
||
| 341 | ("default", "Allan Smithe"), |
||
| 342 | ("prompt", "What's the Director's full name?"), |
||
| 343 | ("prompt_user", True), |
||
| 344 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 345 | ("hide_input", False), |
||
| 346 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
| 347 | ("validation", "^[a-z][A-Z]+$"), |
||
| 348 | ("validation_flags", ["verbose", "ascii"]), |
||
| 349 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 350 | ("type", "string") |
||
| 351 | ]) |
||
| 352 | ]) |
||
| 353 | ]) |
||
| 354 | } |
||
| 355 | ) |
||
| 356 | |||
| 357 | # Test the ability to change the variable's name field since it is used to |
||
| 358 | # identify the variable to modifed with extra context and to remove a |
||
| 359 | # key from the context via the removal token: '<<ACTION::REMOVE>>' |
||
| 360 | context_with_valid_extra_2 = ( |
||
| 361 | { |
||
| 362 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 363 | 'extra_context': [ |
||
| 364 | { |
||
| 365 | 'name': 'director_credit::producer_credit', |
||
| 366 | 'prompt': 'Is there a producer credit on this film?', |
||
| 367 | 'description': 'There are usually a lot of producers...', |
||
| 368 | }, |
||
| 369 | { |
||
| 370 | 'name': 'director_name', |
||
| 371 | 'skip_if': '<<REMOVE::FIELD>>', |
||
| 372 | }, |
||
| 373 | |||
| 374 | ] |
||
| 375 | }, |
||
| 376 | { |
||
| 377 | "representative": OrderedDict([ |
||
| 378 | ("name", "cc-representative"), |
||
| 379 | ("cookiecutter_version", "2.0.0"), |
||
| 380 | ("variables", [ |
||
| 381 | OrderedDict([ |
||
| 382 | ("name", "producer_credit"), |
||
| 383 | ("default", True), |
||
| 384 | ("prompt", "Is there a producer credit on this film?"), |
||
| 385 | ("description", "There are usually a lot of producers..."), |
||
| 386 | ("type", "boolean") |
||
| 387 | ]), |
||
| 388 | OrderedDict([ |
||
| 389 | ("name", "director_name"), |
||
| 390 | ("default", "Allan Smithe"), |
||
| 391 | ("prompt", "What's the Director's full name?"), |
||
| 392 | ("prompt_user", True), |
||
| 393 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 394 | ("hide_input", False), |
||
| 395 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
| 396 | ("validation", "^[a-z][A-Z]+$"), |
||
| 397 | ("validation_flags", ["verbose", "ascii"]), |
||
| 398 | ("type", "string") |
||
| 399 | ]) |
||
| 400 | ]) |
||
| 401 | ]) |
||
| 402 | } |
||
| 403 | ) |
||
| 404 | # Test changing variable's name field value, default field, prompt field, |
||
| 405 | # and changing the type |
||
| 406 | context_with_valid_extra_3 = ( |
||
| 407 | { |
||
| 408 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 409 | 'extra_context': [ |
||
| 410 | { |
||
| 411 | 'name': 'director_credit::producer_credits', |
||
| 412 | 'default': 2, |
||
| 413 | 'prompt': 'How many producers does this film have?', |
||
| 414 | 'description': 'There are usually a lot of producers...', |
||
| 415 | 'type': "int", |
||
| 416 | } |
||
| 417 | ] |
||
| 418 | }, |
||
| 419 | { |
||
| 420 | "representative": OrderedDict([ |
||
| 421 | ("name", "cc-representative"), |
||
| 422 | ("cookiecutter_version", "2.0.0"), |
||
| 423 | ("variables", [ |
||
| 424 | OrderedDict([ |
||
| 425 | ("name", "producer_credits"), |
||
| 426 | ("default", 2), |
||
| 427 | ("prompt", "How many producers does this film have?"), |
||
| 428 | ("description", "There are usually a lot of producers..."), |
||
| 429 | ("type", "int") |
||
| 430 | ]), |
||
| 431 | OrderedDict([ |
||
| 432 | ("name", "director_name"), |
||
| 433 | ("default", "Allan Smithe"), |
||
| 434 | ("prompt", "What's the Director's full name?"), |
||
| 435 | ("prompt_user", True), |
||
| 436 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 437 | ("hide_input", False), |
||
| 438 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
| 439 | ("validation", "^[a-z][A-Z]+$"), |
||
| 440 | ("validation_flags", ["verbose", "ascii"]), |
||
| 441 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 442 | ("type", "string") |
||
| 443 | ]) |
||
| 444 | ]) |
||
| 445 | ]) |
||
| 446 | } |
||
| 447 | ) |
||
| 448 | # Test changing choices field without changing the default, but default |
||
| 449 | # does not change because the first position in choices matches default |
||
| 450 | context_with_valid_extra_4 = ( |
||
| 451 | { |
||
| 452 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 453 | 'extra_context': [ |
||
| 454 | { |
||
| 455 | 'name': 'director_name', |
||
| 456 | 'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
| 457 | 'John Ford', 'Billy Wilder'], |
||
| 458 | } |
||
| 459 | ] |
||
| 460 | }, |
||
| 461 | { |
||
| 462 | "representative": OrderedDict([ |
||
| 463 | ("name", "cc-representative"), |
||
| 464 | ("cookiecutter_version", "2.0.0"), |
||
| 465 | ("variables", [ |
||
| 466 | OrderedDict([ |
||
| 467 | ("name", "director_credit"), |
||
| 468 | ("default", True), |
||
| 469 | ("prompt", "Is there a director credit on this film?"), |
||
| 470 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 471 | ("type", "boolean") |
||
| 472 | ]), |
||
| 473 | OrderedDict([ |
||
| 474 | ("name", "director_name"), |
||
| 475 | ("default", "Allan Smithe"), |
||
| 476 | ("prompt", "What's the Director's full name?"), |
||
| 477 | ("prompt_user", True), |
||
| 478 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 479 | ("hide_input", False), |
||
| 480 | ("choices", ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford', 'Billy Wilder']), |
||
| 481 | ("validation", "^[a-z][A-Z]+$"), |
||
| 482 | ("validation_flags", ["verbose", "ascii"]), |
||
| 483 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 484 | ("type", "string") |
||
| 485 | ]) |
||
| 486 | ]) |
||
| 487 | ]) |
||
| 488 | } |
||
| 489 | ) |
||
| 490 | # Test changing choices field and changing the default |
||
| 491 | context_with_valid_extra_5 = ( |
||
| 492 | { |
||
| 493 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 494 | 'extra_context': [ |
||
| 495 | { |
||
| 496 | 'name': 'director_name', |
||
| 497 | 'default': 'John Ford', |
||
| 498 | 'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
| 499 | 'John Ford', 'Billy Wilder'], |
||
| 500 | } |
||
| 501 | ] |
||
| 502 | }, |
||
| 503 | { |
||
| 504 | "representative": OrderedDict([ |
||
| 505 | ("name", "cc-representative"), |
||
| 506 | ("cookiecutter_version", "2.0.0"), |
||
| 507 | ("variables", [ |
||
| 508 | OrderedDict([ |
||
| 509 | ("name", "director_credit"), |
||
| 510 | ("default", True), |
||
| 511 | ("prompt", "Is there a director credit on this film?"), |
||
| 512 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 513 | ("type", "boolean") |
||
| 514 | ]), |
||
| 515 | OrderedDict([ |
||
| 516 | ("name", "director_name"), |
||
| 517 | ("default", "John Ford"), |
||
| 518 | ("prompt", "What's the Director's full name?"), |
||
| 519 | ("prompt_user", True), |
||
| 520 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 521 | ("hide_input", False), |
||
| 522 | ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'Billy Wilder']), |
||
| 523 | ("validation", "^[a-z][A-Z]+$"), |
||
| 524 | ("validation_flags", ["verbose", "ascii"]), |
||
| 525 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 526 | ("type", "string") |
||
| 527 | ]) |
||
| 528 | ]) |
||
| 529 | ]) |
||
| 530 | } |
||
| 531 | ) |
||
| 532 | # Test changing the default, but not the choices field, yet seeing choices field re-ordered |
||
| 533 | # to put default value in first location |
||
| 534 | context_with_valid_extra_6 = ( |
||
| 535 | { |
||
| 536 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 537 | 'extra_context': [ |
||
| 538 | { |
||
| 539 | 'name': 'director_name', |
||
| 540 | 'default': 'John Ford', |
||
| 541 | } |
||
| 542 | ] |
||
| 543 | }, |
||
| 544 | { |
||
| 545 | "representative": OrderedDict([ |
||
| 546 | ("name", "cc-representative"), |
||
| 547 | ("cookiecutter_version", "2.0.0"), |
||
| 548 | ("variables", [ |
||
| 549 | OrderedDict([ |
||
| 550 | ("name", "director_credit"), |
||
| 551 | ("default", True), |
||
| 552 | ("prompt", "Is there a director credit on this film?"), |
||
| 553 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 554 | ("type", "boolean") |
||
| 555 | ]), |
||
| 556 | OrderedDict([ |
||
| 557 | ("name", "director_name"), |
||
| 558 | ("default", "John Ford"), |
||
| 559 | ("prompt", "What's the Director's full name?"), |
||
| 560 | ("prompt_user", True), |
||
| 561 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 562 | ("hide_input", False), |
||
| 563 | ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston']), |
||
| 564 | ("validation", "^[a-z][A-Z]+$"), |
||
| 565 | ("validation_flags", ["verbose", "ascii"]), |
||
| 566 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 567 | ("type", "string") |
||
| 568 | ]) |
||
| 569 | ]) |
||
| 570 | ]) |
||
| 571 | } |
||
| 572 | ) |
||
| 573 | # Test changing choices field without changing the default, but default |
||
| 574 | # does get changee because the first position in choices field chagned |
||
| 575 | context_with_valid_extra_7 = ( |
||
| 576 | { |
||
| 577 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 578 | 'extra_context': [ |
||
| 579 | { |
||
| 580 | 'name': 'director_name', |
||
| 581 | 'choices': ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
| 582 | 'John Ford'], |
||
| 583 | } |
||
| 584 | ] |
||
| 585 | }, |
||
| 586 | { |
||
| 587 | "representative": OrderedDict([ |
||
| 588 | ("name", "cc-representative"), |
||
| 589 | ("cookiecutter_version", "2.0.0"), |
||
| 590 | ("variables", [ |
||
| 591 | OrderedDict([ |
||
| 592 | ("name", "director_credit"), |
||
| 593 | ("default", True), |
||
| 594 | ("prompt", "Is there a director credit on this film?"), |
||
| 595 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 596 | ("type", "boolean") |
||
| 597 | ]), |
||
| 598 | OrderedDict([ |
||
| 599 | ("name", "director_name"), |
||
| 600 | ("default", "Billy Wilder"), |
||
| 601 | ("prompt", "What's the Director's full name?"), |
||
| 602 | ("prompt_user", True), |
||
| 603 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 604 | ("hide_input", False), |
||
| 605 | ("choices", ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford']), |
||
| 606 | ("validation", "^[a-z][A-Z]+$"), |
||
| 607 | ("validation_flags", ["verbose", "ascii"]), |
||
| 608 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 609 | ("type", "string") |
||
| 610 | ]) |
||
| 611 | ]) |
||
| 612 | ]) |
||
| 613 | } |
||
| 614 | ) |
||
| 615 | # Test changing the default value with a value that is not in choices, |
||
| 616 | # we should see the choice first position get updated. |
||
| 617 | context_with_valid_extra_8 = ( |
||
| 618 | { |
||
| 619 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
| 620 | 'extra_context': [ |
||
| 621 | { |
||
| 622 | 'name': 'director_name', |
||
| 623 | 'default': 'Peter Sellers', |
||
| 624 | } |
||
| 625 | ] |
||
| 626 | }, |
||
| 627 | { |
||
| 628 | "representative": OrderedDict([ |
||
| 629 | ("name", "cc-representative"), |
||
| 630 | ("cookiecutter_version", "2.0.0"), |
||
| 631 | ("variables", [ |
||
| 632 | OrderedDict([ |
||
| 633 | ("name", "director_credit"), |
||
| 634 | ("default", True), |
||
| 635 | ("prompt", "Is there a director credit on this film?"), |
||
| 636 | ("description", "Directors take credit for most of their films, usually..."), |
||
| 637 | ("type", "boolean") |
||
| 638 | ]), |
||
| 639 | OrderedDict([ |
||
| 640 | ("name", "director_name"), |
||
| 641 | ("default", "Peter Sellers"), |
||
| 642 | ("prompt", "What's the Director's full name?"), |
||
| 643 | ("prompt_user", True), |
||
| 644 | ("description", "The default director is not proud of their work, we hope you are."), |
||
| 645 | ("hide_input", False), |
||
| 646 | ("choices", ["Peter Sellers", "Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
| 647 | ("validation", "^[a-z][A-Z]+$"), |
||
| 648 | ("validation_flags", ["verbose", "ascii"]), |
||
| 649 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
| 650 | ("type", "string") |
||
| 651 | ]) |
||
| 652 | ]) |
||
| 653 | ]) |
||
| 654 | } |
||
| 655 | ) |
||
| 656 | yield context_with_valid_extra_0 |
||
| 657 | yield context_with_valid_extra_1 |
||
| 658 | yield context_with_valid_extra_2 |
||
| 659 | yield context_with_valid_extra_3 |
||
| 660 | yield context_with_valid_extra_4 |
||
| 661 | yield context_with_valid_extra_5 |
||
| 662 | yield context_with_valid_extra_6 |
||
| 663 | yield context_with_valid_extra_7 |
||
| 664 | yield context_with_valid_extra_8 |
||
| 665 | |||
| 677 |