-
Notifications
You must be signed in to change notification settings - Fork 6
add to test coverage #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add to test coverage #243
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
77d34f3
add test_get_addr_info()
lisac aff37b0
add test_datetime_str_to_date() and test_utcnow()
lisac 1b3243a
add tests for file_util.py
lisac d046d97
add test for string_utils.py
lisac 39c3ec0
add test for app_config.py
lisac a7c4c24
fix format
lisac 933f8de
add newline to mark end of file
lisac d73aa33
remove unneeded print()
lisac c460a25
remove redundant test
lisac 41d694a
remove a test for behavior that we inherit from pydantic
lisac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
|
||
import pytest | ||
from smart_open import open as smart_open | ||
|
||
import src.util.file_util as file_util | ||
|
||
|
||
def create_file(root_path, file_path): | ||
full_path = os.path.join(root_path, file_path) | ||
|
||
if not file_util.is_s3_path(str(full_path)): | ||
os.makedirs(os.path.dirname(full_path), exist_ok=True) | ||
|
||
with smart_open(full_path, mode="w") as outfile: | ||
outfile.write("hello") | ||
|
||
return full_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,is_s3", | ||
[ | ||
("s3://bucket/folder/test.txt", True), | ||
("./relative/folder/test.txt", False), | ||
("http://example.com/test.txt", False), | ||
], | ||
) | ||
def test_is_s3_path(path, is_s3): | ||
assert file_util.is_s3_path(path) is is_s3 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,bucket,prefix", | ||
[ | ||
("s3://my_bucket/my_key", "my_bucket", "my_key"), | ||
("s3://my_bucket/path/to/directory/", "my_bucket", "path/to/directory/"), | ||
("s3://my_bucket/path/to/file.txt", "my_bucket", "path/to/file.txt"), | ||
], | ||
) | ||
def test_split_s3_url(path, bucket, prefix): | ||
assert file_util.split_s3_url(path) == (bucket, prefix) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,bucket", | ||
[ | ||
("s3://bucket/folder/test.txt", "bucket"), | ||
("s3://bucket_x/folder", "bucket_x"), | ||
("s3://bucket-y/folder/", "bucket-y"), | ||
("s3://bucketz", "bucketz"), | ||
], | ||
) | ||
def test_get_s3_bucket(path, bucket): | ||
assert file_util.get_s3_bucket(path) == bucket | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,file_key", | ||
[ | ||
("s3://bucket/folder/test.txt", "folder/test.txt"), | ||
("s3://bucket_x/file.csv", "file.csv"), | ||
("s3://bucket-y/folder/path/to/abc.zip", "folder/path/to/abc.zip"), | ||
("./folder/path", "/folder/path"), | ||
("sftp://folder/filename", "filename"), | ||
], | ||
) | ||
def test_get_s3_file_key(path, file_key): | ||
assert file_util.get_s3_file_key(path) == file_key | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,file_name", | ||
[ | ||
("s3://bucket/folder/test.txt", "test.txt"), | ||
("s3://bucket_x/file.csv", "file.csv"), | ||
("s3://bucket-y/folder/path/to/abc.zip", "abc.zip"), | ||
("./folder/path", "path"), | ||
("sftp://filename", "filename"), | ||
], | ||
) | ||
def test_get_s3_file_name(path, file_name): | ||
assert file_util.get_file_name(path) == file_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from src.util.string_utils import join_list | ||
|
||
|
||
def test_join_list(): | ||
assert join_list(None) == "" | ||
assert join_list(None, ",") == "" | ||
assert join_list(None, "|") == "" | ||
assert join_list([]) == "" | ||
assert join_list([], ",") == "" | ||
assert join_list([], "|") == "" | ||
|
||
assert join_list(["a", "b", "c"]) == "a\nb\nc" | ||
assert join_list(["a", "b", "c"], ",") == "a,b,c" | ||
assert join_list(["a", "b", "c"], "|") == "a|b|c" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of scope of this PR but why do we even have this function