Skip to content

Commit

Permalink
updates tests for gx class and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BWMac committed Nov 14, 2023
1 parent 2b8ffec commit d30a081
Showing 1 changed file with 66 additions and 15 deletions.
81 changes: 66 additions & 15 deletions tests/test_gx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@


def test_that_an_initialized_runner_has_the_attributes_it_should(syn):
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=good_dataset_path)
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
assert test_runner.gx_project_dir == "./great_expectations"
assert test_runner.syn == syn
assert test_runner.dataset_path == good_dataset_path
assert test_runner.expectation_suite_name == "metabolomics"
assert test_runner.upload_folder == "test_folder"
assert isinstance(test_runner.context, FileDataContext)
assert (
test_runner.validations_relative_path
Expand All @@ -34,20 +40,35 @@ def test_that_an_initialized_runner_has_the_attributes_it_should(syn):
def test_check_if_expectation_suite_exists_returns_false_when_the_expectation_suite_does_not_exist(
syn,
):
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=bad_dataset_path)
assert test_runner.check_if_expectation_suite_exists() is False
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=bad_dataset_path,
dataset_name="not_supported_dataset",
upload_folder="test_folder",
)
assert test_runner._check_if_expectation_suite_exists() is False


def test_check_if_expectation_suite_exists_returns_true_when_the_expectation_suite_exists(
syn,
):
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=good_dataset_path)
assert test_runner.check_if_expectation_suite_exists() is True
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
assert test_runner._check_if_expectation_suite_exists() is True


def test_get_results_path(syn):
expected = "./great_expectations/gx/uncommitted/data_docs/local_site/validations/test/path/to/to.html"
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=good_dataset_path)
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
mocked_checkpoint_result = mock.create_autospec(CheckpointResult)
mocked_validation_result_identifier = mock.create_autospec(
ValidationResultIdentifier(
Expand Down Expand Up @@ -77,25 +98,55 @@ def test_get_results_path(syn):

def test_upload_results_file_to_synapse(syn):
with patch.object(syn, "store") as patch_syn_store:
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=good_dataset_path)
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
test_runner._upload_results_file_to_synapse("test_path")
patch_syn_store.assert_called_once_with(
File(
path="test_path",
parent=test_runner.synapse_folder_dict[
test_runner.expectation_suite_name
],
)
File(path="test_path", parent=test_runner.upload_folder)
)


def test_that_run_completes_successfully(syn):
test_runner = GreatExpectationsRunner(syn=syn, dataset_path=good_dataset_path)
def test_that_run_completes_successfully_when_check_if_expectation_suite_exists_is_true(
syn,
):
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
with patch.object(
test_runner, "_check_if_expectation_suite_exists", return_value=True
), patch.object(
test_runner, "_get_results_path", return_value="test_path"
) as patch_get_results_path, patch.object(
test_runner, "_upload_results_file_to_synapse", return_value=None
) as patch_upload_results_file_to_synapse:
test_runner.run()
patch_get_results_path.assert_called_once()
patch_upload_results_file_to_synapse.assert_called_once_with("test_path")


def test_that_run_does_not_complete_when_check_if_expectation_suite_exists_is_false(
syn,
):
test_runner = GreatExpectationsRunner(
syn=syn,
dataset_path=good_dataset_path,
dataset_name="metabolomics",
upload_folder="test_folder",
)
with patch.object(
test_runner, "_check_if_expectation_suite_exists", return_value=False
), patch.object(
test_runner, "_get_results_path", return_value="test_path"
) as patch_get_results_path, patch.object(
test_runner, "_upload_results_file_to_synapse", return_value=None
) as patch_upload_results_file_to_synapse:
test_runner.run()
patch_get_results_path.assert_not_called()
patch_upload_results_file_to_synapse.assert_not_called()

0 comments on commit d30a081

Please sign in to comment.