Completed
Push — develop ( 9ba97b...51e53a )
by Jace
14s queued 11s
created

tests.test_api.describe_lock()   B

Complexity

Conditions 4

Size

Total Lines 107
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 38
nop 0
dl 0
loc 107
rs 8.968
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
# pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned,no-member
2
3
import inspect
4
import os
5
import shutil
6
from contextlib import suppress
7
8
import log
9
import pytest
10
from expecter import expect
11
from freezegun import freeze_time
12
13
import gitman
14
from gitman import shell
15
from gitman.exceptions import InvalidConfig, InvalidRepository, UncommittedChanges
16
from gitman.models import Config
17
18
from .utilities import strip
19
20
21
ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)))
22
TMP = os.path.join(ROOT, 'tmp')
23
24
CONFIG = """
25
location: deps
26
sources:
27
- name: gitman_1
28
  type: git
29
  repo: https://github.com/jacebrowning/gitman-demo
30
  sparse_paths:
31
  -
32
  rev: example-branch
33
  link:
34
  scripts:
35
  -
36
- name: gitman_2
37
  type: git
38
  repo: https://github.com/jacebrowning/gitman-demo
39
  sparse_paths:
40
  -
41
  rev: example-tag
42
  link:
43
  scripts:
44
  -
45
- name: gitman_3
46
  type: git
47
  repo: https://github.com/jacebrowning/gitman-demo
48
  sparse_paths:
49
  -
50
  rev: 9bf18e16b956041f0267c21baad555a23237b52e
51
  link:
52
  scripts:
53
  -
54
sources_locked:
55
-
56
groups:
57
-
58
""".lstrip()
59
60
61
@pytest.yield_fixture
62
def config():
63
    log.info("Temporary directory: %s", TMP)
64
65
    with suppress(FileNotFoundError, PermissionError):
66
        shutil.rmtree(TMP)
67
    with suppress(FileExistsError):
68
        os.makedirs(TMP)
69
    os.chdir(TMP)
70
71
    os.system("touch .git")
72
    config = Config(root=TMP)
73
    config.datafile.text = CONFIG
74
    config.datafile.load()
75
76
    log.debug("File listing: %s", os.listdir(TMP))
77
78
    yield config
79
80
    os.chdir(ROOT)
81
82
83
def describe_init():
84
    def it_creates_a_new_config_file(tmpdir):
85
        tmpdir.chdir()
86
87
        expect(gitman.init()) == True
88
89
        expect(Config().datafile.text) == strip(
90
            """
91
        location: gitman_sources
92
        sources:
93
        - name: sample_dependency
94
          type: git
95
          repo: https://github.com/githubtraining/hellogitworld
96
          sparse_paths:
97
          -
98
          rev: master
99
          link:
100
          scripts:
101
          -
102
        sources_locked:
103
        - name: sample_dependency
104
          type: git
105
          repo: https://github.com/githubtraining/hellogitworld
106
          sparse_paths:
107
          -
108
          rev: ebbbf773431ba07510251bb03f9525c7bab2b13a
109
          link:
110
          scripts:
111
          -
112
        groups:
113
        -
114
        """
115
        )
116
117
    def it_does_not_modify_existing_config_file(config):
118
        expect(gitman.init()) == False
119
120
        expect(config.datafile.text) == CONFIG
121
122
123
def describe_install():
124
    def it_creates_missing_directories(config):
125
        shell.rm(config.location)
126
127
        expect(gitman.install('gitman_1', depth=1)) == True
128
129
        expect(os.listdir(config.location)) == ['gitman_1']
130
131
    def it_should_not_modify_config(config):
132
        expect(gitman.install('gitman_1', depth=1)) == True
133
134
        expect(config.datafile.text) == CONFIG
135
136
    def it_merges_sources(config):
137
        config.datafile.text = strip(
138
            """
139
        location: deps
140
        sources:
141
        - name: gitman_1
142
          type: git
143
          repo: https://github.com/jacebrowning/gitman-demo
144
          rev: example-branch
145
          link:
146
          scripts:
147
          -
148
        sources_locked:
149
        - name: gitman_2
150
          type: git
151
          repo: https://github.com/jacebrowning/gitman-demo
152
          rev: example-branch
153
          link:
154
          scripts:
155
          -
156
        - name: gitman_3
157
          type: git
158
          repo: https://github.com/jacebrowning/gitman-demo
159
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
160
          link:
161
          scripts:
162
          -
163
        """
164
        )
165
        config.datafile.load()
166
167
        expect(gitman.install(depth=1)) == True
168
169
        expect(len(os.listdir(config.location))) == 3
170
171
    def it_can_handle_missing_locked_sources(config):
172
        config.datafile.text = strip(
173
            """
174
        location: deps
175
        sources:
176
        - name: gitman_1
177
          repo: https://github.com/jacebrowning/gitman-demo
178
          rev: example-branch
179
          link:
180
          scripts:
181
          -
182
        sources_locked:
183
        - name: gitman_2
184
          type: git
185
          repo: https://github.com/jacebrowning/gitman-demo
186
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
187
          link:
188
          scripts:
189
          -
190
        """
191
        )
192
        config.datafile.load()
193
194
        expect(gitman.install('gitman_1', depth=1)) == True
195
196
        expect(os.listdir(config.location)) == ['gitman_1']
197
198
    def it_detects_invalid_repositories(config):
199
        shell.rm(os.path.join("deps", "gitman_1", ".git"))
200
        shell.mkdir(os.path.join("deps", "gitman_1", ".git"))
201
202
        try:
203
            with pytest.raises(InvalidRepository):
204
                expect(gitman.install('gitman_1', depth=1)) == False
205
206
        finally:
207
            shell.rm(os.path.join("deps", "gitman_1"))
208
209
    def describe_links():
210
        @pytest.fixture
211
        def config_with_link(config):
212
            config.datafile.text = strip(
213
                """
214
            location: deps
215
            sources:
216
            - name: gitman_1
217
              repo: https://github.com/jacebrowning/gitman-demo
218
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
219
              link: my_link
220
              scripts:
221
              -
222
            """
223
            )
224
            config.datafile.load()
225
226
            return config
227
228
        def it_should_create_links(config_with_link):
229
            expect(gitman.install(depth=1)) == True
230
231
            expect(os.listdir()).contains('my_link')
232
233
        def it_should_not_overwrite_files(config_with_link):
234
            os.system("touch my_link")
235
236
            with pytest.raises(RuntimeError):
237
                gitman.install(depth=1)
238
239
        def it_overwrites_files_with_force(config_with_link):
240
            os.system("touch my_link")
241
242
            expect(gitman.install(depth=1, force=True)) == True
243
244
    def describe_scripts():
245
        @pytest.fixture
246
        def config_with_scripts(config):
247
            config.datafile.text = strip(
248
                """
249
            location: deps
250
            sources:
251
            - name: gitman_1
252
              type: git
253
              repo: https://github.com/jacebrowning/gitman-demo
254
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
255
              link:
256
              scripts:
257
              - make foobar
258
            """
259
            )
260
            config.datafile.load()
261
262
            return config
263
264
        def it_detects_failures_in_scripts(config_with_scripts):
265
            with pytest.raises(RuntimeError):
266
                expect(gitman.install())
267
268
        def script_failures_can_be_ignored(config_with_scripts):
269
            expect(gitman.install(force=True)) == True
270
271
    def describe_sparse_paths():
272
        @pytest.fixture
273
        def config_with_scripts(config):
274
            config.datafile.text = strip(
275
                """
276
                    location: deps
277
                    sources:
278
                    - name: gitman_1
279
                      type: git
280
                      repo: https://github.com/jacebrowning/gitman-demo
281
                      sparse_paths:
282
                      - src/*
283
                      rev: ddbe17ef173538d1fda29bd99a14bab3c5d86e78
284
                      link:
285
                      scripts:
286
                      -
287
                    """
288
            )
289
            config.datafile.load()
290
291
            return config
292
293
        def it_successfully_materializes_the_repo(config):
294
            expect(gitman.install(depth=1, force=True)) == True
295
            dir_listing = os.listdir(os.path.join(config.location, "gitman_1"))
296
            expect(dir_listing).contains('src')
297
298
        def it_contains_only_the_sparse_paths(config):
299
            expect(gitman.install(depth=1, force=True)) == True
300
            dir_listing = os.listdir(os.path.join(config.location, "gitman_1"))
301
            expect(dir_listing).contains('src')
302
            expect(len(dir_listing) == 1)
303
304
305
def describe_uninstall():
306
    def it_deletes_dependencies_when_they_exist(config):
307
        gitman.install('gitman_1', depth=1)
308
        expect(os.path.isdir(config.location)) == True
309
310
        expect(gitman.uninstall()) == True
311
312
        expect(os.path.exists(config.location)) == False
313
314
    def it_should_not_fail_when_no_dependencies_exist(config):
315
        expect(os.path.isdir(config.location)) == False
316
317
        expect(gitman.uninstall()) == True
318
319
    def it_deletes_the_log_file(config):
320
        gitman.install('gitman_1', depth=1)
321
        gitman.list()
322
        expect(os.path.exists(config.log_path)) == True
323
324
        gitman.uninstall()
325
        expect(os.path.exists(config.log_path)) == False
326
327
328
def describe_keep_location():
329
    def it_deletes_dependencies_when_they_exist(config):
330
        gitman.install('gitman_1', depth=1)
331
        expect(os.path.isdir(config.location)) == True
332
333
        expect(gitman.uninstall(keep_location=True)) == True
334
335
        path = os.path.join(config.location, 'gitman_1')
336
        expect(os.path.exists(path)) == False
337
338
        expect(os.path.exists(config.location)) == True
339
340
        gitman.uninstall()
341
342
    def it_should_not_fail_when_no_dependencies_exist(config):
343
        expect(os.path.isdir(config.location)) == False
344
345
        expect(gitman.uninstall(keep_location=True)) == True
346
347
        gitman.uninstall()
348
349
    def it_deletes_the_log_file(config):
350
        gitman.install('gitman_1', depth=1)
351
        gitman.list()
352
        expect(os.path.exists(config.log_path)) == True
353
354
        gitman.uninstall(keep_location=True)
355
        expect(os.path.exists(config.log_path)) == False
356
357
        gitman.uninstall()
358
359
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
864
865
def describe_list():
866
    @freeze_time("2012-01-14 12:00:01")
867
    def it_updates_the_log(config):
868
        gitman.install()
869
        gitman.list()
870
871
        with open(config.log_path) as stream:
872
            contents = stream.read().replace(TMP, "tmp").replace('\\', '/')
873
        expect(contents) == strip(
874
            """
875
        2012-01-14 12:00:01
876
        tmp/deps/gitman_1: https://github.com/jacebrowning/gitman-demo @ 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
877
        tmp/deps/gitman_1/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ 050290bca3f14e13fd616604202b579853e7bfb0
878
        tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ fb693447579235391a45ca170959b5583c5042d8
879
        tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
880
        tmp/deps/gitman_1/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
881
        tmp/deps/gitman_2: https://github.com/jacebrowning/gitman-demo @ 7bd138fe7359561a8c2ff9d195dff238794ccc04
882
        tmp/deps/gitman_3: https://github.com/jacebrowning/gitman-demo @ 9bf18e16b956041f0267c21baad555a23237b52e
883
        """,
884
            end='\n\n',
885
        )
886
887
888
def describe_lock():
889
    def it_records_all_versions_when_no_arguments(config):
890
        expect(gitman.update(depth=1, lock=False)) == True
891
        expect(gitman.lock()) == True
892
893
        config.datafile.load()
894
        expect(config.datafile.text).contains(
895
            strip(
896
                """
897
        sources_locked:
898
        - name: gitman_1
899
          type: git
900
          repo: https://github.com/jacebrowning/gitman-demo
901
          sparse_paths:
902
          -
903
          rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
904
          link:
905
          scripts:
906
          -
907
        - name: gitman_2
908
          type: git
909
          repo: https://github.com/jacebrowning/gitman-demo
910
          sparse_paths:
911
          -
912
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
913
          link:
914
          scripts:
915
          -
916
        - name: gitman_3
917
          type: git
918
          repo: https://github.com/jacebrowning/gitman-demo
919
          sparse_paths:
920
          -
921
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
922
          link:
923
          scripts:
924
          -
925
        """
926
            )
927
        )
928
929
    def it_records_specified_dependencies(config):
930
        expect(gitman.update(depth=1, lock=False)) == True
931
        expect(gitman.lock('gitman_1', 'gitman_3')) == True
932
933
        config.datafile.load()
934
        expect(config.datafile.text).contains(
935
            strip(
936
                """
937
        sources_locked:
938
        - name: gitman_1
939
          type: git
940
          repo: https://github.com/jacebrowning/gitman-demo
941
          sparse_paths:
942
          -
943
          rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
944
          link:
945
          scripts:
946
          -
947
        - name: gitman_3
948
          type: git
949
          repo: https://github.com/jacebrowning/gitman-demo
950
          sparse_paths:
951
          -
952
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
953
          link:
954
          scripts:
955
          -
956
        """
957
            )
958
        )
959
960
    def it_should_fail_on_dirty_repositories(config):
961
        expect(gitman.update(depth=1, lock=False)) == True
962
        shell.rm(os.path.join("deps", "gitman_1", ".project"))
963
964
        try:
965
            with pytest.raises(UncommittedChanges):
966
                gitman.lock()
967
968
            expect(config.datafile.text).does_not_contain("<dirty>")
969
970
        finally:
971
            shell.rm(os.path.join("deps", "gitman_1"))
972
973
    def it_should_fail_on_missing_repositories(config):
974
        shell.mkdir("deps")
975
        shell.rm(os.path.join("deps", "gitman_1"))
976
977
        with pytest.raises(InvalidRepository):
978
            gitman.lock()
979
980
        expect(config.datafile.text).does_not_contain("<unknown>")
981
982
    def it_should_fail_on_invalid_repositories(config):
983
        shell.mkdir("deps")
984
        shell.rm(os.path.join("deps", "gitman_1", ".git"))
985
        shell.mkdir(os.path.join("deps", "gitman_1", ".git"))
986
987
        try:
988
            with pytest.raises(InvalidRepository):
989
                gitman.lock()
990
991
            expect(config.datafile.text).does_not_contain("<unknown>")
992
993
        finally:
994
            shell.rm(os.path.join("deps", "gitman_1"))
995