Skip to content

Commit 7e22397

Browse files
committed
undo ex_info changes
1 parent b8f4428 commit 7e22397

9 files changed

+139
-75
lines changed

tests/integ/scala/test_column_suite.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,15 @@ def test_column_constructors_col(session):
486486
assert df.select(col("CoL")).collect() == [Row(1)]
487487
assert df.select(col('"COL"')).collect() == [Row(1)]
488488

489-
with pytest.raises(SnowparkSQLException, match="invalid identifier"):
489+
with pytest.raises(SnowparkSQLException) as ex_info:
490490
df.select(col('"Col"')).collect()
491-
with pytest.raises(SnowparkSQLException, match="invalid identifier"):
491+
assert "invalid identifier" in str(ex_info)
492+
with pytest.raises(SnowparkSQLException) as ex_info:
492493
df.select(col("COL .")).collect()
493-
with pytest.raises(SnowparkSQLException, match="invalid identifier"):
494+
assert "invalid identifier" in str(ex_info)
495+
with pytest.raises(SnowparkSQLException) as ex_info:
494496
df.select(col('"CoL"')).collect()
497+
assert "invalid identifier" in str(ex_info)
495498

496499

497500
def test_column_constructors_select(session):
@@ -505,10 +508,10 @@ def test_column_constructors_select(session):
505508

506509
with pytest.raises(SnowparkSQLException) as ex_info:
507510
df.select('"Col"').collect()
508-
assert "invalid identifier" in str(ex_info.value)
511+
assert "invalid identifier" in str(ex_info)
509512
with pytest.raises(SnowparkSQLException) as ex_info:
510513
df.select("COL .").collect()
511-
assert "invalid identifier" in str(ex_info.value)
514+
assert "invalid identifier" in str(ex_info)
512515

513516

514517
@pytest.mark.xfail(
@@ -530,16 +533,16 @@ def test_sql_expr_column(session):
530533

531534
with pytest.raises(SnowparkSQLException) as ex_info:
532535
df.select(sql_expr('"Col"')).collect()
533-
assert "invalid identifier" in str(ex_info.value)
536+
assert "invalid identifier" in str(ex_info)
534537
with pytest.raises(SnowparkSQLException) as ex_info:
535538
df.select(sql_expr("COL .")).collect()
536-
assert "syntax error" in str(ex_info.value)
539+
assert "syntax error" in str(ex_info)
537540
with pytest.raises(SnowparkSQLException) as ex_info:
538541
df.select(sql_expr('"CoL"')).collect()
539-
assert "invalid identifier" in str(ex_info.value)
542+
assert "invalid identifier" in str(ex_info)
540543
with pytest.raises(SnowparkSQLException) as ex_info:
541544
df.select(sql_expr("col .")).collect()
542-
assert "syntax error" in str(ex_info.value)
545+
assert "syntax error" in str(ex_info)
543546

544547

545548
def test_errors_for_aliased_columns(session, local_testing_mode):
@@ -553,15 +556,15 @@ def test_errors_for_aliased_columns(session, local_testing_mode):
553556
with pytest.raises(exc) as ex_info:
554557
df.select(col("a").as_("b") + 10).collect()
555558
if not local_testing_mode:
556-
assert "You can only define aliases for the root" in str(ex_info.value)
559+
assert "You can only define aliases for the root" in str(ex_info)
557560
else:
558-
assert "invalid identifier" in str(ex_info.value)
561+
assert "invalid identifier" in str(ex_info)
559562
with pytest.raises(exc) as ex_info:
560563
df.group_by(col("a")).agg(avg(col("a").as_("b"))).collect()
561564
if not local_testing_mode:
562-
assert "You can only define aliases for the root" in str(ex_info.value)
565+
assert "You can only define aliases for the root" in str(ex_info)
563566
else:
564-
assert "invalid identifier" in str(ex_info.value)
567+
assert "invalid identifier" in str(ex_info)
565568

566569

567570
def test_like(session):
@@ -665,7 +668,7 @@ def test_regexp(session):
665668

666669
with pytest.raises(SnowparkSQLException) as ex_info:
667670
TestData.string4(session).where(col("A").regexp("+*")).collect()
668-
assert "Invalid regular expression" in str(ex_info.value)
671+
assert "Invalid regular expression" in str(ex_info)
669672

670673
# Test when pattern is a column of literal strings
671674
df = session.create_dataframe(
@@ -725,7 +728,7 @@ def test_when_case(session, local_testing_mode):
725728
when(col("a").is_null(), lit("a")).when(col("a") == 1, lit(6)).as_("a")
726729
).collect()
727730
if not local_testing_mode:
728-
assert "Numeric value 'a' is not recognized" in str(ex_info.value)
731+
assert "Numeric value 'a' is not recognized" in str(ex_info)
729732

730733

731734
def test_lit_contains_single_quote(session):

tests/integ/scala/test_dataframe_aggregate_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ def test_decimal_sum_over_window_should_work(session):
11371137
def test_aggregate_function_in_groupby(session):
11381138
with pytest.raises(SnowparkSQLException) as ex_info:
11391139
TestData.test_data4(session).group_by(sum(col('"KEY"'))).count().collect()
1140-
assert "is not a valid group by expression" in str(ex_info.value)
1140+
assert "is not a valid group by expression" in str(ex_info)
11411141

11421142

11431143
def test_ints_in_agg_exprs_are_taken_as_groupby_ordinal(session):

tests/integ/scala/test_dataframe_copy_into.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ def test_copy_csv_negative(session, tmp_stage_name1, tmp_table_name):
398398
)
399399
assert (
400400
f"Cannot create the target table {table_name_not_exist} because Snowpark cannot determine the column names to use. You should create the table before calling copy_into_table()"
401-
in str(exec_info.value)
401+
in str(exec_info)
402402
)
403403

404404
# case 2: copy into an existing table table with unmatched transformations
405405
with pytest.raises(SnowparkSQLException) as exec_info:
406406
df.copy_into_table(tmp_table_name, transformations=[col("$s1").as_("c1_alias")])
407407
assert "Insert value list does not match column list expecting 3 but got 1" in str(
408-
exec_info.value
408+
exec_info
409409
)
410410

411411

@@ -668,7 +668,7 @@ def test_copy_csv_negative_test_with_column_names(session, tmp_stage_name1):
668668
)
669669
assert (
670670
"Number of column names provided to copy into does not match the number of transformations provided. Number of column names: 1, number of transformations: 2"
671-
in str(exec_info.value)
671+
in str(exec_info)
672672
)
673673

674674
# case 2: column names contains unknown columns
@@ -678,7 +678,7 @@ def test_copy_csv_negative_test_with_column_names(session, tmp_stage_name1):
678678
target_columns=["c1", "c2", "c3", "c4"],
679679
transformations=[col("$1"), col("$2"), col("$3"), col("$4")],
680680
)
681-
assert "invalid identifier 'C4'" in str(exec_info.value)
681+
assert "invalid identifier 'C4'" in str(exec_info)
682682
finally:
683683
Utils.drop_table(session, table_name)
684684

@@ -1103,14 +1103,14 @@ def test_copy_non_csv_negative_test(
11031103
df.copy_into_table(table_name)
11041104
assert (
11051105
f"Cannot create the target table {table_name} because Snowpark cannot determine the column names to use. You should create the table before calling copy_into_table()"
1106-
in str(exec_info.value)
1106+
in str(exec_info)
11071107
)
11081108

11091109
with pytest.raises(SnowparkDataframeReaderException) as exec_info:
11101110
df.copy_into_table(table_name, transformations=[col("$1").as_("A")])
11111111
assert (
11121112
f"Cannot create the target table {table_name} because Snowpark cannot determine the column names to use. You should create the table before calling copy_into_table()"
1113-
in str(exec_info.value)
1113+
in str(exec_info)
11141114
)
11151115

11161116
Utils.create_table(session, table_name, "c1 String")
@@ -1121,7 +1121,7 @@ def test_copy_non_csv_negative_test(
11211121
)
11221122
assert (
11231123
"Insert value list does not match column list expecting 1 but got 2"
1124-
in str(exec_info.value)
1124+
in str(exec_info)
11251125
)
11261126
finally:
11271127
Utils.drop_table(session, table_name)

tests/integ/scala/test_dataframe_reader_suite.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def get_df_from_reader_and_file_format(reader, file_format):
136136

137137
@pytest.fixture(scope="module", autouse=True)
138138
def setup(session, resources_path, local_testing_mode):
139+
# TODO SNOW-2098847: remove this workaround after fixing the issue
140+
session._use_scoped_temp_objects = False
141+
139142
test_files = TestFiles(resources_path)
140143
if not local_testing_mode:
141144
Utils.create_stage(session, tmp_stage_name1, is_temporary=True)
@@ -399,7 +402,7 @@ def test_read_csv(session, mode):
399402
)
400403
with pytest.raises(SnowparkSQLException) as ex_info:
401404
df3.collect()
402-
assert "is out of range" in str(ex_info.value)
405+
assert "is out of range" in str(ex_info)
403406

404407

405408
@pytest.mark.xfail(
@@ -590,7 +593,7 @@ def test_read_csv_incorrect_schema(session, mode):
590593
df = reader.option("purge", False).schema(incorrect_schema).csv(test_file_on_stage)
591594
with pytest.raises(SnowparkSQLException) as ex_info:
592595
df.collect()
593-
assert "Number of columns in file (3) does not match" in str(ex_info.value)
596+
assert "Number of columns in file (3) does not match" in str(ex_info)
594597

595598

596599
@pytest.mark.skipif(
@@ -1971,10 +1974,6 @@ def test_read_multiple_csvs(session):
19711974
"config.getoption('local_testing_mode', default=False)",
19721975
reason="xml not supported in local testing mode",
19731976
)
1974-
@pytest.mark.skipif(
1975-
IS_IN_STORED_PROC,
1976-
reason="SNOW-2044853: Flaky in stored procedure test",
1977-
)
19781977
@pytest.mark.parametrize(
19791978
"file,row_tag,expected_row_count,expected_column_count",
19801979
[
@@ -1997,10 +1996,6 @@ def test_read_xml_row_tag(
19971996
"config.getoption('local_testing_mode', default=False)",
19981997
reason="xml not supported in local testing mode",
19991998
)
2000-
@pytest.mark.skipif(
2001-
IS_IN_STORED_PROC,
2002-
reason="SNOW-2044853: Flaky in stored procedure test",
2003-
)
20041999
def test_read_xml_no_xxe(session):
20052000
row_tag = "bar"
20062001
stage_file_path = f"@{tmp_stage_name1}/{test_file_xxe_xml}"
@@ -2012,10 +2007,6 @@ def test_read_xml_no_xxe(session):
20122007
"config.getoption('local_testing_mode', default=False)",
20132008
reason="xml not supported in local testing mode",
20142009
)
2015-
@pytest.mark.skipif(
2016-
IS_IN_STORED_PROC,
2017-
reason="SNOW-2044853: Flaky in stored procedure test",
2018-
)
20192010
def test_read_xml_query_nested_data(session):
20202011
row_tag = "tag"
20212012
df = session.read.option("rowTag", row_tag).xml(
@@ -2046,10 +2037,6 @@ def test_read_xml_non_existing_file(session):
20462037
"config.getoption('local_testing_mode', default=False)",
20472038
reason="xml not supported in local testing mode",
20482039
)
2049-
@pytest.mark.skipif(
2050-
IS_IN_STORED_PROC,
2051-
reason="SNOW-2044853: Flaky in stored procedure test",
2052-
)
20532040
@pytest.mark.parametrize(
20542041
"file",
20552042
(
@@ -2060,12 +2047,13 @@ def test_read_xml_non_existing_file(session):
20602047
)
20612048
def test_read_malformed_xml(session, file):
20622049
row_tag = "record"
2050+
file_path = f"@{tmp_stage_name1}/{file}"
20632051

20642052
# permissive mode
20652053
df = (
20662054
session.read.option("rowTag", row_tag)
20672055
.option("mode", "permissive")
2068-
.xml(f"@{tmp_stage_name1}/{file}")
2056+
.xml(file_path)
20692057
)
20702058
result = df.collect()
20712059
assert len(result) == 2
@@ -2079,17 +2067,37 @@ def test_read_malformed_xml(session, file):
20792067
df = (
20802068
session.read.option("rowTag", row_tag)
20812069
.option("mode", "dropmalformed")
2082-
.xml(f"@{tmp_stage_name1}/{test_file_malformed_no_closing_tag_xml}")
2070+
.xml(file_path)
20832071
)
20842072
result = df.collect()
20852073
assert len(result) == 1
20862074
assert len(result[0]) == 3
20872075

20882076
# failfast mode
20892077
df = (
2090-
session.read.option("rowTag", row_tag)
2091-
.option("mode", "failfast")
2092-
.xml(f"@{tmp_stage_name1}/{test_file_malformed_no_closing_tag_xml}")
2078+
session.read.option("rowTag", row_tag).option("mode", "failfast").xml(file_path)
20932079
)
20942080
with pytest.raises(SnowparkSQLException, match="Malformed XML record at bytes"):
20952081
df.collect()
2082+
2083+
2084+
@pytest.mark.skipif(
2085+
"config.getoption('local_testing_mode', default=False)",
2086+
reason="xml not supported in local testing mode",
2087+
)
2088+
def test_read_xml_row_tag_not_found(session):
2089+
row_tag = "non-existing-tag"
2090+
df = session.read.option("rowTag", row_tag).xml(
2091+
f"@{tmp_stage_name1}/{test_file_books_xml}"
2092+
)
2093+
2094+
with pytest.raises(
2095+
SnowparkDataframeReaderException, match="Cannot find the row tag"
2096+
):
2097+
df.collect()
2098+
2099+
# also works for nested query plan
2100+
with pytest.raises(
2101+
SnowparkDataframeReaderException, match="Cannot find the row tag"
2102+
):
2103+
df.filter(lit(True)).collect()

tests/integ/scala/test_dataframe_suite.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,28 +1268,28 @@ def test_select_negative_select(session):
12681268
# Select with empty sequences
12691269
with pytest.raises(ValueError) as ex_info:
12701270
df.select()
1271-
assert "The input of select() cannot be empty" in str(ex_info.value)
1271+
assert "The input of select() cannot be empty" in str(ex_info)
12721272

12731273
with pytest.raises(ValueError) as ex_info:
12741274
df.select([])
1275-
assert "The input of select() cannot be empty" in str(ex_info.value)
1275+
assert "The input of select() cannot be empty" in str(ex_info)
12761276

12771277
# select columns which don't exist
12781278
with pytest.raises(SnowparkSQLException) as ex_info:
12791279
df.select("not_exists_column").collect()
1280-
assert "SQL compilation error" in str(ex_info.value)
1280+
assert "SQL compilation error" in str(ex_info)
12811281

12821282
with pytest.raises(SnowparkSQLException) as ex_info:
12831283
df.select(["not_exists_column"]).collect()
1284-
assert "SQL compilation error" in str(ex_info.value)
1284+
assert "SQL compilation error" in str(ex_info)
12851285

12861286
with pytest.raises(SnowparkSQLException) as ex_info:
12871287
df.select(col("not_exists_column")).collect()
1288-
assert "SQL compilation error" in str(ex_info.value)
1288+
assert "SQL compilation error" in str(ex_info)
12891289

12901290
with pytest.raises(SnowparkSQLException) as ex_info:
12911291
df.select([col("not_exists_column")]).collect()
1292-
assert "SQL compilation error" in str(ex_info.value)
1292+
assert "SQL compilation error" in str(ex_info)
12931293

12941294

12951295
def test_drop_and_dropcolumns(session):
@@ -1392,8 +1392,8 @@ def test_rollup(session):
13921392
with pytest.raises(SnowparkSQLException) as ex_info:
13931393
df.rollup(list()).agg(sum_(col("value"))).show()
13941394

1395-
assert "001003 (42000): " in str(ex_info.value) and "SQL compilation error" in str(
1396-
ex_info.value
1395+
assert "001003 (42000): " in str(ex_info) and "SQL compilation error" in str(
1396+
ex_info
13971397
)
13981398

13991399
# rollup() on 1 column
@@ -1518,8 +1518,8 @@ def test_cube(session):
15181518
with pytest.raises(SnowparkSQLException) as ex_info:
15191519
df.cube(list()).agg(sum_(col("value"))).show()
15201520

1521-
assert "001003 (42000): " in str(ex_info.value) and "SQL compilation error" in str(
1522-
ex_info.value
1521+
assert "001003 (42000): " in str(ex_info) and "SQL compilation error" in str(
1522+
ex_info
15231523
)
15241524

15251525
# cube() on 1 column

0 commit comments

Comments
 (0)