Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/jedi/common.py: 27%
15 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-20 06:09 +0000
1from contextlib import contextmanager
4@contextmanager
5def monkeypatch(obj, attribute_name, new_value):
6 """
7 Like pytest's monkeypatch, but as a value manager.
8 """
9 old_value = getattr(obj, attribute_name)
10 try:
11 setattr(obj, attribute_name, new_value)
12 yield
13 finally:
14 setattr(obj, attribute_name, old_value)
17def indent_block(text, indention=' '):
18 """This function indents a text block with a default of four spaces."""
19 temp = ''
20 while text and text[-1] == '\n':
21 temp += text[-1]
22 text = text[:-1]
23 lines = text.split('\n')
24 return '\n'.join(map(lambda s: indention + s, lines)) + temp