MCPcopy Create free account
hub / github.com/celery/celery / open

Function open

t/unit/conftest.py:739–754  ·  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

737
738@contextmanager
739def open(side_effect=None):
740 """Patch builtins.open so that it returns StringIO object.
741 :param side_effect: Additional side effect for when the open context
742 is entered.
743 Example::
744 >>> with mock.open(io.BytesIO) as open_fh:
745 ... something_opening_and_writing_bytes_to_a_file()
746 ... self.assertIn(b'foo', open_fh.getvalue())
747 """
748 with patch('builtins.open') as open_:
749 with _mock_context(open_) as context:
750 if side_effect is not None:
751 context.__enter__.side_effect = side_effect
752 val = context.__enter__.return_value = WhateverIO()
753 val.__exit__ = Mock()
754 yield val
755
756
757@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
kill_child_process_onceFunction · 0.85

Calls 2

_mock_contextFunction · 0.85
WhateverIOClass · 0.70

Tested by

no test coverage detected