Beispiel #1
0
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_attach_file_raises_error(capsys):
    with temp_directory():
        _attach_file('tempfile.txt', 'fake_gist_slug', version=2)

        expected_result = "[jovian] Error: [Errno 2] No such file or directory: 'tempfile.txt' (tempfile.txt)"
        captured = capsys.readouterr()
        assert captured.err.strip() == expected_result
Beispiel #3
0
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"
        }
Beispiel #4
0
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"
        }
Beispiel #5
0
def test_get_rcdata():
    with temp_directory():
        expected_result = {"notebooks": {}}
        assert get_rcdata() == expected_result

    with fake_rc():
        assert get_rcdata() == _data
Beispiel #6
0
def test_attach_file(mock_upload_file):
    with temp_directory():
        os.system('touch tempfile.txt')

        _attach_file('tempfile.txt', 'fake_gist_slug', version=2)
        mock_upload_file.assert_called_with('fake_gist_slug',
                                            ('tempfile.txt', ANY), ANY, 2,
                                            False)
Beispiel #7
0
def fake_rcdata():
    with temp_directory():
        data = dedent("""
                {
                    "notebooks": {
                        "metrics-example.ipynb": {
                        "slug": "aakashns/metrics-example"
                        },
                        "jovian-tutorial.ipynb" : {
                        "slug": "aakashns/jovian-tutorial"
                        }
                    }
                }""").strip()

        with open('.jovianrc', 'w') as f:
            f.write(data)

        yield
Beispiel #8
0
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_upload_conda_env(mock_upload_file, mock_get_platform,
                          mock_get_conda_env_name, mock_read_conda_env):
    with temp_directory():
        mock_read_conda_env.return_value = ENV_STR

        with open('environment-linux.yml', 'w') as f:
            f.write(ENV_STR)

        upload_conda_env('fake_gist_slug', version=2)

        calls = [
            mock.call(gist_slug='fake_gist_slug',
                      file=('environment.yml', ENV_STR),
                      version=2),
            mock.call(gist_slug='fake_gist_slug',
                      file=('environment-linux.yml', ANY),
                      version=2),
            mock.call(gist_slug='fake_gist_slug',
                      file=('environment-macos.yml', ENV_STR),
                      version=2)
        ]

        mock_upload_file.assert_has_calls(calls)
Beispiel #10
0
def test_save_rcdata(data, expected_result):
    with temp_directory():
        save_rcdata(data=data)

        with open(RC_FILENAME, 'r') as f:
            assert json.load(f) == expected_result
Beispiel #11
0
def test_rcfile_does_not_exist():
    with temp_directory():
        assert not rcfile_exists()
Beispiel #12
0
def fake_rc():
    with temp_directory():
        with open(RC_FILENAME, 'w') as f:
            json.dump(_data, f, indent=2)

        yield
def test_identify_env_file_no_environment_file():
    with temp_directory():
        assert identify_env_file(env_fname=None) == None
Beispiel #14
0
def test_is_not_git():
    with temp_directory():
        assert not is_git()