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