Skip to content

Commit

Permalink
Simplify test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Nov 23, 2023
1 parent 9fad5e5 commit 38b7b34
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Empty file added compiled_tests/__init__.py
Empty file.
14 changes: 2 additions & 12 deletions compiled_tests/test_compiled_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import tempfile
import types

import build
import _compiled__init__ as compiled_cli

TEST_SOURCE = r"""
import sys
Expand Down Expand Up @@ -60,24 +62,12 @@ def foo():
print("Similar hashes:", hash, match)
"""


def import_from_root(filename: str) -> types.ModuleType:
root_dir = os.path.dirname(os.path.dirname(__file__))
module_path = os.path.join(root_dir, filename)
spec = importlib.util.spec_from_file_location(filename, module_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def test_cli():
test_file = os.path.join(tempfile.gettempdir(), "test_file.py")
with open(test_file, "w") as file:
file.write(TEST_SOURCE)

# patch the replaceable modules by putting the values from `build.py`
build = import_from_root("build.py")
compiled_cli = import_from_root("_compiled__init__.py")
compiled_cli.REPLACEABLE_MODULES = build.SUPPORTED_LIBRARIES

try:
Expand Down

0 comments on commit 38b7b34

Please sign in to comment.