def test_clone_fresh_false(mock_get_gist, mock_requests_get): with temp_directory() as dir: mock_get_gist.return_value = FAKE_GIST get1, get2 = mock.Mock(), mock.Mock() get1.content, get2.content = b'{"notebook": "content"}', b"environment content" mock_requests_get.side_effect = [get1, get2] clone('aakashns/metrics-example', version='3', fresh=False) os.chdir(dir) mock_get_gist.assert_called_with('aakashns/metrics-example', '3', False) mock_requests_get.assert_has_calls([ call("https://storage.com/slug1"), call("https://storage.com/slug2") ]) # Check that directory was not created assert "metrics-example" not in os.listdir() # Check that files were downloaded assert set( os.listdir()) == {"environment.yml", "metrics-example.ipynb"}
def test_clone(mock_get_gist, mock_requests_get): with temp_directory() as dir: mock_get_gist.return_value = FAKE_GIST get1, get2 = mock.Mock(), mock.Mock() get1.content, get2.content = b"notebook content", b"environment content" mock_requests_get.side_effect = [get1, get2] clone('aakashns/metrics-example', version='3') os.chdir(dir) mock_get_gist.assert_called_with('aakashns/metrics-example', '3', True) mock_requests_get.assert_has_calls([ call("https://storage.com/slug1"), call("https://storage.com/slug2") ]) # Check that folder was created assert os.listdir() == ["metrics-example"] # Check that files were downloaded assert set(os.listdir("metrics-example")) == { ".jovianrc", "environment.yml", "metrics-example.ipynb" }
def exec_clone(ctx, notebook, version, no_outputs, overwrite): """Clone a notebook hosted on Jovian: $ jovian clone aakashns/jovian-tutorial Or clone a specific version of notebook: $ jovian clone aakashns/jovian-tutorial -v 10 """ clone(slug=notebook, version=version, include_outputs=not no_outputs, overwrite=overwrite)
def test_clone_overwrite(mock_get_gist, mock_requests_get): with temp_directory() as dir: mock_get_gist.return_value = FAKE_GIST get1, get2 = mock.Mock(), mock.Mock() get1.content, get2.content = b'{"notebook": "content"}', b"environment content" mock_requests_get.side_effect = [get1, get2] * 2 clone('aakashns/metrics-example', version='3') os.chdir(dir) # Check that directory was created assert "metrics-example" in os.listdir() clone('aakashns/metrics-example', version='3', overwrite=True) os.chdir(dir) # Check that another directory was not created assert os.listdir() == ["metrics-example"]
def test_clone_multiple(mock_get_gist, mock_requests_get): with temp_directory() as dir: mock_get_gist.return_value = FAKE_GIST get1, get2 = mock.Mock(), mock.Mock() get1.content, get2.content = b'{"notebook": "content"}', b"environment content" mock_requests_get.side_effect = [get1, get2] * 3 # first call clone('aakashns/metrics-example', version='3') os.chdir(dir) # second call clone('aakashns/metrics-example', version='3') os.chdir(dir) # third call clone('aakashns/metrics-example', version='3') os.chdir(dir) mock_get_gist.assert_called_with('aakashns/metrics-example', '3', True) mock_requests_get.assert_has_calls([ call("https://storage.com/slug1"), call("https://storage.com/slug2") ] * 3) # Check that multiple folders were created assert set(os.listdir()) == { "metrics-example", "metrics-example-1", "metrics-example-2" }
def exec_clone(slug): clone(slug)