Skip to content

Commit

Permalink
Add unit tests for updated normalize_path and split_path utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dhung committed Apr 3, 2024
1 parent bc86e8f commit 1e4ec14
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/unit/test_internal_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
#

import pytest

from snowflake.snowpark._internal import utils


@pytest.mark.parametrize(
"path, expected_dir, expected_file",
[
("stage/", "stage", ""),
("stage/file.txt", "stage", "file.txt"),
("dir/subdir/file.txt", "dir/subdir", "file.txt"),
("@stage/dir/subdir/file.txt", "@stage/dir/subdir", "file.txt"),
("'@stage/dir/subdir/file.txt'", "@stage/dir/subdir", "file.txt"),
(
"snow://domain/test_entity/versions/test_version/file.txt",
"snow://domain/test_entity/versions/test_version",
"file.txt",
),
(
"'snow://domain/test_entity/versions/test_version/file.txt'",
"snow://domain/test_entity/versions/test_version",
"file.txt",
),
],
)
def test_split_path(path: str, expected_dir: str, expected_file: str) -> None:
dir, file = utils.split_path(path)
assert expected_dir == dir
assert expected_file == file


@pytest.mark.parametrize(
"path, is_local, expected",
[
("dir/file.txt", True, "'file://dir/file.txt'"),
("dir/subdir/file.txt", True, "'file://dir/subdir/file.txt'"),
("'dir/subdir/file.txt'", True, "'dir/subdir/file.txt'"),
("file://dir/subdir/file.txt", True, "'file://dir/subdir/file.txt'"),
("stage/", False, "'@stage/'"),
("stage/file.txt", False, "'@stage/file.txt'"),
("'stage/file.txt'", False, "'stage/file.txt'"),
(
"stage/'embedded_quote'/file.txt",
False,
"'@stage/\\'embedded_quote\\'/file.txt'",
),
("@stage/dir/subdir/file.txt", False, "'@stage/dir/subdir/file.txt'"),
("'@stage/dir/subdir/file.txt'", False, "'@stage/dir/subdir/file.txt'"),
(
"snow://domain/test_entity/versions/test_version/file.txt",
False,
"'snow://domain/test_entity/versions/test_version/file.txt'",
),
(
"'snow://domain/test_entity/versions/test_version/file.txt'",
False,
"'snow://domain/test_entity/versions/test_version/file.txt'",
),
],
)
def test_normalize_path(path: str, is_local: bool, expected: str) -> None:
actual = utils.normalize_path(path, is_local)
assert expected == actual

0 comments on commit 1e4ec14

Please sign in to comment.