-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
d30c260
commit a15c2d9
Showing
1 changed file
with
9 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
import functools | ||
|
||
try: | ||
builtin_import = __builtins__.__import__ | ||
except AttributeError: | ||
builtin_import = __builtins__['__import__'] | ||
builtin_import = __builtins__["__import__"] | ||
|
||
|
||
def _fake_import(name, globals=None, locals=None, fromlist=(), level=0): | ||
if name == 'ctypes': | ||
if name == "ctypes": | ||
try: | ||
ModuleNotFoundError | ||
except NameError: | ||
ModuleNotFoundError = ImportError | ||
raise ModuleNotFoundError('No module named %s' % name) | ||
raise ModuleNotFoundError("No module named %s" % name) | ||
return builtin_import(name, globals, locals, fromlist, level) | ||
|
||
|
||
def mock_import(func): | ||
@functools.wraps(func) | ||
def wrap(*args, **kwargs): | ||
import builtins | ||
|
||
try: | ||
builtins.__import__ = _fake_import | ||
return func(*args, **kwargs) | ||
finally: | ||
builtins.__import__ = builtin_import | ||
|
||
return wrap | ||
|
||
|
||
@mock_import | ||
def test_ctypes_not_installed(): | ||
from platformdirs import windows | ||
def test_ctypes_not_installed() -> None: | ||
pass |