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