Ejemplo n.º 1
0
def test_request_env_name(prompt_ret_val, extract_env_name_ret_val,
                          expected_result):
    with fake_envfile():
        with mock.patch("jovian.utils.envfile.click.prompt", return_value=prompt_ret_val), \
                mock.patch("jovian.utils.envfile.extract_env_name", return_value=extract_env_name_ret_val):
            assert request_env_name(
                env_name=None, env_fname='environment.yml') == expected_result
Ejemplo n.º 2
0
def test_write_env_name(data, name):
    with fake_envfile():
        dump_environment_to_yaml_file('test.yml', data)

        write_env_name(name, 'test.yml')

        assert get_environment_dict('test.yml')['name'] == name
Ejemplo n.º 3
0
def test_run_command(mock_popen, side_effect, calls):
    with fake_envfile():
        mock_popen().communicate.side_effect = side_effect
        run_command(
            'conda env update --file environment.yml --name environment-name',
            'environment.yml', ['mixpanel=1.11.0', 'sigmasix=1.91.0'])

        mock_popen.assert_has_calls(calls)
Ejemplo n.º 4
0
def test_activate_conda_not_found(mock_get_conda_bin, capsys):
    with fake_envfile():
        assert activate('environment.yml') == False

        expected_result = """[jovian] Error: Anaconda binary not found. Please make sure the "conda" command is in your system PATH or the environment variable $CONDA_EXE points to the anaconda binary"""

        captured = capsys.readouterr()
        assert expected_result.strip() in captured.err.strip()
Ejemplo n.º 5
0
def test_activate_env_name_none(mock_get_conda_bin, mock_extract_env_name,
                                capsys):
    with fake_envfile():
        activate('environment.yml')

        expected_result = """[jovian] Environment name not provided/detected. Skipping.."""

        captured = capsys.readouterr()
        assert expected_result.strip() in captured.out.strip()
Ejemplo n.º 6
0
def test_activate_env_fname_none(mock_get_conda_bin, mock_identify_env_file,
                                 capsys):
    with fake_envfile():
        assert activate('environment.yml') == False

        expected_result = """[jovian] Error: Failed to detect a conda environment YML file. Skipping.."""

        captured = capsys.readouterr()
        assert expected_result.strip() in captured.err.strip()
Ejemplo n.º 7
0
def test_install_env_name_none(mock_request_env_name, mock_get_conda_bin,
                               capsys):
    with fake_envfile():
        install('environment.yml')

        expected_result = dedent("""
            [jovian] Detected conda environment file: environment.yml

            [jovian] Environment name not provided/detected. Skipping..
            """).strip()
        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result
Ejemplo n.º 8
0
def test_get_environment_dict_raises_exception_invalid_file():
    with fake_envfile():
        with open('invalid-yaml-file.yml', 'w') as f:
            f.write(
                dedent("""
            ok:
                sub1: sub1
                ][
            hello:
                world: world
                some: other
            """))
        assert get_environment_dict('invalid-yaml-file.yml') == {}
Ejemplo n.º 9
0
def test_activate(mock_get_conda_bin, capsys):
    with fake_envfile():
        activate('environment.yml')

        expected_result = dedent("""
            [jovian] Detected conda environment file: environment.yml

            [jovian] Copy and execute the following command (try "source activate" if "conda activate doesn't work" )
                conda activate test-env
        """).strip()

        captured = capsys.readouterr()
        assert expected_result.strip() in captured.out.strip()
Ejemplo n.º 10
0
def test_install(mock_run_command, mock_request_env_name, mock_get_conda_bin):
    with fake_envfile():
        mock_run_command.return_value = True

        install('environment.yml')

        mock_run_command.assert_called_with(
            command=
            'conda env update --file "environment.yml" --name "test-env"',
            env_fname='environment.yml',
            packages=[
                'mixpanel=1.11.0', 'sigmasix=1.91.0', 'sqlite', 'six==1.11.0',
                'sqlite==2.0.0'
            ],
            run=1)
Ejemplo n.º 11
0
def test_dump_environment_to_yaml_file_normal():
    with fake_envfile():
        data = {
            'channels': ['defaults'],
            'dependencies': [
                'mixpanel=1.11.0', 'sigmasix=1.91.0', 'sqlite', {
                    'pip': ['six==1.11.0', 'sqlite==2.0.0']
                }
            ],
            'name':
            'test-env',
            'prefix':
            '/home/admin/anaconda3/envs/test-env'
        }
        dump_environment_to_yaml_file('test.yml', data)

        assert get_environment_dict('test.yml') == data
Ejemplo n.º 12
0
def test_get_environment_dict():
    with fake_envfile():
        expected_result = {
            'prefix':
            '/home/admin/anaconda3/envs/test-env',
            'dependencies': [
                'mixpanel=1.11.0', 'sigmasix=1.91.0', 'sqlite', {
                    'pip': ['six==1.11.0', 'sqlite==2.0.0']
                }
            ],
            'channels': ['defaults'],
            'name':
            'test-env'
        }
        environment = get_environment_dict(env_fname='environment.yml')

        assert environment == expected_result
Ejemplo n.º 13
0
def test_get_environment_dict_non_existent_file():
    with fake_envfile():
        expected = {
            'prefix':
            '/home/admin/anaconda3/envs/test-env',
            'dependencies': [
                'mixpanel=1.11.0', 'sigmasix=1.91.0', 'sqlite', {
                    'pip': ['six==1.11.0', 'sqlite==2.0.0']
                }
            ],
            'channels': ['defaults'],
            'name':
            'test-env'
        }
        environment = get_environment_dict(env_fname='environment.yml')

        with pytest.raises(FileNotFoundError):
            get_environment_dict(env_fname='non-existent-file.yml')
Ejemplo n.º 14
0
def test_sanitize_envfile():
    with fake_envfile():
        packages = ['six==1.11.0', 'sigmasix=1.91.0']
        sanitize_envfile('environment.yml', packages)

        expected_result = {
            'channels': ['defaults'],
            'dependencies':
            ['mixpanel=1.11.0', 'sqlite', {
                'pip': ['sqlite==2.0.0']
            }],
            'name':
            'test-env',
            'prefix':
            '/home/admin/anaconda3/envs/test-env'
        }

        assert get_environment_dict('environment.yml') == expected_result
Ejemplo n.º 15
0
def test_install_unsuccessful(mock_run_command, mock_request_env_name,
                              mock_get_conda_bin, capsys):
    with fake_envfile():
        mock_run_command.return_value = False

        install('environment.yml')

        expected_result = dedent("""
                            [jovian] Detected conda environment file: environment.yml

                            [jovian] Some pip packages failed to install.
                            [jovian] 
                            #
                            # To activate this environment, use
                            #
                            #     $ conda activate test-env
                            #
                            # To deactivate an active environment, use
                            #
                            #     $ conda deactivate
                        """).strip()

        captured = capsys.readouterr()
        assert captured.out.strip() == expected_result
Ejemplo n.º 16
0
def test_extract(func, env_fname, expected_result):
    with fake_envfile():
        assert func(env_fname) == expected_result

        with pytest.raises(FileNotFoundError):
            func('non-existent-file.yml')
Ejemplo n.º 17
0
def test_check_error(error_str, expected_result):
    with fake_envfile():
        packages = extract_env_packages(env_fname='environment.yml')
        assert check_error(error_str=error_str,
                           packages=packages) == expected_result
Ejemplo n.º 18
0
def test_extract_package_from_line(line, expected_result):
    with fake_envfile():
        packages = extract_env_packages(env_fname='environment.yml')
        assert extract_package_from_line(line=line,
                                         packages=packages) == expected_result
Ejemplo n.º 19
0
def test_identify_env_file_exists():
    with fake_envfile():
        assert identify_env_file(env_fname=None) == 'environment.yml'
Ejemplo n.º 20
0
def test_remove_packages(dependencies, expected_result):
    with fake_envfile():
        packages = extract_env_packages(env_fname='environment.yml')
        assert remove_packages(dependencies, packages) == expected_result