Beispiel #1
0
def test_create_environment_folder_size_warning(config_mock, mocker, tmpdir):
    os_pexists_mock = mocker.patch("os.path.exists", side_effect=[False])
    mocker.patch("os.makedirs")
    mocker.patch("os.chmod")
    sem_file_creation_mock = mocker.patch(
        "commands.experiment.common.Path.touch")
    mocker.patch("shutil.copy2")
    mocker.patch("commands.experiment.common.copy_tree")
    confirm_mock = mocker.patch('commands.experiment.common.click.confirm')

    sfl_size = 1024
    script_folder_location = tmpdir.mkdir('sfl')
    sfl_file = script_folder_location.join('file.bin')
    with open(sfl_file, "wb") as f:
        f.write(os.urandom(sfl_size))

    create_environment(EXPERIMENT_NAME,
                       SCRIPT_LOCATION,
                       folder_location=script_folder_location,
                       show_folder_size_warning=True,
                       max_folder_size_in_bytes=sfl_size / 2)

    assert sem_file_creation_mock.call_count == 1, "semaphore file wasn't created"
    assert os_pexists_mock.call_count == 1, "existence of an experiment's folder wasn't checked"
    assert confirm_mock.call_count == 1
Beispiel #2
0
def test_create_environment_lack_of_home_folder_error(config_mock, mocker):
    os_pexists_mock = mocker.patch("os.path.exists", side_effect=[False])
    os_mkdirs_mock = mocker.patch("os.makedirs", side_effect=RuntimeError())
    sh_copy_mock = mocker.patch("shutil.copy2")

    with pytest.raises(SubmitExperimentError):
        create_environment(EXPERIMENT_NAME, SCRIPT_LOCATION, EXPERIMENT_FOLDER)

    assert os_pexists_mock.call_count == 1, "existence of an experiment's folder wasn't checked"
    assert os_mkdirs_mock.call_count == 1, "experiment's folder was created"
    assert sh_copy_mock.call_count == 0, "files were copied"
Beispiel #3
0
def test_create_environment_makedir_error(config_mock, mocker):
    os_pexists_mock = mocker.patch("os.path.exists", side_effect=[False])
    mocker.patch("os.makedirs", side_effect=Exception("Test exception"))
    sh_copy_mock = mocker.patch("shutil.copy2")
    copytree_mock = mocker.patch("commands.experiment.common.copy_tree")

    with pytest.raises(SubmitExperimentError):
        create_environment(EXPERIMENT_NAME, SCRIPT_LOCATION, EXPERIMENT_FOLDER)

    assert os_pexists_mock.call_count == 1, "existence of an experiment's folder wasn't checked"
    assert copytree_mock.call_count == 0, "additional folder was copied"
    assert sh_copy_mock.call_count == 0, "files were copied"
Beispiel #4
0
def test_create_environment_success(config_mock, mocker):
    os_pexists_mock = mocker.patch("os.path.exists", side_effect=[False])
    mocker.patch("os.makedirs")
    mocker.patch("os.chmod")
    sem_file_creation_mock = mocker.patch("commands.experiment.common.Path.touch")
    sh_copy_mock = mocker.patch("shutil.copy2")
    sh_copytree_mock = mocker.patch("commands.experiment.common.copy_tree")

    experiment_path = create_environment(EXPERIMENT_NAME, SCRIPT_LOCATION, EXPERIMENT_FOLDER)

    assert sem_file_creation_mock.call_count == 1, "semaphore file wasn't created"
    assert os_pexists_mock.call_count == 1, "existence of an experiment's folder wasn't checked"
    assert sh_copytree_mock.call_count == 1, "additional folder wan't copied"
    assert sh_copy_mock.call_count == 1, "files weren't copied"
    assert experiment_path == FAKE_CLI_EXPERIMENT_PATH