-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from wednesday-solutions/fix/mypy-type
Feat: Test Cases Added
- Loading branch information
Showing
16 changed files
with
175 additions
and
29 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.env | ||
.coverage | ||
app/__pycache__ | ||
app/tests/__pycache__ | ||
*__pycache__ | ||
temp | ||
htmlcov |
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
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
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,6 @@ | ||
mypy~=1.7.1 | ||
pylint~=3.0.2 | ||
coverage~=7.3.2 | ||
python-dotenv~=1.0.0 | ||
kaggle~=1.5.16 | ||
pre-commit~=3.6.0 |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,74 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from app.Extraction import extract_from_kaggle | ||
|
||
|
||
class TestExtraction(unittest.TestCase): | ||
@patch("app.Extraction.kaggle") | ||
def test_extract_from_kaggle_success(self, mock_kaggle): | ||
mock_kaggle_instance = mock_kaggle | ||
mock_api_instance = mock_kaggle_instance.KaggleApi.return_value | ||
# Mocking authenticate and dataset_download_cli methods | ||
mock_api_instance.authenticate.return_value = None | ||
mock_api_instance.dataset_download_cli.return_value = None | ||
|
||
# Call the function to test with flag=True for success case | ||
result = extract_from_kaggle(True) | ||
|
||
# Assertions | ||
mock_kaggle_instance.KaggleApi.assert_called_once() | ||
mock_api_instance.authenticate.assert_called_once() | ||
mock_api_instance.dataset_download_cli.assert_called_once_with( | ||
"mastmustu/insurance-claims-fraud-data", | ||
unzip=True, | ||
path="/dbfs/mnt/rawdata/", | ||
) | ||
|
||
self.assertEqual(result, ("/mnt/rawdata/", "/mnt/transformed/")) | ||
|
||
@patch("app.Extraction.kaggle") | ||
def test_extract_from_kaggle_success_false(self, mock_kaggle): | ||
mock_kaggle_instance = mock_kaggle | ||
mock_api_instance = mock_kaggle_instance.KaggleApi.return_value | ||
# Mocking authenticate and dataset_download_cli methods | ||
mock_api_instance.authenticate.return_value = None | ||
mock_api_instance.dataset_download_cli.return_value = None | ||
|
||
# Call the function to test with flag=True for success case | ||
result = extract_from_kaggle(False) | ||
|
||
# Assertions | ||
mock_kaggle_instance.KaggleApi.assert_called_once() | ||
mock_api_instance.authenticate.assert_called_once() | ||
mock_api_instance.dataset_download_cli.assert_called_once_with( | ||
"mastmustu/insurance-claims-fraud-data", unzip=True, path="temp/" | ||
) | ||
|
||
self.assertEqual( | ||
result, | ||
( | ||
"s3://glue-bucket-vighnesh/rawdata/", | ||
"s3://glue-bucket-vighnesh/transformed/", | ||
), | ||
) | ||
|
||
@patch("app.Extraction.kaggle") | ||
def test_extract_from_kaggle_failure(self, mock_kaggle): | ||
mock_kaggle_instance = mock_kaggle | ||
mock_api_instance = mock_kaggle_instance.KaggleApi.return_value | ||
# Mocking authenticate and dataset_download_cli methods | ||
mock_api_instance.authenticate.side_effect = Exception( | ||
"Simulated authentication failure" | ||
) | ||
|
||
# Call the function to test with flag=False for failure case | ||
with self.assertRaises(Exception) as context: | ||
extract_from_kaggle(False) | ||
|
||
# Assertions | ||
mock_kaggle_instance.KaggleApi.assert_called_once() | ||
mock_api_instance.authenticate.assert_called_once() | ||
mock_api_instance.dataset_download_cli.assert_not_called() | ||
|
||
# Check if the correct exception is raised | ||
self.assertEqual(str(context.exception), "Simulated authentication failure") |
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
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,52 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from app.connect_glue import init_glue | ||
|
||
|
||
class TestInitGlue(unittest.TestCase): | ||
@patch("app.connect_glue.SparkContext") | ||
@patch("app.connect_glue.GlueContext") | ||
@patch("app.connect_glue.Job") | ||
def test_init_glue(self, mock_job, mock_glue_context, mock_spark_context): | ||
# Mock the SparkContext, GlueContext, and Job | ||
mock_spark_context_instance = MagicMock() | ||
mock_glue_context_instance = MagicMock() | ||
mock_job_instance = MagicMock() | ||
|
||
# Set up the behavior of the mock instances | ||
mock_spark_context.return_value = mock_spark_context_instance | ||
mock_glue_context.return_value = mock_glue_context_instance | ||
mock_job.return_value = mock_job_instance | ||
|
||
# Call the function to test | ||
glue_context, spark, job = init_glue() | ||
|
||
# Assertions | ||
mock_spark_context.assert_called_once() | ||
mock_glue_context.assert_called_once_with(mock_spark_context_instance) | ||
mock_job.assert_called_once_with(mock_glue_context_instance) | ||
|
||
# Check if the returned values are correct | ||
self.assertEqual(glue_context, mock_glue_context_instance) | ||
self.assertEqual(spark, mock_glue_context_instance.spark_session) | ||
self.assertEqual(job, mock_job_instance) | ||
|
||
@patch("app.connect_glue.SparkContext") | ||
@patch("app.connect_glue.GlueContext") | ||
@patch("app.connect_glue.Job") | ||
def test_init_glue_failure(self, mock_job, mock_glue_context, mock_spark_context): | ||
# Simulate a ValueError during SparkContext initialization | ||
error_statement = "Simulated SparkContext initialization failure" | ||
mock_spark_context.side_effect = ValueError(error_statement) | ||
|
||
# Call the function to test | ||
with self.assertRaises(ValueError) as context: | ||
init_glue() | ||
|
||
# Assertions | ||
mock_spark_context.assert_called_once() | ||
mock_glue_context.assert_not_called() # GlueContext should not be called if SparkContext initialization fails | ||
mock_job.assert_not_called() # Job should not be called if SparkContext initialization fails | ||
|
||
# Check if the error displayed correctly | ||
self.assertEqual(str(context.exception), error_statement) |