Skip to content

Commit cbadea1

Browse files
authored
Increases test coverage (#2739)
## Changes Increases coverage ### Functionality - [x] fixes and modifies testing warnings ### Tests - [x] modified unit tests
1 parent cb5cfe8 commit cbadea1

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

tests/unit/hive_metastore/test_table_size.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import sys
23

34
from databricks.labs.lsql.backends import MockBackend
@@ -41,11 +42,11 @@ def test_table_size_crawler(mocker):
4142
assert TableSize("hive_metastore", "db1", "table2", 200) in results
4243

4344

44-
def test_table_size_unknown_error(mocker):
45+
def test_table_size_unknown_error(mocker, caplog):
4546
errors = {}
4647
rows = {
4748
"table_size": [],
48-
"hive_metastore.inventory_database.tables": [
49+
"`hive_metastore`.`inventory_database`.`tables`": [
4950
("hive_metastore", "db1", "table1", "MANAGED", "DELTA", "dbfs:/location/table", None),
5051
],
5152
"SHOW DATABASES": [("db1",)],
@@ -56,16 +57,17 @@ def test_table_size_unknown_error(mocker):
5657
tsc = TableSizeCrawler(backend, "inventory_database")
5758
tsc._spark._jsparkSession.table().queryExecution().analyzed().stats().sizeInBytes.side_effect = Exception(...)
5859

59-
results = tsc.snapshot()
60+
with caplog.at_level(logging.WARNING):
61+
results = tsc.snapshot()
6062

6163
assert len(results) == 0
6264

6365

64-
def test_table_size_table_or_view_not_found(mocker):
66+
def test_table_size_table_or_view_not_found(mocker, caplog):
6567
errors = {}
6668
rows = {
6769
"table_size": [],
68-
"hive_metastore.inventory_database.tables": [
70+
"`hive_metastore`.`inventory_database`.`tables`": [
6971
("hive_metastore", "db1", "table1", "MANAGED", "DELTA", "dbfs:/location/table", None),
7072
],
7173
"SHOW DATABASES": [("db1",)],
@@ -80,16 +82,18 @@ def test_table_size_table_or_view_not_found(mocker):
8082
"[TABLE_OR_VIEW_NOT_FOUND]"
8183
)
8284

83-
results = tsc.snapshot()
85+
with caplog.at_level(logging.WARNING):
86+
results = tsc.snapshot()
8487

8588
assert len(results) == 0
89+
assert "Failed to evaluate hive_metastore.db1.table1 table size. Table not found" in caplog.text
8690

8791

88-
def test_table_size_delta_table_not_found(mocker):
92+
def test_table_size_delta_table_not_found(mocker, caplog):
8993
errors = {}
9094
rows = {
9195
"table_size": [],
92-
"hive_metastore.inventory_database.tables": [
96+
"`hive_metastore`.`inventory_database`.`tables`": [
9397
("hive_metastore", "db1", "table1", "MANAGED", "DELTA", "dbfs:/location/table", None),
9498
],
9599
"SHOW DATABASES": [("db1",)],
@@ -104,16 +108,18 @@ def test_table_size_delta_table_not_found(mocker):
104108
"[DELTA_TABLE_NOT_FOUND]"
105109
)
106110

107-
results = tsc.snapshot()
111+
with caplog.at_level(logging.WARNING):
112+
results = tsc.snapshot()
108113

109114
assert len(results) == 0
115+
assert "Failed to evaluate hive_metastore.db1.table1 table size. Table not found" in caplog.text
110116

111117

112-
def test_table_size_when_table_corrupted(mocker):
118+
def test_table_size_when_table_corrupted(mocker, caplog):
113119
errors = {}
114120
rows = {
115121
"table_size": [],
116-
"hive_metastore.inventory_database.tables": [
122+
"`hive_metastore`.`inventory_database`.`tables`": [
117123
("hive_metastore", "db1", "table1", "MANAGED", "DELTA", "dbfs:/location/table", None),
118124
],
119125
"SHOW DATABASES": [("db1",)],
@@ -127,16 +133,18 @@ def test_table_size_when_table_corrupted(mocker):
127133
"[DELTA_MISSING_TRANSACTION_LOG]"
128134
)
129135

130-
results = tsc.snapshot()
136+
with caplog.at_level(logging.WARNING):
137+
results = tsc.snapshot()
131138

132139
assert len(results) == 0
140+
assert "Delta table hive_metastore.db1.table1 is corrupted: missing transaction log" in caplog.text
133141

134142

135-
def test_table_size_when_delta_invalid_format_error(mocker):
143+
def test_table_size_when_delta_invalid_format_error(mocker, caplog):
136144
errors = {}
137145
rows = {
138146
"table_size": [],
139-
"hive_metastore.inventory_database.tables": [
147+
"`hive_metastore`.`inventory_database`.`tables`": [
140148
("hive_metastore", "db1", "table1", "MANAGED", "DELTA", "dbfs:/location/table", None),
141149
],
142150
"SHOW DATABASES": [("db1",)],
@@ -150,6 +158,11 @@ def test_table_size_when_delta_invalid_format_error(mocker):
150158
"[DELTA_INVALID_FORMAT]"
151159
)
152160

153-
results = tsc.snapshot()
161+
with caplog.at_level(logging.WARNING):
162+
results = tsc.snapshot()
154163

155164
assert len(results) == 0
165+
assert (
166+
"Unable to read Delta table hive_metastore.db1.table1, please check table structure and try again."
167+
in caplog.text
168+
)

0 commit comments

Comments
 (0)