Skip to content

Commit 35f0e72

Browse files
fcollonvaltelamonian
authored andcommitted
Correct tests
1 parent 4eac96f commit 35f0e72

File tree

7 files changed

+64
-44
lines changed

7 files changed

+64
-44
lines changed

jupyterlab_git/tests/test_branch.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# local lib
77
from jupyterlab_git.git import Git
8+
from .testutils import FakeContentManager
89

910

1011
def test_is_remote_branch():
@@ -18,7 +19,7 @@ def test_is_remote_branch():
1819
('refs/tags/[email protected]', 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/[email protected]'
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

jupyterlab_git/tests/test_clone.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from jupyterlab_git.git import Git, GitAuthInputWrapper
66

7+
from .testutils import FakeContentManager
8+
79

810
@patch('subprocess.Popen')
911
@patch('os.environ', {'TEST': 'test'})
@@ -18,7 +20,7 @@ def test_git_clone_success(mock_subproc_popen):
1820
mock_subproc_popen.return_value = process_mock
1921

2022
# When
21-
actual_response = Git(root_dir='/bin').clone(current_path='test_curr_path', repo_url='ghjkhjkl')
23+
actual_response = Git(FakeContentManager('/bin')).clone(current_path='test_curr_path', repo_url='ghjkhjkl')
2224

2325
# Then
2426
mock_subproc_popen.assert_has_calls([
@@ -52,7 +54,7 @@ def test_git_clone_failure_from_git(mock_subproc_popen):
5254
mock_subproc_popen.return_value = process_mock
5355

5456
# When
55-
actual_response = Git(root_dir='/bin').clone(current_path='test_curr_path', repo_url='ghjkhjkl')
57+
actual_response = Git(FakeContentManager('/bin')).clone(current_path='test_curr_path', repo_url='ghjkhjkl')
5658

5759
# Then
5860
mock_subproc_popen.assert_has_calls([
@@ -84,7 +86,7 @@ def test_git_clone_with_auth_success(mock_GitAuthInputWrapper):
8486
'username' : 'asdf',
8587
'password' : 'qwerty'
8688
}
87-
actual_response = Git(root_dir='/bin').clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
89+
actual_response = Git(FakeContentManager('/bin')).clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
8890

8991
# Then
9092
mock_GitAuthInputWrapper.assert_has_calls([
@@ -121,7 +123,7 @@ def test_git_clone_with_auth_wrong_repo_url_failure_from_git(mock_GitAuthInputWr
121123
'username' : 'asdf',
122124
'password' : 'qwerty'
123125
}
124-
actual_response = Git(root_dir='/bin').clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
126+
actual_response = Git(FakeContentManager('/bin')).clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
125127

126128
# Then
127129
mock_GitAuthInputWrapper.assert_has_calls([
@@ -158,7 +160,7 @@ def test_git_clone_with_auth_auth_failure_from_git(mock_GitAuthInputWrapper):
158160
'username' : 'asdf',
159161
'password' : 'qwerty'
160162
}
161-
actual_response = Git(root_dir='/bin').clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
163+
actual_response = Git(FakeContentManager('/bin')).clone(current_path='test_curr_path', repo_url='ghjkhjkl', auth=auth)
162164

163165
# Then
164166
mock_GitAuthInputWrapper.assert_has_calls([

jupyterlab_git/tests/test_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from jupyterlab_git.git import Git
88
from jupyterlab_git.handlers import GitConfigHandler
99

10+
from .testutils import FakeContentManager
11+
1012

1113
@patch("jupyterlab_git.handlers.GitConfigHandler.__init__", Mock(return_value=None))
1214
@patch(
1315
"jupyterlab_git.handlers.GitConfigHandler.get_json_body",
1416
Mock(return_value={"path": "test_path"}),
1517
)
16-
@patch("jupyterlab_git.handlers.GitConfigHandler.git", Git("/bin"))
18+
@patch("jupyterlab_git.handlers.GitConfigHandler.git", Git(FakeContentManager("/bin")))
1719
@patch("jupyterlab_git.handlers.GitConfigHandler.finish")
1820
@patch("subprocess.Popen")
1921
def test_git_get_config_success(popen, finish):
@@ -69,7 +71,7 @@ def test_git_get_config_success(popen, finish):
6971
}
7072
),
7173
)
72-
@patch("jupyterlab_git.handlers.GitConfigHandler.git", Git("/bin"))
74+
@patch("jupyterlab_git.handlers.GitConfigHandler.git", Git(FakeContentManager('/bin')))
7375
@patch("jupyterlab_git.handlers.GitConfigHandler.finish")
7476
@patch("subprocess.Popen")
7577
def test_git_set_config_success(popen, finish):

jupyterlab_git/tests/test_detailed_log.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# local lib
66
from jupyterlab_git.git import Git
77

8+
from .testutils import FakeContentManager
9+
810

911
@patch('subprocess.Popen')
1012
def test_detailed_log(mock_subproc_popen):
@@ -62,7 +64,7 @@ def test_detailed_log(mock_subproc_popen):
6264
}
6365

6466
# When
65-
actual_response = Git(root_dir='/bin').detailed_log(
67+
actual_response = Git(FakeContentManager('/bin')).detailed_log(
6668
selected_hash='f29660a2472e24164906af8653babeb48e4bf2ab',
6769
current_path='test_curr_path')
6870

jupyterlab_git/tests/test_diff.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
from jupyterlab_git.git import Git
99

10+
from .testutils import FakeContentManager
11+
1012

1113
def test_changed_files_invalid_input():
1214
with pytest.raises(HTTPError):
13-
actual_response = Git(root_dir="/bin").changed_files(
15+
actual_response = Git(FakeContentManager('/bin')).changed_files(
1416
base="64950a634cd11d1a01ddfedaeffed67b531cb11e"
1517
)
1618

@@ -21,7 +23,7 @@ def test_changed_files_single_commit(mock_call):
2123
mock_call.return_value = b"file1.ipynb\nfile2.py"
2224

2325
# When
24-
actual_response = Git(root_dir="/bin").changed_files(
26+
actual_response = Git(FakeContentManager('/bin')).changed_files(
2527
single_commit="64950a634cd11d1a01ddfedaeffed67b531cb11e"
2628
)
2729

@@ -40,7 +42,7 @@ def test_changed_files_working_tree(mock_call):
4042
mock_call.return_value = b"file1.ipynb\nfile2.py"
4143

4244
# When
43-
actual_response = Git(root_dir="/bin").changed_files(base="WORKING", remote="HEAD")
45+
actual_response = Git(FakeContentManager('/bin')).changed_files(base="WORKING", remote="HEAD")
4446

4547
# Then
4648
mock_call.assert_called_with(
@@ -55,7 +57,7 @@ def test_changed_files_index(mock_call):
5557
mock_call.return_value = b"file1.ipynb\nfile2.py"
5658

5759
# When
58-
actual_response = Git(root_dir="/bin").changed_files(base="INDEX", remote="HEAD")
60+
actual_response = Git(FakeContentManager('/bin')).changed_files(base="INDEX", remote="HEAD")
5961

6062
# Then
6163
mock_call.assert_called_with(
@@ -70,7 +72,7 @@ def test_changed_files_two_commits(mock_call):
7072
mock_call.return_value = b"file1.ipynb\nfile2.py"
7173

7274
# When
73-
actual_response = Git(root_dir="/bin").changed_files(
75+
actual_response = Git(FakeContentManager('/bin')).changed_files(
7476
base="HEAD", remote="origin/HEAD"
7577
)
7678

@@ -87,7 +89,7 @@ def test_changed_files_git_diff_error(mock_call):
8789
mock_call.side_effect = CalledProcessError(128, "cmd", b"error message")
8890

8991
# When
90-
actual_response = Git(root_dir="/bin").changed_files(
92+
actual_response = Git(FakeContentManager('/bin')).changed_files(
9193
base="HEAD", remote="origin/HEAD"
9294
)
9395

0 commit comments

Comments
 (0)