MCPcopy
hub / github.com/celery/celery / open

Function open

t/unit/conftest.py:718–733  ·  view source on GitHub ↗

Patch builtins.open so that it returns StringIO object. :param side_effect: Additional side effect for when the open context is entered. Example:: >>> with mock.open(io.BytesIO) as open_fh: ... something_opening_and_writing_bytes_to_a_file() ... self.a

(side_effect=None)

Source from the content-addressed store, hash-verified

716
717@contextmanager
718def open(side_effect=None):
719 """Patch builtins.open so that it returns StringIO object.
720 :param side_effect: Additional side effect for when the open context
721 is entered.
722 Example::
723 >>> with mock.open(io.BytesIO) as open_fh:
724 ... something_opening_and_writing_bytes_to_a_file()
725 ... self.assertIn(b'foo', open_fh.getvalue())
726 """
727 with patch('builtins.open') as open_:
728 with _mock_context(open_) as context:
729 if side_effect is not None:
730 context.__enter__.side_effect = side_effect
731 val = context.__enter__.return_value = WhateverIO()
732 val.__exit__ = Mock()
733 yield val
734
735
736@contextmanager

Callers 15

parse_dist_metaFunction · 0.85
_reqsFunction · 0.85
find_missing_authorsFunction · 0.85
assert_generatorMethod · 0.85
celery_configFunction · 0.85
class_certsMethod · 0.85
test_sphinxFunction · 0.85
read_changes_fileFunction · 0.85
read_pidMethod · 0.85
write_pidMethod · 0.85

Calls 2

_mock_contextFunction · 0.85
WhateverIOClass · 0.70

Tested by

no test coverage detected