5
5
6
6
# local lib
7
7
from jupyterlab_git .git import Git
8
+ from .testutils import FakeContentManager
8
9
9
10
10
11
def test_is_remote_branch ():
@@ -18,7 +19,7 @@ def test_is_remote_branch():
18
19
(
'refs/tags/[email protected] ' ,
False )
19
20
]
20
21
for test_case in test_cases :
21
- actual_response = Git (root_dir = '/bin' )._is_remote_branch (test_case [0 ])
22
+ actual_response = Git (FakeContentManager ( '/bin' ) )._is_remote_branch (test_case [0 ])
22
23
assert test_case [1 ] == actual_response
23
24
24
25
@@ -35,12 +36,12 @@ def test_get_branch_name():
35
36
36
37
]
37
38
for test_case in good_test_cases :
38
- actual_response = Git (root_dir = '/bin' )._get_branch_name (test_case [0 ])
39
+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_branch_name (test_case [0 ])
39
40
assert test_case [1 ] == actual_response
40
41
41
42
for test_case in bad_test_cases :
42
43
with pytest .raises (ValueError ):
43
- Git (root_dir = '/bin' )._get_branch_name (test_case )
44
+ Git (FakeContentManager ( '/bin' ) )._get_branch_name (test_case )
44
45
45
46
46
47
@patch ('subprocess.Popen' )
@@ -55,7 +56,7 @@ def test_get_current_branch_success(mock_subproc_popen):
55
56
mock_subproc_popen .return_value = process_mock
56
57
57
58
# When
58
- actual_response = Git (root_dir = '/bin' ).get_current_branch (
59
+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_current_branch (
59
60
current_path = 'test_curr_path' )
60
61
61
62
# Then
@@ -265,12 +266,12 @@ def test_get_branch_reference_success(mock_subproc_popen):
265
266
}
266
267
process_mock .configure_mock (** attrs )
267
268
mock_subproc_popen .return_value = process_mock
268
-
269
+
269
270
# When
270
271
actual_response = Git (root_dir = '/bin' )._get_branch_reference (
271
272
branchname = branch ,
272
273
current_path = 'test_curr_path' )
273
-
274
+
274
275
# Then
275
276
mock_subproc_popen .assert_has_calls ([
276
277
call (
@@ -300,12 +301,12 @@ def test_get_branch_reference_failure(mock_subproc_popen):
300
301
}
301
302
process_mock .configure_mock (** attrs )
302
303
mock_subproc_popen .return_value = process_mock
303
-
304
+
304
305
# When
305
306
actual_response = Git (root_dir = '/bin' )._get_branch_reference (
306
307
branchname = branch ,
307
308
current_path = 'test_curr_path' )
308
-
309
+
309
310
# Then
310
311
mock_subproc_popen .assert_has_calls ([
311
312
call (
@@ -333,7 +334,7 @@ def test_get_current_branch_failure(mock_subproc_popen):
333
334
334
335
# When
335
336
with pytest .raises (Exception ) as error :
336
- Git (root_dir = '/bin' ).get_current_branch (current_path = 'test_curr_path' )
337
+ Git (FakeContentManager ( '/bin' ) ).get_current_branch (current_path = 'test_curr_path' )
337
338
338
339
# Then
339
340
mock_subproc_popen .assert_has_calls ([
@@ -368,7 +369,7 @@ def test_get_current_branch_detached_success(mock_subproc_popen):
368
369
mock_subproc_popen .return_value = process_mock
369
370
370
371
# When
371
- actual_response = Git (root_dir = '/bin' )._get_current_branch_detached (
372
+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_current_branch_detached (
372
373
current_path = 'test_curr_path' )
373
374
374
375
# Then
@@ -398,7 +399,7 @@ def test_get_current_branch_detached_failure(mock_subproc_popen):
398
399
399
400
# When
400
401
with pytest .raises (Exception ) as error :
401
- Git (root_dir = '/bin' )._get_current_branch_detached (current_path = 'test_curr_path' )
402
+ Git (FakeContentManager ( '/bin' ) )._get_current_branch_detached (current_path = 'test_curr_path' )
402
403
403
404
# Then
404
405
mock_subproc_popen .assert_has_calls ([
@@ -434,7 +435,7 @@ def test_get_upstream_branch_success(mock_subproc_popen):
434
435
mock_subproc_popen .return_value = process_mock
435
436
436
437
# When
437
- actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
438
+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
438
439
current_path = 'test_curr_path' , branch_name = test_case [0 ])
439
440
440
441
# Then
@@ -466,7 +467,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
466
467
467
468
# When: fatal: no such branch: 'blah'
468
469
with pytest .raises (Exception ) as error :
469
- Git (root_dir = '/bin' ).get_upstream_branch (
470
+ Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
470
471
current_path = 'test_curr_path' , branch_name = 'blah' )
471
472
472
473
# Then
@@ -485,7 +486,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
485
486
error .value )
486
487
487
488
# When: fatal: no upstream configured for branch
488
- actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
489
+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
489
490
current_path = 'test_curr_path' , branch_name = 'test' )
490
491
491
492
# Then
@@ -502,7 +503,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
502
503
assert None == actual_response
503
504
504
505
# When: "fatal: ambiguous argument 'blah@origin': unknown revision or path not in the working tree.
505
- actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
506
+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
506
507
current_path = 'test_curr_path' , branch_name = 'blah' )
507
508
508
509
# Then
@@ -531,7 +532,7 @@ def test_get_tag_success(mock_subproc_popen):
531
532
mock_subproc_popen .return_value = process_mock
532
533
533
534
# When
534
- actual_response = Git (root_dir = '/bin' )._get_tag (
535
+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag (
535
536
current_path = 'test_curr_path' , commit_sha = 'abcdefghijklmnopqrstuvwxyz01234567890123' )
536
537
537
538
# Then
@@ -559,14 +560,14 @@ def test_get_tag_failure(mock_subproc_popen):
559
560
560
561
# When
561
562
with pytest .raises (Exception ) as error :
562
- Git (root_dir = '/bin' )._get_tag (
563
+ Git (FakeContentManager ( '/bin' ) )._get_tag (
563
564
current_path = 'test_curr_path' , commit_sha = 'blah' )
564
565
565
566
assert "Error [fatal: Not a valid object name blah] " \
566
567
"occurred while executing [git describe --tags blah] command to get nearest tag associated with branch." == str (
567
568
error .value )
568
569
569
- actual_response = Git (root_dir = '/bin' )._get_tag (
570
+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag (
570
571
current_path = 'test_curr_path' , commit_sha = '01234567899999abcdefghijklmnopqrstuvwxyz' )
571
572
572
573
assert None == actual_response
@@ -602,7 +603,7 @@ def test_no_tags(mock_subproc_popen):
602
603
mock_subproc_popen .return_value = process_mock
603
604
604
605
# When
605
- actual_response = Git (root_dir = '/bin' )._get_tag ('/path/foo' , '768c79ad661598889f29bdf8916f4cc488f5062a' )
606
+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag ('/path/foo' , '768c79ad661598889f29bdf8916f4cc488f5062a' )
606
607
607
608
# Then
608
609
mock_subproc_popen .assert_has_calls ([
@@ -694,7 +695,7 @@ def test_branch_success(mock_subproc_popen):
694
695
}
695
696
696
697
# When
697
- actual_response = Git (root_dir = '/bin' ).branch (
698
+ actual_response = Git (FakeContentManager ( '/bin' ) ).branch (
698
699
current_path = 'test_curr_path' )
699
700
700
701
# Then
@@ -740,7 +741,7 @@ def test_branch_failure(mock_subproc_popen):
740
741
}
741
742
742
743
# When
743
- actual_response = Git (root_dir = '/bin' ).branch (current_path = 'test_curr_path' )
744
+ actual_response = Git (FakeContentManager ( '/bin' ) ).branch (current_path = 'test_curr_path' )
744
745
745
746
# Then
746
747
mock_subproc_popen .assert_has_calls ([
@@ -828,7 +829,7 @@ def com_mock_side_effect():
828
829
}
829
830
830
831
# When
831
- actual_response = Git (root_dir = '/bin' ).branch (
832
+ actual_response = Git (FakeContentManager ( '/bin' ) ).branch (
832
833
current_path = 'test_curr_path' )
833
834
834
835
# Then
0 commit comments