# Path: compliance_checker/runner.py
# def stdout_redirector(stream):
#     def run_checker(
#         cls,
#         ds_loc,
#         checker_names,
#         verbose,
#         criteria,
#         skip_checks=None,
#         include_checks=None,
#         output_filename="-",
#         output_format=["text"],
#         options=None,
#     ):
#     def stdout_output(cls, cs, score_dict, verbose, limit):
#     def html_output(cls, cs, score_dict, output_filename, ds_loc, limit):
#     def json_output(
#         cls, cs, score_dict, output_filename, ds_loc, limit, output_type="json"
#     ):
#     def check_errors(cls, score_groups, verbose):
# class ComplianceChecker(object):
# 
# Path: compliance_checker/tests/conftest.py
# def static_files(cdl_stem):
#     """
#     Returns the Path to a valid nc dataset\n
#     replaces the old STATIC_FILES dict
#     """
#     datadir = Path(resource_filename("compliance_checker", "tests/data")).resolve()
#     assert datadir.exists(), f"{datadir} not found"
# 
#     cdl_paths = glob_down(datadir, f"{cdl_stem}.cdl", 3)
#     assert (
#         len(cdl_paths) > 0
#     ), f"No file named {cdl_stem}.cdl found in {datadir} or its subfolders"
#     assert (
#         len(cdl_paths) == 1
#     ), f"Multiple candidates found with the name {cdl_stem}.cdl:\n{cdl_paths}\nPlease reconcile naming conflict"
#     cdl_path = cdl_paths[0]  # PurePath object
# 
#     nc_path = cdl_path.parent / f"{cdl_path.stem}.nc"
#     if not nc_path.exists():
#         generate_dataset(cdl_path, nc_path)
#         assert (
#             nc_path.exists()
#         ), f"ncgen CLI utility failed to produce {nc_path} from {cdl_path}"
#     return str(nc_path)


import io
import json
import os
import sys
import pytest
from argparse import Namespace
from compliance_checker.runner import CheckSuite, ComplianceChecker
from .conftest import static_files
        # hack: use argparse.Namespace to mock checker object with attributes
        # since SimpleNamespace is Python 3.3+ only
        CheckSuite.checkers.clear()
        # need to mock setuptools entrypoints here in order to load in checkers
        def checker_1():
            return Namespace(name="checker_1")

        def checker_2():
            return Namespace(_cc_spec="checker_2", _cc_spec_version="2.2")

        mock_checkers = [Namespace(resolve=checker_1), Namespace(resolve=checker_2)]
        with pytest.warns(DeprecationWarning):
            CheckSuite._load_checkers(mock_checkers)

        cs = CheckSuite()
        saved = sys.stdout
        try:
            # ugly!  consider refactoring to use py.test capsys
            fake_stdout = io.StringIO()
            sys.stdout = fake_stdout
            cs._print_suites()
            assert fake_stdout.getvalue() == " - checker_1:unknown\n - checker_2:2.2\n"
        finally:
            sys.stdout = saved
            fake_stdout.close()

    def test_multiple_json_output(self, tmp_txt_file):
        """
        Tests that a suite can produce JSON output to a file
        """

# Path: compliance_checker/runner.py
# def stdout_redirector(stream):
#     def run_checker(
#         cls,
#         ds_loc,
#         checker_names,
#         verbose,
#         criteria,
#         skip_checks=None,
#         include_checks=None,
#         output_filename="-",
#         output_format=["text"],
#         options=None,
#     ):
#     def stdout_output(cls, cs, score_dict, verbose, limit):
#     def html_output(cls, cs, score_dict, output_filename, ds_loc, limit):
#     def json_output(
#         cls, cs, score_dict, output_filename, ds_loc, limit, output_type="json"
#     ):
#     def check_errors(cls, score_groups, verbose):
# class ComplianceChecker(object):
# 
# Path: compliance_checker/tests/conftest.py
# def static_files(cdl_stem):
#     """
#     Returns the Path to a valid nc dataset\n
#     replaces the old STATIC_FILES dict
#     """
#     datadir = Path(resource_filename("compliance_checker", "tests/data")).resolve()
#     assert datadir.exists(), f"{datadir} not found"
# 
#     cdl_paths = glob_down(datadir, f"{cdl_stem}.cdl", 3)
#     assert (
#         len(cdl_paths) > 0
#     ), f"No file named {cdl_stem}.cdl found in {datadir} or its subfolders"
#     assert (
#         len(cdl_paths) == 1
#     ), f"Multiple candidates found with the name {cdl_stem}.cdl:\n{cdl_paths}\nPlease reconcile naming conflict"
#     cdl_path = cdl_paths[0]  # PurePath object
# 
#     nc_path = cdl_path.parent / f"{cdl_path.stem}.nc"
#     if not nc_path.exists():
#         generate_dataset(cdl_path, nc_path)
#         assert (
#             nc_path.exists()
#         ), f"ncgen CLI utility failed to produce {nc_path} from {cdl_path}"
#     return str(nc_path)


# Path: compliance_checker/tests/test_cli.py
import io
import json
import os
import sys
import pytest
from argparse import Namespace
from compliance_checker.runner import CheckSuite, ComplianceChecker
from .conftest import static_files

        # hack: use argparse.Namespace to mock checker object with attributes
        # since SimpleNamespace is Python 3.3+ only
        CheckSuite.checkers.clear()
        # need to mock setuptools entrypoints here in order to load in checkers
        def checker_1():
            return Namespace(name="checker_1")

        def checker_2():
            return Namespace(_cc_spec="checker_2", _cc_spec_version="2.2")

        mock_checkers = [Namespace(resolve=checker_1), Namespace(resolve=checker_2)]
        with pytest.warns(DeprecationWarning):
            CheckSuite._load_checkers(mock_checkers)

        cs = CheckSuite()
        saved = sys.stdout
        try:
            # ugly!  consider refactoring to use py.test capsys
            fake_stdout = io.StringIO()
            sys.stdout = fake_stdout
            cs._print_suites()
            assert fake_stdout.getvalue() == " - checker_1:unknown\n - checker_2:2.2\n"
        finally:
            sys.stdout = saved
            fake_stdout.close()

    def test_multiple_json_output(self, tmp_txt_file):
        """
        Tests that a suite can produce JSON output to a file
        """

        return_value, errors = ComplianceChecker.run_checker(