Esempio n. 1
0
 def prompt(self) -> None:
     file_url_or_path: str = click.prompt(PROMPT_FILES_BASE_PATH,
                                          type=click.Path())
     if not toolkit.is_cloud_file_url(file_url_or_path):
         file_url_or_path = toolkit.get_relative_path_from_config_file_to_base_path(
             self.context_root_dir, file_url_or_path)
     self.base_path = file_url_or_path
def test_get_relative_path_from_config_file_to_data_base_file_path_from_within_ge_directory_and_relative_data_path(
        monkeypatch, simulated_project_directories):
    """
    This test simulates using the CLI from within the great_expectations
    directory.

    /projects/pipeline1/great_expectations
    /projects/data/pipeline1

    cwd: /projects/pipeline1/great_expectations
    data: ../../data/pipeline1
    expected results in yaml: ../../data/pipeline1
    """
    ge_dir, data_dir = simulated_project_directories
    monkeypatch.chdir(ge_dir)
    assert str(os.path.abspath(os.path.curdir)) == str(ge_dir)

    obs = get_relative_path_from_config_file_to_base_path(
        ge_dir, os.path.join("..", "..", "data", "pipeline1"))
    assert obs == os.path.join("..", "..", "data", "pipeline1")
def test_get_relative_path_from_config_file_to_data_base_file_path_from_misc_directory_and_relative_data_path(
        monkeypatch, misc_directory, simulated_project_directories):
    """
    This test simulates using the CLI with the --config flag operating from a
    random directory

    /projects/pipeline1/great_expectations
    /projects/data/pipeline1
    /tmp_path/misc

    cwd: /tmp_path/random
    data: ../../projects/data/pipeline1
    expected results in yaml: ../../data/pipeline1
    """
    ge_dir, data_dir = simulated_project_directories
    monkeypatch.chdir(misc_directory)
    assert str(os.path.abspath(os.path.curdir)) == str(misc_directory)

    obs = get_relative_path_from_config_file_to_base_path(
        ge_dir, os.path.join("..", "..", "projects", "data", "pipeline1"))
    assert obs == os.path.join("..", "..", "data", "pipeline1")
def test_get_relative_path_from_config_file_to_data_base_file_path_from_adjacent_directory_and_absolute_data_path(
        monkeypatch, simulated_project_directories):
    """
    This test simulates using the CLI from a directory containing the
    great_expectations directory and using an absolute path.

    /projects/pipeline1/great_expectations
    /projects/data/pipeline1

    cwd: /projects/pipeline1
    data: /projects/data/pipeline1
    expected results in yaml: ../../data/pipeline1
    """
    ge_dir, data_dir = simulated_project_directories
    adjacent_dir = os.path.dirname(ge_dir)
    monkeypatch.chdir(adjacent_dir)
    assert str(os.path.abspath(os.path.curdir)) == str(adjacent_dir)

    absolute_path = os.path.abspath(os.path.join("..", "data", "pipeline1"))
    obs = get_relative_path_from_config_file_to_base_path(
        ge_dir, absolute_path)
    assert obs == os.path.join("..", "..", "data", "pipeline1")