-
-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnitTest: simplify sublime API mocking
- Loading branch information
Showing
1 changed file
with
10 additions
and
19 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,19 +1,10 @@ | ||
from sys import modules | ||
|
||
if "sublime" not in modules: | ||
import importlib.machinery | ||
import os | ||
|
||
PACKAGE_ROOT = os.path.dirname(__file__) | ||
|
||
# Mock the sublime module for CLI usage | ||
sublime = importlib.machinery.SourceFileLoader( | ||
"sublime", | ||
os.path.join(PACKAGE_ROOT, "mock_sublime.py") | ||
).load_module() | ||
|
||
# Mock the sublime_plugin module for CLI usage | ||
sublime_plugin = importlib.machinery.SourceFileLoader( | ||
"sublime_plugin", | ||
os.path.join(PACKAGE_ROOT, "mock_sublime_plugin.py") | ||
).load_module() | ||
# flake8: noqa: F401 | ||
try: | ||
import sublime | ||
except ImportError: | ||
# Mock the sublime API modules for CLI usage | ||
from sys import modules | ||
from . import mock_sublime | ||
from . import mock_sublime_plugin | ||
modules["sublime"] = mock_sublime | ||
modules["sublime_plugin"] = mock_sublime_plugin |