I am trying to enjoy the ridicule of Python, and I am tripping over to mock the next function.
helpers.py
from path import Path
def sanitize_line_ending(filename):
""" Converts the line endings of the file to the line endings
of the current system.
"""
input_path = Path(filename)
with input_path.in_place() as (reader, writer):
for line in reader:
writer.write(line)
test_helpers.py
@mock.patch('downloader.helpers.Path')
def test_sanitize_line_endings(self, mock_path):
mock_path.in_place.return_value = (1,2)
helpers.sanitize_line_ending('varun.txt')
However, I constantly get the following error:
ValueError: need more than 0 values to unpack
Given that I set the return value as a tuple, I do not understand why Python cannot unpack it.
Then I changed my code to test_sanitize_line_endingssave the print return value input_path.in_place(), and I see that the return value is an object MagicMock. In particular, it prints something like
<MagicMock name='Path().in_place()' id='13023525345'>
If I understand correctly, I want mock_pathMagicMock, which has an in_place function that returns a tuple.
What am I doing wrong, and how can I correctly replace the return value input_path.in_place()in sanitize_line_ending.