Skip to content

Commit

Permalink
chore(ingest): reorganize unit tests (#11636)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Oct 17, 2024
1 parent d34717f commit b814469
Show file tree
Hide file tree
Showing 42 changed files with 25 additions and 29 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def test_configure_with_file_sink_does_not_init_graph(self, mock_source, tmp_pat
def test_run_including_fake_transformation(self):
pipeline = Pipeline.create(
{
"source": {"type": "tests.unit.test_pipeline.FakeSource"},
"source": {"type": "tests.unit.api.test_pipeline.FakeSource"},
"transformers": [
{"type": "tests.unit.test_pipeline.AddStatusRemovedTransformer"}
{"type": "tests.unit.api.test_pipeline.AddStatusRemovedTransformer"}
],
"sink": {"type": "tests.test_helpers.sink_helpers.RecordingSink"},
"run_id": "pipeline_test",
Expand All @@ -253,7 +253,7 @@ def test_run_including_registered_transformation(self):

pipeline = Pipeline.create(
{
"source": {"type": "tests.unit.test_pipeline.FakeSource"},
"source": {"type": "tests.unit.api.test_pipeline.FakeSource"},
"transformers": [
{
"type": "simple_add_dataset_ownership",
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_pipeline_return_code(self, tmp_path, source, strict_warnings, exit_code
---
run_id: pipeline_test
source:
type: tests.unit.test_pipeline.{source}
type: tests.unit.api.test_pipeline.{source}
config: {{}}
sink:
type: console
Expand Down Expand Up @@ -379,7 +379,7 @@ def test_pipeline_return_code(self, tmp_path, source, strict_warnings, exit_code
def test_pipeline_process_commits(self, commit_policy, source, should_commit):
pipeline = Pipeline.create(
{
"source": {"type": f"tests.unit.test_pipeline.{source}"},
"source": {"type": f"tests.unit.api.test_pipeline.{source}"},
"sink": {"type": "console"},
"run_id": "pipeline_test",
}
Expand Down
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
validate_all_providers_have_committed_successfully,
)
from tests.test_helpers.type_helpers import PytestConfig
from tests.unit.test_glue_source_stubs import (
from tests.unit.glue.test_glue_source_stubs import (
databases_1,
databases_2,
get_bucket_tagging,
Expand Down Expand Up @@ -71,6 +71,8 @@
GMS_PORT = 8080
GMS_SERVER = f"http://localhost:{GMS_PORT}"

test_resources_dir = Path(__file__).parent


def glue_source(
platform_instance: Optional[str] = None,
Expand Down Expand Up @@ -247,7 +249,6 @@ def test_glue_ingest(
write_metadata_file(tmp_path / mce_file, mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / mce_file,
Expand Down Expand Up @@ -312,8 +313,6 @@ def test_config_without_platform():

@freeze_time(FROZEN_TIME)
def test_glue_stateful(pytestconfig, tmp_path, mock_time, mock_datahub_graph):
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"

deleted_actor_golden_mcs = "{}/glue_deleted_actor_mces_golden.json".format(
test_resources_dir
)
Expand Down Expand Up @@ -438,7 +437,6 @@ def test_glue_with_delta_schema_ingest(
write_metadata_file(tmp_path / "glue_delta_mces.json", mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / "glue_delta_mces.json",
Expand Down Expand Up @@ -475,7 +473,6 @@ def test_glue_with_malformed_delta_schema_ingest(
write_metadata_file(tmp_path / "glue_malformed_delta_mces.json", mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / "glue_malformed_delta_mces.json",
Expand Down Expand Up @@ -571,7 +568,6 @@ def test_glue_ingest_include_table_lineage(
write_metadata_file(tmp_path / mce_file, mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / mce_file,
Expand Down Expand Up @@ -678,7 +674,6 @@ def fake_schema_metadata(entity_urn: str) -> models.SchemaMetadataClass:
write_metadata_file(tmp_path / mce_file, mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / mce_file,
Expand Down Expand Up @@ -716,7 +711,6 @@ def test_glue_ingest_with_profiling(
write_metadata_file(tmp_path / mce_file, mce_objects)

# Verify the output.
test_resources_dir = pytestconfig.rootpath / "tests/unit/glue"
mce_helpers.check_golden_file(
pytestconfig,
output_path=tmp_path / mce_file,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SqlParsingDebugInfo,
SqlParsingResult,
)
from tests.unit.redshift_query_mocker import mock_cursor
from tests.unit.redshift.redshift_query_mocker import mock_cursor


def test_get_sources_from_query():
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
job_types,
)
from tests.test_helpers import mce_helpers
from tests.unit.test_sagemaker_source_stubs import (
from tests.unit.sagemaker.test_sagemaker_source_stubs import (
describe_endpoint_response_1,
describe_endpoint_response_2,
describe_feature_group_response_1,
Expand Down
28 changes: 15 additions & 13 deletions metadata-ingestion/tests/unit/utilities/test_perf_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,39 @@

def test_perf_timer_simple():
with PerfTimer() as timer:
time.sleep(1)
assert approx(timer.elapsed_seconds()) == 1
time.sleep(0.4)
assert approx(timer.elapsed_seconds()) == 0.4

assert approx(timer.elapsed_seconds()) == 1
assert approx(timer.elapsed_seconds()) == 0.4


def test_perf_timer_paused_timer():
with PerfTimer() as current_timer:
time.sleep(1)
assert approx(current_timer.elapsed_seconds()) == 1
time.sleep(0.5)
assert approx(current_timer.elapsed_seconds()) == 0.5
with current_timer.pause():
time.sleep(2)
assert approx(current_timer.elapsed_seconds()) == 1
assert approx(current_timer.elapsed_seconds()) == 1
time.sleep(1)
time.sleep(0.3)
assert approx(current_timer.elapsed_seconds()) == 0.5
assert approx(current_timer.elapsed_seconds()) == 0.5
time.sleep(0.2)

assert approx(current_timer.elapsed_seconds()) == 2
assert approx(current_timer.elapsed_seconds()) == 0.7


def test_generator_with_paused_timer():
n = 4

def generator_function():
with PerfTimer() as inner_timer:
time.sleep(1)
for i in range(10):
for i in range(n):
time.sleep(0.2)
with inner_timer.pause():
time.sleep(0.2)
yield i
assert approx(inner_timer.elapsed_seconds()) == 1 + 0.2 * 10
assert approx(inner_timer.elapsed_seconds()) == 1 + 0.2 * n

with PerfTimer() as outer_timer:
seq = generator_function()
list([i for i in seq])
assert approx(outer_timer.elapsed_seconds()) == 1 + 0.2 * 10 + 0.2 * 10
assert approx(outer_timer.elapsed_seconds()) == 1 + 0.2 * n + 0.2 * n

0 comments on commit b814469

Please sign in to comment.