-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(floorist): RHICOMPL-2984 Bugfix for empty prefix floorplan
- Fix a bug for when floorplan file does not provide prefix - Add helper function for generating directory names - Add unit test coverage
- Loading branch information
1 parent
d522496
commit 6dd9d5e
Showing
8 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -16,3 +16,4 @@ python_requires = >=3.6, <4 | |
[options.extras_require] | ||
test = | ||
pytest | ||
pytest-mock |
This file contains 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 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,11 @@ | ||
from datetime import date | ||
|
||
|
||
def generate_name(bucket_name, prefix=None): | ||
|
||
file_name = date.today().strftime('year_created=%Y/month_created=%-m/day_created=%-d') | ||
parts = ["s3:/", bucket_name, file_name] | ||
if prefix: | ||
parts.insert(2, prefix) | ||
|
||
return '/'.join(parts) |
This file contains 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,2 @@ | ||
- query: SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter); | ||
prefix: some-prefix |
This file contains 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 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,28 @@ | ||
from floorist.floorist import main | ||
from floorist.config import Config | ||
|
||
|
||
def test_floorplan_without_prefix_is_handled_correctly(mocker): | ||
config_mock = mocker.patch('floorist.floorist.get_config') | ||
config_mock.return_value = Config(bucket_name='foo') | ||
awswrangler_mock = mocker.patch('floorist.floorist.wr') | ||
mocker.patch('floorist.floorist.create_engine') | ||
mocker.patch('floorist.floorist.open') | ||
mocker.patch('floorist.floorist.logging') | ||
safe_load_mock = mocker.patch('floorist.floorist.yaml.safe_load') | ||
safe_load_mock.return_value = [{'query': "a query", 'prefix': None}] | ||
pandas_mock = mocker.patch('floorist.floorist.pd') | ||
pandas_mock.read_sql.return_value = ["some-data"] | ||
helper_mock = mocker.patch("floorist.floorist.generate_name") | ||
helper_mock.return_value = "some-name" | ||
main() | ||
helper_mock.assert_called_with("foo", None) | ||
expected_kwargs = { | ||
"index" : False, | ||
"compression" : 'gzip', | ||
"dataset" : True, | ||
"mode" : 'append' | ||
} | ||
awswrangler_mock.s3.to_parquet.assert_called_with("some-data", "some-name", **expected_kwargs) | ||
|
||
|
This file contains 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,21 @@ | ||
from floorist.helpers import generate_name | ||
from datetime import date | ||
|
||
|
||
def test_name_without_prefix(): | ||
bucket_name = "my_bucket" | ||
actual_name = generate_name("my_bucket") | ||
name = date.today().strftime('year_created=%Y/month_created=%-m/day_created=%-d') | ||
expected_name = f"s3://{bucket_name}/{name}" | ||
|
||
assert actual_name == expected_name | ||
|
||
|
||
def test_name_with_prefix(): | ||
bucket_name = "my_bucket" | ||
prefix = "some-prefix" | ||
actual_name = generate_name(bucket_name, prefix) | ||
name = date.today().strftime('year_created=%Y/month_created=%-m/day_created=%-d') | ||
expected_name = f"s3://{bucket_name}/{prefix}/{name}" | ||
|
||
assert actual_name == expected_name |