def test_commit_deprecated_args(mock_in_script, mock_in_notebook, commit_kwargs, expected_result, capsys): commit(message="this is the first commit", **commit_kwargs) captured = capsys.readouterr() assert captured.err.strip() == \ expected_result.strip() + """\n[jovian] Error: Failed to detect Jupyter notebook or Python script. Skipping.."""
def test_commit_file_does_not_exist( mock_in_script, mock_in_notebook, mock_parse_filename, mock_os_path_exists, capsys): commit('initial commit') expected_result = """[jovian] Error: The detected/provided file "file" does not exist. Please provide the correct notebook filename as the "filename" argument to "jovian.commit".""" captured = capsys.readouterr() assert captured.err.strip() == expected_result.strip()
def test_commit_kaggle_notebook_project_none( mock_perform_kaggle_commit, mock_in_notebook, mock_parse_filename, mock_save_notebook, capsys): commit() expected_result_err = dedent(""" [jovian] Error: Please provide the project argument e.g. jovian.commit(project='my-project')""") captured = capsys.readouterr() assert captured.err.strip() == expected_result_err.strip()
def test_commit_kaggle_notebook( mock_perform_kaggle_commit, mock_in_notebook, mock_parse_filename, mock_save_notebook, capsys): commit(project="sample-notebook") expected_result_out = dedent(""" [jovian] Attempting to save notebook.. [jovian] Detected Kaggle notebook...""") captured = capsys.readouterr() assert captured.out.strip() == expected_result_out.strip()
def test_commit_in_notebook_filename_none( mock_in_script, mock_in_notebook, mock_parse_filename, mock_save_notebook, capsys): commit('initial commit') expected_result_out = dedent(""" [jovian] Attempting to save notebook..""") expected_result_err = dedent(""" [jovian] Error: Failed to detect notebook filename. Please provide the correct notebook filename as the "filename" argument to "jovian.commit".""") captured = capsys.readouterr() assert captured.out.strip() == expected_result_out.strip() assert captured.err.strip() == expected_result_err.strip()
def submit(assignment=None, notebook_url=None, **kwargs): """ Performs jovian.commit and makes a assignment submission with the uploaded notebook. """ if not assignment: log("Please provide assignment name", error=True) return filename = _parse_filename(kwargs.get('filename')) if filename == '__notebook_source__.ipynb': log("""jovian.submit does not support kaggle notebooks directly. Please make a commit first, copy the notebook URL and pass it to jovian.submit. eg. jovian.submit(assignment="zero-to-pandas-a1", notebook_url="https://jovian.ai/PrajwalPrashanth/assignment")""", error=True) return post_url = POST_API.format(assignment) nb_url = notebook_url if notebook_url else commit(**kwargs) if nb_url: data = { 'assignment_url': nb_url } auth_headers = _h() log('Submitting assignment..') res = post(url=_u(post_url), json=data, headers=auth_headers) if res.status_code == 200: data = res.json()['data'] course_slug = data.get('course_slug') assignment_slug = data.get('section_slug') assignment_page_url = ASSIGNMENT_PAGE_URL.format(course_slug, assignment_slug) log('Verify your submission at {}'.format(urljoin(read_webapp_url(), assignment_page_url))) else: log('Jovian submit failed. {}'.format(pretty(res)), error=True)
def test_commit(mock_in_script, mock_in_notebook, mock_parse_filename, mock_os_path_exists, mock_parse_project, mock_create_gist_simple, mock_read_webapp_url, mock_set_notebook_slug, mock_capture_environment, mock_attach_files, mock_perform_git_commit, mock_attach_records, capsys): returned_value = commit('initial commit', files=['file1', 'file2', 'file3'], privacy='secret', environment='conda', outputs=['model.h5', 'gen.csv']) mock_create_gist_simple.assert_called_with('file', 'fake_project_id', 'secret', 'fake_project_title', 'initial commit') mock_set_notebook_slug.assert_called_with('file', 'fake_gist_slug') mock_capture_environment.assert_called_with('conda', 'fake_gist_slug', 2) _attach_files_calls = [ call(['file1', 'file2', 'file3'], 'fake_gist_slug', 2, exclude_files='file'), call(['model.h5', 'gen.csv'], 'fake_gist_slug', 2, output=True) ] mock_attach_files.assert_has_calls(_attach_files_calls) mock_perform_git_commit.assert_called_with('file', False, 'initial commit') mock_attach_records.assert_called_with('fake_gist_slug', 2) expected_common_result = "[jovian] Committed successfully! https://staging.jovian.ml/rohit/demo-notebook" captured = capsys.readouterr() assert captured.out.strip() == expected_common_result.strip() assert returned_value == "https://staging.jovian.ml/rohit/demo-notebook"