| Conditions | 5 |
| Total Lines | 485 |
| Code Lines | 58 |
| 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 | # pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned,no-member |
||
| 353 | def describe_update(): |
||
| 354 | def it_should_not_modify_config(config): |
||
| 355 | gitman.update('gitman_1', depth=1) |
||
| 356 | |||
| 357 | expect(config.__mapper__.text) == CONFIG |
||
| 358 | |||
| 359 | def it_locks_previously_locked_dependnecies(config): |
||
| 360 | config.__mapper__.text = strip( |
||
| 361 | """ |
||
| 362 | location: deps |
||
| 363 | sources: |
||
| 364 | - name: gitman_1 |
||
| 365 | type: git |
||
| 366 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 367 | sparse_paths: |
||
| 368 | - |
||
| 369 | rev: example-branch |
||
| 370 | link: |
||
| 371 | scripts: |
||
| 372 | - |
||
| 373 | - name: gitman_2 |
||
| 374 | type: git |
||
| 375 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 376 | sparse_paths: |
||
| 377 | - |
||
| 378 | rev: example-tag |
||
| 379 | link: |
||
| 380 | scripts: |
||
| 381 | - |
||
| 382 | sources_locked: |
||
| 383 | - name: gitman_2 |
||
| 384 | type: git |
||
| 385 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 386 | sparse_paths: |
||
| 387 | - |
||
| 388 | rev: (old revision) |
||
| 389 | link: |
||
| 390 | scripts: |
||
| 391 | - |
||
| 392 | groups: [] |
||
| 393 | """ |
||
| 394 | ) |
||
| 395 | |||
| 396 | gitman.update(depth=1) |
||
| 397 | |||
| 398 | expect(config.__mapper__.text) == strip( |
||
| 399 | """ |
||
| 400 | location: deps |
||
| 401 | sources: |
||
| 402 | - name: gitman_1 |
||
| 403 | type: git |
||
| 404 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 405 | sparse_paths: |
||
| 406 | - |
||
| 407 | rev: example-branch |
||
| 408 | link: |
||
| 409 | scripts: |
||
| 410 | - |
||
| 411 | - name: gitman_2 |
||
| 412 | type: git |
||
| 413 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 414 | sparse_paths: |
||
| 415 | - |
||
| 416 | rev: example-tag |
||
| 417 | link: |
||
| 418 | scripts: |
||
| 419 | - |
||
| 420 | sources_locked: |
||
| 421 | - name: gitman_2 |
||
| 422 | type: git |
||
| 423 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 424 | sparse_paths: |
||
| 425 | - |
||
| 426 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 427 | link: |
||
| 428 | scripts: |
||
| 429 | - |
||
| 430 | groups: [] |
||
| 431 | """ |
||
| 432 | ) |
||
| 433 | |||
| 434 | def it_should_not_lock_dependnecies_when_disabled(config): |
||
| 435 | config.__mapper__.text = strip( |
||
| 436 | """ |
||
| 437 | location: deps |
||
| 438 | sources: |
||
| 439 | - name: gitman_1 |
||
| 440 | type: git |
||
| 441 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 442 | sparse_paths: |
||
| 443 | - |
||
| 444 | rev: example-branch |
||
| 445 | link: |
||
| 446 | scripts: |
||
| 447 | - |
||
| 448 | - name: gitman_2 |
||
| 449 | type: git |
||
| 450 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 451 | sparse_paths: |
||
| 452 | - |
||
| 453 | rev: example-tag |
||
| 454 | link: |
||
| 455 | scripts: |
||
| 456 | - |
||
| 457 | sources_locked: |
||
| 458 | - name: gitman_2 |
||
| 459 | type: git |
||
| 460 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 461 | sparse_paths: |
||
| 462 | - |
||
| 463 | rev: (old revision) |
||
| 464 | link: |
||
| 465 | scripts: |
||
| 466 | - |
||
| 467 | groups: [] |
||
| 468 | """ |
||
| 469 | ) |
||
| 470 | |||
| 471 | gitman.update(depth=1, lock=False) |
||
| 472 | |||
| 473 | expect(config.__mapper__.text) == strip( |
||
| 474 | """ |
||
| 475 | location: deps |
||
| 476 | sources: |
||
| 477 | - name: gitman_1 |
||
| 478 | type: git |
||
| 479 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 480 | sparse_paths: |
||
| 481 | - |
||
| 482 | rev: example-branch |
||
| 483 | link: |
||
| 484 | scripts: |
||
| 485 | - |
||
| 486 | - name: gitman_2 |
||
| 487 | type: git |
||
| 488 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 489 | sparse_paths: |
||
| 490 | - |
||
| 491 | rev: example-tag |
||
| 492 | link: |
||
| 493 | scripts: |
||
| 494 | - |
||
| 495 | sources_locked: |
||
| 496 | - name: gitman_2 |
||
| 497 | type: git |
||
| 498 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 499 | sparse_paths: |
||
| 500 | - |
||
| 501 | rev: (old revision) |
||
| 502 | link: |
||
| 503 | scripts: |
||
| 504 | - |
||
| 505 | groups: [] |
||
| 506 | """ |
||
| 507 | ) |
||
| 508 | |||
| 509 | def it_should_not_allow_source_and_group_name_conflicts(config): |
||
| 510 | config.__mapper__.text = strip( |
||
| 511 | """ |
||
| 512 | location: deps |
||
| 513 | sources: |
||
| 514 | - name: gitman_1 |
||
| 515 | type: git |
||
| 516 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 517 | rev: example-branch |
||
| 518 | - name: gitman_2 |
||
| 519 | type: git |
||
| 520 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 521 | rev: example-branch |
||
| 522 | groups: |
||
| 523 | - name: gitman_1 |
||
| 524 | members: |
||
| 525 | - gitman_1 |
||
| 526 | - gitman_2 |
||
| 527 | """ |
||
| 528 | ) |
||
| 529 | |||
| 530 | with pytest.raises(InvalidConfig): |
||
| 531 | gitman.update(depth=1, lock=True) |
||
| 532 | |||
| 533 | def it_locks_previously_locked_dependnecies_by_group_name(config): |
||
| 534 | config.__mapper__.text = strip( |
||
| 535 | """ |
||
| 536 | location: deps |
||
| 537 | sources: |
||
| 538 | - name: gitman_1 |
||
| 539 | type: git |
||
| 540 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 541 | sparse_paths: |
||
| 542 | - |
||
| 543 | rev: example-branch |
||
| 544 | link: |
||
| 545 | scripts: |
||
| 546 | - |
||
| 547 | - name: gitman_2 |
||
| 548 | type: git |
||
| 549 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 550 | sparse_paths: |
||
| 551 | - |
||
| 552 | rev: example-tag |
||
| 553 | link: |
||
| 554 | scripts: |
||
| 555 | - |
||
| 556 | - name: gitman_3 |
||
| 557 | type: git |
||
| 558 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 559 | sparse_paths: |
||
| 560 | - |
||
| 561 | rev: example-tag |
||
| 562 | link: |
||
| 563 | scripts: |
||
| 564 | - |
||
| 565 | sources_locked: |
||
| 566 | - name: gitman_1 |
||
| 567 | type: git |
||
| 568 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 569 | sparse_paths: |
||
| 570 | - |
||
| 571 | rev: (old revision) |
||
| 572 | link: |
||
| 573 | scripts: |
||
| 574 | - |
||
| 575 | - name: gitman_2 |
||
| 576 | type: git |
||
| 577 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 578 | sparse_paths: |
||
| 579 | - |
||
| 580 | rev: (old revision) |
||
| 581 | link: |
||
| 582 | scripts: |
||
| 583 | - |
||
| 584 | groups: |
||
| 585 | - name: group_a |
||
| 586 | members: |
||
| 587 | - gitman_1 |
||
| 588 | - gitman_2 |
||
| 589 | """ |
||
| 590 | ) |
||
| 591 | |||
| 592 | gitman.update('group_a', depth=1) |
||
| 593 | |||
| 594 | expect(config.__mapper__.text) == strip( |
||
| 595 | """ |
||
| 596 | location: deps |
||
| 597 | sources: |
||
| 598 | - name: gitman_1 |
||
| 599 | type: git |
||
| 600 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 601 | sparse_paths: |
||
| 602 | - |
||
| 603 | rev: example-branch |
||
| 604 | link: |
||
| 605 | scripts: |
||
| 606 | - |
||
| 607 | - name: gitman_2 |
||
| 608 | type: git |
||
| 609 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 610 | sparse_paths: |
||
| 611 | - |
||
| 612 | rev: example-tag |
||
| 613 | link: |
||
| 614 | scripts: |
||
| 615 | - |
||
| 616 | - name: gitman_3 |
||
| 617 | type: git |
||
| 618 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 619 | sparse_paths: |
||
| 620 | - |
||
| 621 | rev: example-tag |
||
| 622 | link: |
||
| 623 | scripts: |
||
| 624 | - |
||
| 625 | sources_locked: |
||
| 626 | - name: gitman_1 |
||
| 627 | type: git |
||
| 628 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 629 | sparse_paths: |
||
| 630 | - |
||
| 631 | rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd |
||
| 632 | link: |
||
| 633 | scripts: |
||
| 634 | - |
||
| 635 | - name: gitman_2 |
||
| 636 | type: git |
||
| 637 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 638 | sparse_paths: |
||
| 639 | - |
||
| 640 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 641 | link: |
||
| 642 | scripts: |
||
| 643 | - |
||
| 644 | groups: |
||
| 645 | - name: group_a |
||
| 646 | members: |
||
| 647 | - gitman_1 |
||
| 648 | - gitman_2 |
||
| 649 | """ |
||
| 650 | ) |
||
| 651 | |||
| 652 | def it_should_not_lock_dependencies_changes_force_interactive_no( |
||
| 653 | config, monkeypatch |
||
| 654 | ): |
||
| 655 | def git_changes( |
||
| 656 | type, include_untracked=False, display_status=True, _show=False |
||
| 657 | ): |
||
| 658 | # always return True because changes won't be overwriten |
||
| 659 | return True |
||
| 660 | |||
| 661 | # patch the git.changes function to stimulate the |
||
| 662 | # force-interactive question (without changes no question) |
||
| 663 | monkeypatch.setattr('gitman.git.changes', git_changes) |
||
| 664 | # patch standard input function to return "n" for each call |
||
| 665 | # this is necessary to answer the force-interactive question |
||
| 666 | # with no to skip the force process |
||
| 667 | monkeypatch.setattr('builtins.input', lambda x: "n") |
||
| 668 | |||
| 669 | config.__mapper__.text = strip( |
||
| 670 | """ |
||
| 671 | location: deps |
||
| 672 | sources: |
||
| 673 | - name: gitman_2 |
||
| 674 | type: git |
||
| 675 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 676 | sparse_paths: |
||
| 677 | - |
||
| 678 | rev: example-tag |
||
| 679 | link: |
||
| 680 | scripts: |
||
| 681 | - |
||
| 682 | sources_locked: |
||
| 683 | - name: gitman_2 |
||
| 684 | type: git |
||
| 685 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 686 | sparse_paths: |
||
| 687 | - |
||
| 688 | rev: (old revision) |
||
| 689 | link: |
||
| 690 | scripts: |
||
| 691 | - |
||
| 692 | groups: [] |
||
| 693 | """ |
||
| 694 | ) |
||
| 695 | |||
| 696 | gitman.update(depth=1, force_interactive=True) |
||
| 697 | |||
| 698 | expect(config.__mapper__.text) == strip( |
||
| 699 | """ |
||
| 700 | location: deps |
||
| 701 | sources: |
||
| 702 | - name: gitman_2 |
||
| 703 | type: git |
||
| 704 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 705 | sparse_paths: |
||
| 706 | - |
||
| 707 | rev: example-tag |
||
| 708 | link: |
||
| 709 | scripts: |
||
| 710 | - |
||
| 711 | sources_locked: |
||
| 712 | - name: gitman_2 |
||
| 713 | type: git |
||
| 714 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 715 | sparse_paths: |
||
| 716 | - |
||
| 717 | rev: (old revision) |
||
| 718 | link: |
||
| 719 | scripts: |
||
| 720 | - |
||
| 721 | groups: [] |
||
| 722 | """ |
||
| 723 | ) |
||
| 724 | |||
| 725 | def it_locks_dependencies_changes_force_interactive_yes(config, monkeypatch): |
||
| 726 | def git_changes( |
||
| 727 | type, include_untracked=False, display_status=True, _show=False |
||
| 728 | ): |
||
| 729 | |||
| 730 | # get caller function name |
||
| 731 | caller = inspect.stack()[1].function |
||
| 732 | # if caller is update_files then we return True |
||
| 733 | # to simulate local changes |
||
| 734 | if caller == "update_files": |
||
| 735 | return True |
||
| 736 | |||
| 737 | # all other functions get False because after |
||
| 738 | # the force process there are logically no changes anymore |
||
| 739 | return False |
||
| 740 | |||
| 741 | # patch the git.changes function to stimulate the |
||
| 742 | # force-interactive question (without changes no question) |
||
| 743 | monkeypatch.setattr('gitman.git.changes', git_changes) |
||
| 744 | # patch standard input function to return "y" for each call |
||
| 745 | # this is necessary to answer the force-interactive question |
||
| 746 | # with yes todo the force process |
||
| 747 | monkeypatch.setattr('builtins.input', lambda x: "y") |
||
| 748 | |||
| 749 | config.__mapper__.text = strip( |
||
| 750 | """ |
||
| 751 | location: deps |
||
| 752 | sources: |
||
| 753 | - name: gitman_2 |
||
| 754 | type: git |
||
| 755 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 756 | sparse_paths: |
||
| 757 | - |
||
| 758 | rev: example-tag |
||
| 759 | link: |
||
| 760 | scripts: |
||
| 761 | - |
||
| 762 | sources_locked: |
||
| 763 | - name: gitman_2 |
||
| 764 | type: git |
||
| 765 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 766 | sparse_paths: |
||
| 767 | - |
||
| 768 | rev: (old revision) |
||
| 769 | link: |
||
| 770 | scripts: |
||
| 771 | - |
||
| 772 | groups: [] |
||
| 773 | """ |
||
| 774 | ) |
||
| 775 | |||
| 776 | gitman.update(depth=1, force_interactive=True) |
||
| 777 | |||
| 778 | expect(config.__mapper__.text) == strip( |
||
| 779 | """ |
||
| 780 | location: deps |
||
| 781 | sources: |
||
| 782 | - name: gitman_2 |
||
| 783 | type: git |
||
| 784 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 785 | sparse_paths: |
||
| 786 | - |
||
| 787 | rev: example-tag |
||
| 788 | link: |
||
| 789 | scripts: |
||
| 790 | - |
||
| 791 | sources_locked: |
||
| 792 | - name: gitman_2 |
||
| 793 | type: git |
||
| 794 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 795 | sparse_paths: |
||
| 796 | - |
||
| 797 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 798 | link: |
||
| 799 | scripts: |
||
| 800 | - |
||
| 801 | groups: [] |
||
| 802 | """ |
||
| 803 | ) |
||
| 804 | |||
| 805 | def it_merges_sources(config): |
||
| 806 | config.__mapper__.text = strip( |
||
| 807 | """ |
||
| 808 | location: deps |
||
| 809 | sources: |
||
| 810 | - name: gitman_1 |
||
| 811 | type: git |
||
| 812 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 813 | rev: example-branch |
||
| 814 | link: |
||
| 815 | scripts: |
||
| 816 | - |
||
| 817 | sources_locked: |
||
| 818 | - name: gitman_2 |
||
| 819 | type: git |
||
| 820 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 821 | rev: example-branch |
||
| 822 | link: |
||
| 823 | scripts: |
||
| 824 | - |
||
| 825 | - name: gitman_3 |
||
| 826 | type: git |
||
| 827 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 828 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 829 | link: |
||
| 830 | scripts: |
||
| 831 | - |
||
| 832 | """ |
||
| 833 | ) |
||
| 834 | |||
| 835 | expect(gitman.install(depth=1)) == True |
||
| 836 | |||
| 837 | expect(len(os.listdir(config.location))) == 3 |
||
| 838 | |||
| 966 |