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