55
66# local lib
77from jupyterlab_git .git import Git
8+ from .testutils import FakeContentManager
89
910
1011def test_is_remote_branch ():
@@ -18,7 +19,7 @@ def test_is_remote_branch():
1819 ('refs/tags/blah@0.2.0' , False )
1920 ]
2021 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 ])
2223 assert test_case [1 ] == actual_response
2324
2425
@@ -35,12 +36,12 @@ def test_get_branch_name():
3536 'refs/tags/blah@0.2.0'
3637 ]
3738 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 ])
3940 assert test_case [1 ] == actual_response
4041
4142 for test_case in bad_test_cases :
4243 with pytest .raises (ValueError ):
43- Git (root_dir = '/bin' )._get_branch_name (test_case )
44+ Git (FakeContentManager ( '/bin' ) )._get_branch_name (test_case )
4445
4546
4647@patch ('subprocess.Popen' )
@@ -55,7 +56,7 @@ def test_get_current_branch_success(mock_subproc_popen):
5556 mock_subproc_popen .return_value = process_mock
5657
5758 # When
58- actual_response = Git (root_dir = '/bin' ).get_current_branch (
59+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_current_branch (
5960 current_path = 'test_curr_path' )
6061
6162 # Then
@@ -265,12 +266,12 @@ def test_get_branch_reference_success(mock_subproc_popen):
265266 }
266267 process_mock .configure_mock (** attrs )
267268 mock_subproc_popen .return_value = process_mock
268-
269+
269270 # When
270271 actual_response = Git (root_dir = '/bin' )._get_branch_reference (
271272 branchname = branch ,
272273 current_path = 'test_curr_path' )
273-
274+
274275 # Then
275276 mock_subproc_popen .assert_has_calls ([
276277 call (
@@ -300,12 +301,12 @@ def test_get_branch_reference_failure(mock_subproc_popen):
300301 }
301302 process_mock .configure_mock (** attrs )
302303 mock_subproc_popen .return_value = process_mock
303-
304+
304305 # When
305306 actual_response = Git (root_dir = '/bin' )._get_branch_reference (
306307 branchname = branch ,
307308 current_path = 'test_curr_path' )
308-
309+
309310 # Then
310311 mock_subproc_popen .assert_has_calls ([
311312 call (
@@ -333,7 +334,7 @@ def test_get_current_branch_failure(mock_subproc_popen):
333334
334335 # When
335336 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' )
337338
338339 # Then
339340 mock_subproc_popen .assert_has_calls ([
@@ -368,7 +369,7 @@ def test_get_current_branch_detached_success(mock_subproc_popen):
368369 mock_subproc_popen .return_value = process_mock
369370
370371 # When
371- actual_response = Git (root_dir = '/bin' )._get_current_branch_detached (
372+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_current_branch_detached (
372373 current_path = 'test_curr_path' )
373374
374375 # Then
@@ -398,7 +399,7 @@ def test_get_current_branch_detached_failure(mock_subproc_popen):
398399
399400 # When
400401 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' )
402403
403404 # Then
404405 mock_subproc_popen .assert_has_calls ([
@@ -434,7 +435,7 @@ def test_get_upstream_branch_success(mock_subproc_popen):
434435 mock_subproc_popen .return_value = process_mock
435436
436437 # When
437- actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
438+ actual_response = Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
438439 current_path = 'test_curr_path' , branch_name = test_case [0 ])
439440
440441 # Then
@@ -466,7 +467,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
466467
467468 # When: fatal: no such branch: 'blah'
468469 with pytest .raises (Exception ) as error :
469- Git (root_dir = '/bin' ).get_upstream_branch (
470+ Git (FakeContentManager ( '/bin' ) ).get_upstream_branch (
470471 current_path = 'test_curr_path' , branch_name = 'blah' )
471472
472473 # Then
@@ -485,7 +486,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
485486 error .value )
486487
487488 # 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 (
489490 current_path = 'test_curr_path' , branch_name = 'test' )
490491
491492 # Then
@@ -502,7 +503,7 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
502503 assert None == actual_response
503504
504505 # 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 (
506507 current_path = 'test_curr_path' , branch_name = 'blah' )
507508
508509 # Then
@@ -531,7 +532,7 @@ def test_get_tag_success(mock_subproc_popen):
531532 mock_subproc_popen .return_value = process_mock
532533
533534 # When
534- actual_response = Git (root_dir = '/bin' )._get_tag (
535+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag (
535536 current_path = 'test_curr_path' , commit_sha = 'abcdefghijklmnopqrstuvwxyz01234567890123' )
536537
537538 # Then
@@ -559,14 +560,14 @@ def test_get_tag_failure(mock_subproc_popen):
559560
560561 # When
561562 with pytest .raises (Exception ) as error :
562- Git (root_dir = '/bin' )._get_tag (
563+ Git (FakeContentManager ( '/bin' ) )._get_tag (
563564 current_path = 'test_curr_path' , commit_sha = 'blah' )
564565
565566 assert "Error [fatal: Not a valid object name blah] " \
566567 "occurred while executing [git describe --tags blah] command to get nearest tag associated with branch." == str (
567568 error .value )
568569
569- actual_response = Git (root_dir = '/bin' )._get_tag (
570+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag (
570571 current_path = 'test_curr_path' , commit_sha = '01234567899999abcdefghijklmnopqrstuvwxyz' )
571572
572573 assert None == actual_response
@@ -602,7 +603,7 @@ def test_no_tags(mock_subproc_popen):
602603 mock_subproc_popen .return_value = process_mock
603604
604605 # When
605- actual_response = Git (root_dir = '/bin' )._get_tag ('/path/foo' , '768c79ad661598889f29bdf8916f4cc488f5062a' )
606+ actual_response = Git (FakeContentManager ( '/bin' ) )._get_tag ('/path/foo' , '768c79ad661598889f29bdf8916f4cc488f5062a' )
606607
607608 # Then
608609 mock_subproc_popen .assert_has_calls ([
@@ -694,7 +695,7 @@ def test_branch_success(mock_subproc_popen):
694695 }
695696
696697 # When
697- actual_response = Git (root_dir = '/bin' ).branch (
698+ actual_response = Git (FakeContentManager ( '/bin' ) ).branch (
698699 current_path = 'test_curr_path' )
699700
700701 # Then
@@ -740,7 +741,7 @@ def test_branch_failure(mock_subproc_popen):
740741 }
741742
742743 # 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' )
744745
745746 # Then
746747 mock_subproc_popen .assert_has_calls ([
@@ -828,7 +829,7 @@ def com_mock_side_effect():
828829 }
829830
830831 # When
831- actual_response = Git (root_dir = '/bin' ).branch (
832+ actual_response = Git (FakeContentManager ( '/bin' ) ).branch (
832833 current_path = 'test_curr_path' )
833834
834835 # Then
0 commit comments