Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pczajka committed Apr 4, 2024
1 parent 0c43754 commit 989e81d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 41 deletions.
40 changes: 24 additions & 16 deletions tests/snowpark/test_anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@

import pytest
from snowflake.cli.plugins.snowpark.models import Requirement
from snowflake.cli.plugins.snowpark.package.anaconda import AnacondaChannel
from snowflake.cli.plugins.snowpark.package.anaconda import (
AnacondaChannel,
AnacondaPackageData,
)

from tests.test_data import test_data
from tests.testing_utils.fixtures import TEST_DIR

ANACONDA = AnacondaChannel(
packages={
"shrubbery": {"1.2.1", "1.2.2"},
"dummy_pkg": {"0.1.1", "1.0.0", "1.1.0"},
"jpeg": {"9e", "9d", "9b"},
"shrubbery": AnacondaPackageData(
snowflake_name="shrubbery", versions={"1.2.1", "1.2.2"}
),
"dummy_pkg": AnacondaPackageData(
snowflake_name="dummy-pkg", versions={"0.1.1", "1.0.0", "1.1.0"}
),
"jpeg": AnacondaPackageData(snowflake_name="jpeg", versions={"9e", "9d", "9b"}),
}
)

Expand Down Expand Up @@ -68,16 +75,16 @@ def test_parse_anaconda_packages(mock_get):
Requirement.parse("Pamela==1.0.1"),
]
split_requirements = anaconda.parse_anaconda_packages(packages=packages)
assert len(split_requirements.snowflake) == 1
assert len(split_requirements.other) == 2
assert split_requirements.snowflake[0].name == "pandas"
assert split_requirements.snowflake[0].specifier is True
assert split_requirements.snowflake[0].specs == [("==", "1.4.4")]
assert split_requirements.other[0].name == "FuelSDK"
assert split_requirements.other[0].specifier is True
assert split_requirements.other[0].specs == [(">=", "0.9.3")]
assert split_requirements.other[1].name == "Pamela"
assert split_requirements.other[1].specs == [("==", "1.0.1")]
assert len(split_requirements.in_snowflake) == 1
assert len(split_requirements.unavailable) == 2
assert split_requirements.in_snowflake[0].name == "pandas"
assert split_requirements.in_snowflake[0].specifier is True
assert split_requirements.in_snowflake[0].specs == [("==", "1.4.4")]
assert split_requirements.unavailable[0].name == "fuelsdk"
assert split_requirements.unavailable[0].specifier is True
assert split_requirements.unavailable[0].specs == [(">=", "0.9.3")]
assert split_requirements.unavailable[1].name == "pamela"
assert split_requirements.unavailable[1].specs == [("==", "1.0.1")]


@patch("snowflake.cli.plugins.snowpark.package.anaconda.requests")
Expand All @@ -93,8 +100,9 @@ def test_anaconda_packages(mock_requests):
anaconda_packages = anaconda.parse_anaconda_packages(test_data.packages)
assert (
Requirement.parse_line("snowflake-connector-python")
in anaconda_packages.snowflake
in anaconda_packages.in_snowflake
)
assert (
Requirement.parse_line("my-totally-awesome-package") in anaconda_packages.other
Requirement.parse_line("my-totally-awesome-package")
in anaconda_packages.unavailable
)
32 changes: 21 additions & 11 deletions tests/snowpark/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
import pytest
from snowflake.cli.plugins.snowpark.common import (
_convert_resource_details_to_dict,
_get_snowflake_packages_delta,
_snowflake_requirements_differ,
_sql_to_python_return_type_mapper,
)

from tests.testing_utils.fixtures import (
test_data,
)


def test_get_snowflake_packages_delta(temp_dir, correct_requirements_snowflake_txt):
anaconda_package = test_data.requirements[-1]

result = _get_snowflake_packages_delta([anaconda_package])

assert sorted(result) == sorted(x.lower() for x in test_data.requirements[:-1])
def test_get_snowflake_packages_delta():
for uploaded_packages, new_packages, expected in [
([], [], False),
(
["package", "package_with_requirements>=2,<4"],
["package-with-requirements <4,>=2", "PACKAGE"],
False,
),
(
["different-requirements<1.1,>0.9"],
["different-requirements<1.0,>0.9"],
True,
),
(["different-package"], ["another-package"], True),
(["package"], ["package", "added-package"], True),
(["package", "removed-package"], ["package"], True),
]:
assert expected == _snowflake_requirements_differ(
uploaded_packages, new_packages
)


def test_convert_resource_details_to_dict():
Expand Down
20 changes: 10 additions & 10 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ def test_parse_anaconda_packages(mock_get):
Requirement.parse("Pamela==1.0.1"),
]
split_requirements = anaconda.parse_anaconda_packages(packages=packages)
assert len(split_requirements.snowflake) == 1
assert len(split_requirements.other) == 2
assert split_requirements.snowflake[0].name == "pandas"
assert split_requirements.snowflake[0].specifier is True
assert split_requirements.snowflake[0].specs == [("==", "1.4.4")]
assert split_requirements.other[0].name == "fuelsdk"
assert split_requirements.other[0].specifier is True
assert split_requirements.other[0].specs == [(">=", "0.9.3")]
assert split_requirements.other[1].name == "pamela"
assert split_requirements.other[1].specs == [("==", "1.0.1")]
assert len(split_requirements.in_snowflake) == 1
assert len(split_requirements.unavailable) == 2
assert split_requirements.in_snowflake[0].name == "pandas"
assert split_requirements.in_snowflake[0].specifier is True
assert split_requirements.in_snowflake[0].specs == [("==", "1.4.4")]
assert split_requirements.unavailable[0].name == "fuelsdk"
assert split_requirements.unavailable[0].specifier is True
assert split_requirements.unavailable[0].specs == [(">=", "0.9.3")]
assert split_requirements.unavailable[1].name == "pamela"
assert split_requirements.unavailable[1].specs == [("==", "1.0.1")]


@patch("platform.system")
Expand Down
6 changes: 5 additions & 1 deletion tests_integration/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def test_package_create_skip_version_check(self, directory_for_test, runner):
assert result.exit_code == 0, result.output
assert Path("july.zip").exists()
files = self._get_filenames_from_zip("july.zip")
assert all([name.startswith("july") for name in files])
# july is not available on anaconda
# packaging dependency defines extras
assert all(
[name.startswith("july") or name.startswith("packaging") for name in files]
)

@pytest.mark.integration
def test_package_from_github(self, directory_for_test, runner):
Expand Down
3 changes: 0 additions & 3 deletions tests_integration/test_snowpark.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,6 @@ def test_build_package_from_github(runner, project_directory, alter_requirements
def test_ignore_anaconda_uses_version_from_zip(
flag, project_directory, runner, test_database
):
# TODO: unclock when anaconda version check will be fixed
if not flag:
return
with project_directory("snowpark_version_check"):
command = ["snowpark", "build", "--allow-shared-libraries"]
if flag:
Expand Down

0 comments on commit 989e81d

Please sign in to comment.