Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/nbconvert/utils/_contextlib_chdir.py: 55%
11 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""Backport of Python 3.11's contextlib.chdir."""
4import os
5from contextlib import AbstractContextManager
8class chdir(AbstractContextManager): # noqa
9 """Non thread-safe context manager to change the current working directory."""
11 def __init__(self, path):
12 """Initialize the manager."""
13 self.path = path
14 self._old_cwd = []
16 def __enter__(self):
17 """Enter the context."""
18 self._old_cwd.append(os.getcwd())
19 os.chdir(self.path)
21 def __exit__(self, *excinfo):
22 """Exit the context."""
23 os.chdir(self._old_cwd.pop())