You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prompt Category:
Unit Testing
Prompt:
================================================ test session starts ================================================
platform darwin -- Python 3.9.6, pytest-8.3.5, pluggy-1.5.0 -- /Library/Developer/CommandLineTools/usr/bin/python3
cachedir: .pytest_cache
rootdir: /Users/surya.sandeep.boda/Desktop/Marscode Zero to One 3
plugins: cov-6.0.0
collected 7 items
test_extract_data.py::TestGoogleSheetExtraction::test_clear_target_sheet_failure PASSED [ 14%]
test_extract_data.py::TestGoogleSheetExtraction::test_clear_target_sheet_success FAILED [ 28%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_api_error PASSED [ 42%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_no_data PASSED [ 57%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_success PASSED [ 71%]
test_extract_data.py::TestGoogleSheetExtraction::test_write_to_target_sheet_failure PASSED [ 85%]
test_extract_data.py::TestGoogleSheetExtraction::test_write_to_target_sheet_success FAILED [100%]
===================================================== FAILURES ======================================================
_____________________________ TestGoogleSheetExtraction.test_clear_target_sheet_success _____________________________
self = <test_extract_data.TestGoogleSheetExtraction testMethod=test_clear_target_sheet_success>
mock_build = <MagicMock name='build' id='4682958544'>
mock_credentials = <MagicMock name='Credentials' id='4683027984'>
@patch('extract_data.Credentials')
@patch('extract_data.build')
def test_clear_target_sheet_success(self, mock_build, mock_credentials):
# Setup mock
mock_service = MagicMock()
mock_build.return_value = mock_service
mock_service.spreadsheets().values().clear().execute.return_value = {}
# Execute
result = clear_target_sheet()
# Assert
self.assertIsNotNone(result)
> mock_service.spreadsheets().values().clear.assert_called_once()
test_extract_data.py:21:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='build().spreadsheets().values().clear' id='4683133088'>
def assert_called_once(self):
"""assert that the mock was called only once.
"""
if not self.call_count == 1:
msg = ("Expected '%s' to have been called once. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'clear' to have been called once. Called 2 times.
E Calls: [call(),
E call(spreadsheetId='1FEqiDqqPfb9YHAWBiqVepmmXj22zNqXNNI7NLGCDVak', range='Sheet1!A:Z'),
E call().execute()].
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/unittest/mock.py:886: AssertionError
___________________________ TestGoogleSheetExtraction.test_write_to_target_sheet_success ____________________________
self = <test_extract_data.TestGoogleSheetExtraction testMethod=test_write_to_target_sheet_success>
def test_write_to_target_sheet_success(self):
# Setup test data
df = pd.DataFrame({
'Email Address': ['[email protected]'],
'Tool being used': ['Tool1'],
'Feature used': ['Feature1'],
'Context Awareness': [4.0],
'Autonomy': [4.0],
'Experience': [4.0],
'Output Quality': [4.0],
'Overall Rating': [4.0],
'Mean Rating': [4.0],
'Difference': [0.0],
'Result': ['Ok'],
'Unique ID': ['ID1']
})
mock_service = MagicMock()
mock_service.spreadsheets().values().update().execute.return_value = {}
mock_service.spreadsheets().batchUpdate().execute.return_value = {}
# Execute
result = write_to_target_sheet(df, mock_service)
# Assert
self.assertTrue(result)
> mock_service.spreadsheets().values().update.assert_called_once()
test_extract_data.py:63:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='mock.spreadsheets().values().update' id='4684074672'>
def assert_called_once(self):
"""assert that the mock was called only once.
"""
if not self.call_count == 1:
msg = ("Expected '%s' to have been called once. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'update' to have been called once. Called 2 times.
E Calls: [call(),
E call(spreadsheetId='1FEqiDqqPfb9YHAWBiqVepmmXj22zNqXNNI7NLGCDVak', range='Sheet1!A1', valueInputOption='USER_ENTERED', body={'values': [['Email Address', 'Tool being used', 'Feature used', 'Context Awareness', 'Autonomy', 'Experience', 'Output Quality', 'Overall Rating', 'Mean Rating', 'Difference', 'Result', 'Unique ID'], ['[email protected]', 'Tool1', 'Feature1', '4.00', '4.00', '4.00', '4.00', '4.00', '4.00', '0.00', 'Ok', 'ID1']], 'majorDimension': 'ROWS'}),
E call().execute()].
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/unittest/mock.py:886: AssertionError
================================================= warnings summary ==================================================
test_extract_data.py:3
/Users/surya.sandeep.boda/Desktop/Marscode Zero to One 3/test_extract_data.py:3: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at pandas-dev/pandas#54466
import pandas as pd
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
---------- coverage: platform darwin, python 3.9.6-final-0 -----------
Name Stmts Miss Cover
-------------------------------------
extract_data.py 119 17 86%
-------------------------------------
TOTAL 119 17 86%
============================================== short test summary info ==============================================
FAILED test_extract_data.py::TestGoogleSheetExtraction::test_clear_target_sheet_success - AssertionError: Expected 'clear' to have been called once. Called 2 times.
FAILED test_extract_data.py::TestGoogleSheetExtraction::test_write_to_target_sheet_success - AssertionError: Expected 'update' to have been called once. Called 2 times.
====================================== 2 failed, 5 passed, 1 warning in 0.57s =======================================
Fix the unit test errors
User Observation:
$ python3 -m pytest test_extract_data.py -v --cov=extract_data
================================================ test session starts ================================================
platform darwin -- Python 3.9.6, pytest-8.3.5, pluggy-1.5.0 -- /Library/Developer/CommandLineTools/usr/bin/python3
cachedir: .pytest_cache
rootdir: /Users/surya.sandeep.boda/Desktop/Marscode Zero to One 3
plugins: cov-6.0.0
collected 6 items
test_extract_data.py::TestGoogleSheetExtraction::test_clear_target_sheet_success PASSED [ 16%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_api_error PASSED [ 33%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_no_data PASSED [ 50%]
test_extract_data.py::TestGoogleSheetExtraction::test_get_google_sheet_data_success PASSED [ 66%]
test_extract_data.py::TestGoogleSheetExtraction::test_write_to_target_sheet_failure PASSED [ 83%]
test_extract_data.py::TestGoogleSheetExtraction::test_write_to_target_sheet_success PASSED [100%]
================================================= warnings summary ==================================================
test_extract_data.py:3
/Users/surya.sandeep.boda/Desktop/Marscode Zero to One 3/test_extract_data.py:3: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at pandas-dev/pandas#54466
import pandas as pd
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
---------- coverage: platform darwin, python 3.9.6-final-0 -----------
Name Stmts Miss Cover
-------------------------------------
extract_data.py 119 20 83%
-------------------------------------
TOTAL 119 20 83%
=========================================== 6 passed, 1 warning in 0.41s ============================================
Response ID:
d1c2b2d7-0d99-4f95-ab3d-04d88548a101
0 commit comments