Skip to content

Commit

Permalink
UnitTest: simplify sublime API mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 19, 2024
1 parent ed3d966 commit d4b43a7
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions package_control/tests/__init__.py
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

0 comments on commit d4b43a7

Please sign in to comment.