Skip to content

Commit

Permalink
Remove deprecated load_module, import from project folder
Browse files Browse the repository at this point in the history
  • Loading branch information
benjwadams committed Jul 16, 2024
1 parent 8d1cca0 commit c967e85
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions compliance_checker/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
from argparse import Namespace
from collections import defaultdict
import importlib.util
from importlib.machinery import SourceFileLoader

import pytest
Expand Down Expand Up @@ -276,12 +277,17 @@ def test_nczarr_pass_through(self, zarr_url):
def test_parse_options():
"""Test the option parser of cchecker.py"""
# Load cchecker.py
cchecker = SourceFileLoader("cchecker", shutil.which("cchecker.py")).load_module()
cchecker_file_path = os.path.join(os.path.dirname(__file__), "..", "..",
"cchecker.py")
spec = importlib.util.spec_from_file_location("cchecker",
cchecker_file_path)
module = importlib.util.module_from_spec(spec)
SourceFileLoader(spec.name, spec.origin).exec_module(module)
# Simple test checker_type:checker_opt
opt_dict = cchecker.parse_options(["cf:enable_appendix_a_checks"])
opt_dict = module.parse_options(["cf:enable_appendix_a_checks"])
assert opt_dict == defaultdict(dict, {"cf": {"enable_appendix_a_checks": None}})
# Test case checker_type:checker_opt:checker_val
opt_dict = cchecker.parse_options(
opt_dict = module.parse_options(
["type:opt:val", "type:opt2:val:2", "cf:enable_appendix_a_checks"],
)
assert opt_dict == defaultdict(
Expand Down

0 comments on commit c967e85

Please sign in to comment.