# Path: diagnostic_primers/scripts/tools.py
# class PDPScriptError(PDPException):
#     def __init__(self, msg="Error in `pdp` script"):
# def last_exception():
# def load_config_tab(args, logger):
# def load_config_json(args, logger):
# def log_clines(clines, logger):
# def run_parallel_jobs(clines, args, logger):
# def has_primersearch(coll):
# def create_output_directory(outdirname, force, logger):
# def chunk(iterable, size):
# def collect_existing_output(dirpath, step, args):


import logging
import os
import pytest
from argparse import Namespace
from diagnostic_primers.scripts import tools
from tools import PDPTestCase





class TestTools(PDPTestCase):

    """Class defining tests of the tools.py module."""

    def setUp(self):
        """Set parameters for tests."""
        self.datadir = os.path.join("tests", "test_input")
        self.fakejsonfile = os.path.join(self.datadir, "fakefile.json")
        self.fakescript = "./fakescript"

        # Null logger for nosetests
        self.logger = logging.getLogger("TestTools logger")
        self.logger.addHandler(logging.NullHandler())

    def test_loadjson_nologger(self):
        """loading nonexistent JSON file fails."""
        args = Namespace(infilename=self.fakejsonfile)
        with pytest.raises(SystemExit):
            tools.load_config_json(args, self.logger)

    def test_runparallel_mp_fail(self):
        """running nonexistent script fails."""
        args = Namespace(scheduler="multiprocessing", workers=1, verbose=False)
        clines = [" ".join([self.fakescript, "-arg1 %d"]) % val for val in range(4)]
        with pytest.raises(SystemExit):

# Path: diagnostic_primers/scripts/tools.py
# class PDPScriptError(PDPException):
#     def __init__(self, msg="Error in `pdp` script"):
# def last_exception():
# def load_config_tab(args, logger):
# def load_config_json(args, logger):
# def log_clines(clines, logger):
# def run_parallel_jobs(clines, args, logger):
# def has_primersearch(coll):
# def create_output_directory(outdirname, force, logger):
# def chunk(iterable, size):
# def collect_existing_output(dirpath, step, args):


# Path: tests/test_tools.py
import logging
import os
import pytest
from argparse import Namespace
from diagnostic_primers.scripts import tools
from tools import PDPTestCase






class TestTools(PDPTestCase):

    """Class defining tests of the tools.py module."""

    def setUp(self):
        """Set parameters for tests."""
        self.datadir = os.path.join("tests", "test_input")
        self.fakejsonfile = os.path.join(self.datadir, "fakefile.json")
        self.fakescript = "./fakescript"

        # Null logger for nosetests
        self.logger = logging.getLogger("TestTools logger")
        self.logger.addHandler(logging.NullHandler())

    def test_loadjson_nologger(self):
        """loading nonexistent JSON file fails."""
        args = Namespace(infilename=self.fakejsonfile)
        with pytest.raises(SystemExit):
            tools.load_config_json(args, self.logger)

    def test_runparallel_mp_fail(self):
        """running nonexistent script fails."""
        args = Namespace(scheduler="multiprocessing", workers=1, verbose=False)
        clines = [" ".join([self.fakescript, "-arg1 %d"]) % val for val in range(4)]
        with pytest.raises(SystemExit):

            tools.run_parallel_jobs(clines, args, self.logger)