Skip to content

Commit

Permalink
add a few tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tempelmann committed Sep 28, 2023
1 parent 4c0d5d6 commit 3e7b7a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
5 changes: 0 additions & 5 deletions discoverx/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,3 @@ def delete_by_class(
if delete_result is not None:
delete_result = delete_result.toPandas()
logger.friendlyHTML(f"<p>The affected tables are</p>{delete_result.to_html()}")

def save_scan(self):
"""Method to save scan result"""
# TODO:
pass
27 changes: 27 additions & 0 deletions tests/unit/discovery_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from discoverx.explorer import DataExplorer, InfoFetcher
from discoverx.discovery import Discovery


@pytest.fixture()
Expand All @@ -14,6 +15,22 @@ def scan_ip_in_tb1(spark, info_fetcher):
return discover


def test_noscan(spark, info_fetcher):
data_explorer = DataExplorer("*.*.tb_1", spark, info_fetcher)
discover = Discovery(
data_explorer._spark,
data_explorer._catalogs,
data_explorer._schemas,
data_explorer._tables,
data_explorer._info_fetcher.get_tables_info(
data_explorer._catalogs, data_explorer._schemas, data_explorer._tables, data_explorer._having_columns
),
)
with pytest.raises(Exception) as scan_first_error:
scan_result = discover.scan_result
assert scan_first_error.value.args[0] == "You first need to scan your lakehouse using Scanner.scan()"


def test_discover_scan_msql(discover_ip):
result = discover_ip._msql("SELECT [ip_v4] as ip FROM *.*.*").collect()
assert {row.ip for row in result} == {"1.2.3.4", "3.4.5.60"}
Expand All @@ -39,6 +56,13 @@ def test_discover_search(discover_ip):
discover_ip.search(None)
assert no_search_term_error.value.args[0] == "search_term has not been provided."

with pytest.raises(ValueError) as search_term_not_string_error:
discover_ip.search(7)
assert (
search_term_not_string_error.value.args[0]
== "The search_term type <class 'int'> is not valid. Please use a string type."
)

with pytest.raises(ValueError) as no_inferred_class_error:
discover_ip.search("###")
assert (
Expand Down Expand Up @@ -97,6 +121,9 @@ def test_discover_delete_by_class(spark, discover_ip):
with pytest.raises(ValueError):
discover_ip.delete_by_class(from_tables="invalid from", by_class="email", values="x")

with pytest.raises(ValueError):
discover_ip.delete_by_class(from_tables="invalid from", by_class="email", values=1)


def test_discover_scan_result(discover_ip):
assert not discover_ip.scan_result.empty

0 comments on commit 3e7b7a6

Please sign in to comment.