|
| 1 | +# python lib |
| 2 | +from subprocess import PIPE |
| 3 | +from mock import patch, call, Mock |
| 4 | + |
| 5 | +# local lib |
| 6 | +from jupyterlab_git.git import Git |
| 7 | + |
| 8 | + |
| 9 | +@patch('subprocess.Popen') |
| 10 | +def test_detailed_log(mock_subproc_popen): |
| 11 | + # Given |
| 12 | + process_output = [ |
| 13 | + 'f29660a (HEAD, origin/feature) Commit message', |
| 14 | + '10 3 notebook_without_spaces.ipynb', |
| 15 | + '11 4 Notebook with spaces.ipynb', |
| 16 | + '12 5 path/notebook_without_spaces.ipynb', |
| 17 | + '13 6 path/Notebook with spaces.ipynb', |
| 18 | + ' notebook_without_spaces.ipynb | 13 ++++++++---', |
| 19 | + ' Notebook with spaces.ipynb | 15 +++++++++----', |
| 20 | + ' path/notebook_without_spaces.ipynb | 17 ++++++++++-----', |
| 21 | + ' path/Notebook with spaces.ipynb | 19 +++++++++++------', |
| 22 | + ' 4 files changed, 46 insertions(+), 18 deletions(-)' |
| 23 | + ] |
| 24 | + process_mock = Mock(returncode=0) |
| 25 | + process_mock.communicate.side_effect = [ |
| 26 | + ('\n'.join(process_output).encode('utf-8'), ''.encode('utf-8')), |
| 27 | + ] |
| 28 | + mock_subproc_popen.return_value = process_mock |
| 29 | + |
| 30 | + expected_response = { |
| 31 | + 'code': 0, |
| 32 | + 'modified_file_note': ' 4 files changed, 46 insertions(+), 18 deletions(-)', |
| 33 | + 'modified_files_count': '4', |
| 34 | + 'number_of_insertions': '46', |
| 35 | + 'number_of_deletions': '18', |
| 36 | + 'modified_files': [ |
| 37 | + { |
| 38 | + 'modified_file_path': 'notebook_without_spaces.ipynb', |
| 39 | + 'modified_file_name': 'notebook_without_spaces.ipynb', |
| 40 | + 'insertion': '10', |
| 41 | + 'deletion': '3' |
| 42 | + }, |
| 43 | + { |
| 44 | + 'modified_file_path': 'Notebook with spaces.ipynb', |
| 45 | + 'modified_file_name': 'Notebook with spaces.ipynb', |
| 46 | + 'insertion': '11', |
| 47 | + 'deletion': '4' |
| 48 | + }, |
| 49 | + { |
| 50 | + 'modified_file_path': 'path/notebook_without_spaces.ipynb', |
| 51 | + 'modified_file_name': 'notebook_without_spaces.ipynb', |
| 52 | + 'insertion': '12', |
| 53 | + 'deletion': '5' |
| 54 | + }, |
| 55 | + { |
| 56 | + 'modified_file_path': 'path/Notebook with spaces.ipynb', |
| 57 | + 'modified_file_name': 'Notebook with spaces.ipynb', |
| 58 | + 'insertion': '13', |
| 59 | + 'deletion': '6' |
| 60 | + } |
| 61 | + ] |
| 62 | + } |
| 63 | + |
| 64 | + # When |
| 65 | + actual_response = Git(root_dir='/bin').detailed_log( |
| 66 | + selected_hash='f29660a2472e24164906af8653babeb48e4bf2ab', |
| 67 | + current_path='test_curr_path') |
| 68 | + |
| 69 | + # Then |
| 70 | + mock_subproc_popen.assert_has_calls([ |
| 71 | + call( |
| 72 | + ['git', 'log', '-1', '--stat', '--numstat', '--oneline', 'f29660a2472e24164906af8653babeb48e4bf2ab'], |
| 73 | + stdout=PIPE, |
| 74 | + stderr=PIPE, |
| 75 | + cwd='/bin/test_curr_path' |
| 76 | + ), |
| 77 | + call().communicate(), |
| 78 | + ], any_order=False) |
| 79 | + |
| 80 | + assert expected_response == actual_response |
0 commit comments