Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions python/tests/e2e/put_get/test_put_get_auto_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
create_temporary_stage_and_upload_file,
get_file_from_stage,
)
from tests.e2e.types.utils import assert_connection_is_open
from tests.utils import shared_test_data_dir


def test_should_compress_the_file_before_uploading_to_stage_when_auto_compress_set_to_true(
execute_query,
connection,
):
uncompressed_file_path = shared_test_data_dir() / "compression" / "test_data.csv"
compressed_file_path = shared_test_data_dir() / "compression" / "test_data.csv.gz"
uncompressed_filename = "test_data.csv"
compressed_filename = "test_data.csv.gz"
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# When File is uploaded to stage with AUTO_COMPRESS set to true
stage_name, _ = create_temporary_stage_and_upload_file(
cursor,
Expand Down Expand Up @@ -58,17 +54,14 @@ def test_should_compress_the_file_before_uploading_to_stage_when_auto_compress_s


def test_should_not_compress_the_file_before_uploading_to_stage_when_auto_compress_set_to_false(
execute_query,
connection,
):
uncompressed_file_path = shared_test_data_dir() / "compression" / "test_data.csv"
uncompressed_filename = "test_data.csv"
compressed_filename = "test_data.csv.gz"

# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# When File is uploaded to stage with AUTO_COMPRESS set to false
stage_name, _ = create_temporary_stage_and_upload_file(
cursor,
Expand Down
19 changes: 6 additions & 13 deletions python/tests/e2e/put_get/test_put_get_basic_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
get_file_from_stage,
list_stage_contents,
)
from tests.e2e.types.utils import assert_connection_is_open
from tests.utils import shared_test_data_dir


Expand Down Expand Up @@ -82,13 +81,11 @@ def test_should_get_file_uploaded_to_stage(connection):
assert content == "1,2,3"


def test_should_return_correct_rowset_for_put(execute_query, connection):
def test_should_return_correct_rowset_for_put(connection):
test_file_path = shared_test_data_dir() / "compression" / "test_data.csv"

# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# When File is uploaded to stage
_, upload_result = create_temporary_stage_and_upload_file(
cursor,
Expand Down Expand Up @@ -140,13 +137,11 @@ def test_should_return_correct_rowset_for_get(connection):
assert get_result[3] == ""


def test_should_return_correct_column_metadata_for_put(execute_query, connection):
def test_should_return_correct_column_metadata_for_put(connection):
test_file_path = shared_test_data_dir() / "compression" / "test_data.csv"

# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# When File is uploaded to stage
_, upload_result = create_temporary_stage_and_upload_file(
cursor,
Expand Down Expand Up @@ -259,14 +254,12 @@ def test_should_get_file_from_subdirectory_in_stage(connection):
assert content == "1,2,3"


def test_should_upload_file_to_subdirectory_in_stage(execute_query, connection):
def test_should_upload_file_to_subdirectory_in_stage(connection):
test_file_path = shared_test_data_dir() / "compression" / "test_data.csv"
filename = test_file_path.name

# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# When File is uploaded to a subdirectory in stage
stage_name = create_temporary_stage(cursor, "TEST_SUBDIR_UPLOAD")
subdir_path = f"@{stage_name}/nested/subdir"
Expand Down
39 changes: 10 additions & 29 deletions python/tests/e2e/put_get/test_put_get_source_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
as_file_uri,
create_temporary_stage,
)
from tests.e2e.types.utils import assert_connection_is_open
from tests.utils import shared_test_data_dir


Expand All @@ -22,12 +21,10 @@
],
)
def test_should_auto_detect_standard_compression_types_when_source_compression_set_to_auto_detect(
execute_query, connection, expected_compression, filename
connection, expected_compression, filename
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And File with standard type (GZIP, BZIP2, BROTLI, ZSTD, DEFLATE)
stage_name, test_file_path = create_stage_and_get_compression_file(
cursor, f"TEST_STAGE_{expected_compression}", expected_compression
Expand Down Expand Up @@ -79,12 +76,10 @@ def test_should_auto_detect_standard_compression_types_when_source_compression_s
],
)
def test_should_upload_compressed_files_with_source_compression_set_to_explicit_types(
execute_query, connection, compression, filename
connection, compression, filename
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And File with standard type (GZIP, BZIP2, BROTLI, ZSTD, DEFLATE, RAW_DEFLATE)
stage_name, test_file_path = create_stage_and_get_compression_file(
cursor, f"TEST_STAGE_{compression}", compression
Expand Down Expand Up @@ -112,13 +107,10 @@ def test_should_upload_compressed_files_with_source_compression_set_to_explicit_


def test_should_not_compress_file_when_source_compression_set_to_auto_detect_and_auto_compress_set_to_false(
execute_query,
connection,
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And Uncompressed file
stage_name, test_file_path = create_stage_and_get_compression_file(
cursor, "TEST_STAGE_NONE_NO_AUTO_COMPRESS", "NONE"
Expand All @@ -138,13 +130,10 @@ def test_should_not_compress_file_when_source_compression_set_to_auto_detect_and


def test_should_not_compress_file_when_source_compression_set_to_none_and_auto_compress_set_to_false(
execute_query,
connection,
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And Uncompressed file
stage_name, test_file_path = create_stage_and_get_compression_file(
cursor, "TEST_STAGE_NONE_NO_AUTO_COMPRESS", "NONE"
Expand All @@ -163,13 +152,10 @@ def test_should_not_compress_file_when_source_compression_set_to_none_and_auto_c


def test_should_compress_uncompressed_file_when_source_compression_set_to_auto_detect_and_auto_compress_set_to_true(
execute_query,
connection,
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And Uncompressed file
stage_name, test_file_path = create_stage_and_get_compression_file(cursor, "TEST_STAGE_AUTO_COMPRESS", "NONE")
filename = "test_data.csv"
Expand All @@ -188,13 +174,10 @@ def test_should_compress_uncompressed_file_when_source_compression_set_to_auto_d


def test_should_compress_uncompressed_file_when_source_compression_set_to_none_and_auto_compress_set_to_true(
execute_query,
connection,
):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And Uncompressed file
stage_name, test_file_path = create_stage_and_get_compression_file(
cursor, "TEST_STAGE_NONE_AUTO_COMPRESS", "NONE"
Expand All @@ -213,11 +196,9 @@ def test_should_compress_uncompressed_file_when_source_compression_set_to_none_a
assert_put_compression_result(result, filename, "NONE", expected_target, "GZIP")


def test_should_return_error_for_unsupported_compression_type(execute_query, connection):
def test_should_return_error_for_unsupported_compression_type(connection):
# Given Snowflake client is logged in
with connection.cursor() as cursor:
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)

# And File compressed with unsupported format
stage_name, test_file_path = create_stage_and_get_compression_file(cursor, "TEST_STAGE_UNSUPPORTED", "LZMA")

Expand Down
29 changes: 10 additions & 19 deletions python/tests/e2e/query/test_basic_execute_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

import pytest

from tests.e2e.types.utils import assert_connection_is_open, assert_sequential_values
from tests.e2e.types.utils import assert_sequential_values


class TestSelectQueries:
"""Tests for basic SELECT query execution."""

def test_should_execute_simple_select_returning_single_value(self, execute_query, cursor):
"""Test simple SELECT returning single value."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test simple SELECT returning single value."""

# When Query "SELECT 1 AS value" is executed
cursor.execute("SELECT 1 AS value")
Expand All @@ -36,9 +35,8 @@ def test_should_execute_simple_select_returning_single_value(self, execute_query
assert result[0] == 1

def test_should_execute_select_returning_multiple_columns(self, execute_query, cursor):
"""Test SELECT returning multiple columns."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test SELECT returning multiple columns."""

# When Query "SELECT 1 AS col1, 'hello' AS col2, '3.14' AS col3" is executed
cursor.execute("SELECT 1 AS col1, 'hello' AS col2, '3.14' AS col3")
Expand All @@ -54,9 +52,8 @@ def test_should_execute_select_returning_multiple_columns(self, execute_query, c
assert result[2] == "3.14"

def test_should_execute_select_returning_multiple_rows(self, execute_query, cursor):
"""Test SELECT returning multiple rows using GENERATOR."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test SELECT returning multiple rows using GENERATOR."""

# When Query "SELECT seq8() AS id FROM TABLE(GENERATOR(ROWCOUNT => 5)) v ORDER BY id" is executed
cursor.execute("SELECT seq8() AS id FROM TABLE(GENERATOR(ROWCOUNT => 5)) v ORDER BY id")
Expand All @@ -68,9 +65,8 @@ def test_should_execute_select_returning_multiple_rows(self, execute_query, curs
assert_sequential_values(values, 5)

def test_should_execute_select_returning_empty_result_set(self, execute_query, cursor):
"""Test SELECT returning empty result set."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test SELECT returning empty result set."""

# When Query "SELECT 1 WHERE 1=0" is executed
cursor.execute("SELECT 1 WHERE 1=0")
Expand All @@ -80,9 +76,8 @@ def test_should_execute_select_returning_empty_result_set(self, execute_query, c
assert result == []

def test_should_execute_select_returning_null_values(self, execute_query, cursor):
"""Test SELECT returning NULL values."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test SELECT returning NULL values."""

# When Query "SELECT NULL AS col1, 42 AS col2, NULL AS col3" is executed
cursor.execute("SELECT NULL AS col1, 42 AS col2, NULL AS col3")
Expand All @@ -99,9 +94,8 @@ class TestDDLStatements:
"""Tests for DDL (Data Definition Language) statements."""

def test_should_execute_create_and_drop_table_statements(self, execute_query, cursor, tmp_schema):
"""Test CREATE and DROP TABLE statements."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test CREATE and DROP TABLE statements."""
table_name = f"{tmp_schema}.test_basic_ddl"

# When CREATE TABLE statement is executed
Expand All @@ -122,9 +116,8 @@ class TestDMLStatements:
"""Tests for DML (Data Manipulation Language) statements."""

def test_should_execute_insert_and_retrieve_inserted_data(self, execute_query, cursor, tmp_schema):
"""Test INSERT and retrieve inserted data."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test INSERT and retrieve inserted data."""

# And A temporary table is created
table_name = f"{tmp_schema}.test_basic_dml"
Expand All @@ -150,9 +143,8 @@ class TestErrorHandling:
"""Tests for error handling."""

def test_should_return_error_for_invalid_sql_syntax(self, execute_query, cursor):
"""Test error handling for invalid SQL syntax."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test error handling for invalid SQL syntax."""

from snowflake.connector import ProgrammingError

Expand All @@ -167,9 +159,8 @@ class TestSequentialExecution:
"""Tests for sequential query execution."""

def test_should_execute_multiple_queries_sequentially_on_same_connection(self, execute_query, cursor):
"""Test multiple queries executed sequentially on same connection."""
# Given Snowflake client is logged in
assert_connection_is_open(execute_query)
"""Test multiple queries executed sequentially on same connection."""

# When Multiple queries are executed sequentially
cursor.execute("SELECT 1 AS first_query")
Expand Down
Loading
Loading