# Path: lava_dispatcher/action.py
# class TestError(LAVAError):
#     """
#     An error in the operation of the test definition, e.g.
#     in parsing measurements or commands which fail.
#     Always ensure TestError is caught, logged and cleared. It is not fatal.
#     """
#     error_help = "TestError: A test failed to run, look at the error message."
#     error_type = "Test"
# 
# class JobError(LAVAError):
#     """
#     An Error arising from the information supplied as part of the TestJob
#     e.g. HTTP404 on a file to be downloaded as part of the preparation of
#     the TestJob or a download which results in a file which tar or gzip
#     does not recognise.
#     """
#     error_help = "JobError: Your job cannot terminate cleanly."
#     error_type = "Job"
# 
# Path: lava_dispatcher/test/test_basic.py
# class StdoutTestCase(unittest.TestCase):  # pylint: disable=too-many-public-methods
# 
#     def setUp(self):
#         super(StdoutTestCase, self).setUp()
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
#         # set to True to update pipeline_references automatically.
#         self.update_ref = False
#         self.job = None
# 
#     def pipeline_reference(self, filename, job=None):
#         y_file = os.path.join(os.path.dirname(__file__), 'pipeline_refs', filename)
#         if self.update_ref:
#             if not job:
#                 job = self.job
#             sys.stderr.write('WARNING: modifying pipeline references!')
#             with open(y_file, 'w') as describe:
#                 yaml.dump(job.pipeline.describe(False), describe)
#         with open(y_file, 'r') as f_ref:
#             return yaml.load(f_ref)
# 
# class Factory(object):
#     """
#     Not Model based, this is not a Django factory.
#     Factory objects are dispatcher based classes, independent
#     of any database objects.
#     """
# 
#     def __init__(self):
#         logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#         logger = logging.getLogger('unittests')
#         logger.disabled = True
#         logger.propagate = False
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
# 
#     def create_fake_qemu_job(self):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/basics.yaml')
#         parser = JobParser()
#         try:
#             with open(sample_job_file) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#         except LAVAError:
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
#     def create_kvm_job(self, filename):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
#         parser = JobParser()
#         try:
#             with open(kvm_yaml) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#             job.logger = DummyLogger()
#         except LAVAError as exc:
#             print(exc)
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
# Path: lava_dispatcher/test/test_multi.py
# class TestMultiDeploy(StdoutTestCase):
#     class FakeDevice(NewDevice):
#     class TestDeploy(object):  # cannot be a subclass of Deployment without a full select function.
#     class TestDeployAction(DeployAction):
#     class TestJob(Job):
# class TestMultiDefinition(StdoutTestCase):  # pylint: disable=too-many-public-methods
# class TestMultiUBoot(StdoutTestCase):  # pylint: disable=too-many-public-methods
#     def setUp(self):
#         def check_config(self, job):
#         def __init__(self):
#         def __init__(self, parent, parameters, job):
#         def validate(self):
#         def run(self, connection, max_end_time, args=None):
#         def __init__(self):
#     def test_multi_deploy(self):
#     def setUp(self):
#     def test_multidefinition(self):
#     def setUp(self):
#     def test_multi_uboot(self):


import re
import os
import yaml
import decimal
from lava_dispatcher.action import TestError, JobError
from lava_dispatcher.test.test_basic import StdoutTestCase, Factory
from lava_dispatcher.test.test_multi import DummyLogger
# LAVA Dispatcher is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along
# with this program; if not, see <http://www.gnu.org/licenses>.



class FakeConnection(object):  # pylint: disable=too-few-public-methods

    def __init__(self, match):
        self.match = match


class TestPatterns(StdoutTestCase):

    def setUp(self):
        super(TestPatterns, self).setUp()
        self.testdef = os.path.join(os.path.dirname(__file__), 'testdefs', 'params.yaml')
        self.res_data = os.path.join(os.path.dirname(__file__), 'testdefs', 'result-data.txt')
        factory = Factory()
        self.job = factory.create_kvm_job("sample_jobs/kvm.yaml")
        self.job.logger = DummyLogger()
        self.job.validate()
        self.ret = False
        test_retry = [action for action in self.job.pipeline.actions if action.name == 'lava-test-retry'][0]
        self.test_shell = [action for action in test_retry.internal_pipeline.actions if action.name == 'lava-test-shell'][0]

# Path: lava_dispatcher/action.py
# class TestError(LAVAError):
#     """
#     An error in the operation of the test definition, e.g.
#     in parsing measurements or commands which fail.
#     Always ensure TestError is caught, logged and cleared. It is not fatal.
#     """
#     error_help = "TestError: A test failed to run, look at the error message."
#     error_type = "Test"
# 
# class JobError(LAVAError):
#     """
#     An Error arising from the information supplied as part of the TestJob
#     e.g. HTTP404 on a file to be downloaded as part of the preparation of
#     the TestJob or a download which results in a file which tar or gzip
#     does not recognise.
#     """
#     error_help = "JobError: Your job cannot terminate cleanly."
#     error_type = "Job"
# 
# Path: lava_dispatcher/test/test_basic.py
# class StdoutTestCase(unittest.TestCase):  # pylint: disable=too-many-public-methods
# 
#     def setUp(self):
#         super(StdoutTestCase, self).setUp()
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
#         # set to True to update pipeline_references automatically.
#         self.update_ref = False
#         self.job = None
# 
#     def pipeline_reference(self, filename, job=None):
#         y_file = os.path.join(os.path.dirname(__file__), 'pipeline_refs', filename)
#         if self.update_ref:
#             if not job:
#                 job = self.job
#             sys.stderr.write('WARNING: modifying pipeline references!')
#             with open(y_file, 'w') as describe:
#                 yaml.dump(job.pipeline.describe(False), describe)
#         with open(y_file, 'r') as f_ref:
#             return yaml.load(f_ref)
# 
# class Factory(object):
#     """
#     Not Model based, this is not a Django factory.
#     Factory objects are dispatcher based classes, independent
#     of any database objects.
#     """
# 
#     def __init__(self):
#         logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#         logger = logging.getLogger('unittests')
#         logger.disabled = True
#         logger.propagate = False
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
# 
#     def create_fake_qemu_job(self):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/basics.yaml')
#         parser = JobParser()
#         try:
#             with open(sample_job_file) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#         except LAVAError:
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
#     def create_kvm_job(self, filename):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
#         parser = JobParser()
#         try:
#             with open(kvm_yaml) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#             job.logger = DummyLogger()
#         except LAVAError as exc:
#             print(exc)
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
# Path: lava_dispatcher/test/test_multi.py
# class TestMultiDeploy(StdoutTestCase):
#     class FakeDevice(NewDevice):
#     class TestDeploy(object):  # cannot be a subclass of Deployment without a full select function.
#     class TestDeployAction(DeployAction):
#     class TestJob(Job):
# class TestMultiDefinition(StdoutTestCase):  # pylint: disable=too-many-public-methods
# class TestMultiUBoot(StdoutTestCase):  # pylint: disable=too-many-public-methods
#     def setUp(self):
#         def check_config(self, job):
#         def __init__(self):
#         def __init__(self, parent, parameters, job):
#         def validate(self):
#         def run(self, connection, max_end_time, args=None):
#         def __init__(self):
#     def test_multi_deploy(self):
#     def setUp(self):
#     def test_multidefinition(self):
#     def setUp(self):
#     def test_multi_uboot(self):


# Path: lava_dispatcher/test/test_test_shell.py
import re
import os
import yaml
import decimal
from lava_dispatcher.action import TestError, JobError
from lava_dispatcher.test.test_basic import StdoutTestCase, Factory
from lava_dispatcher.test.test_multi import DummyLogger

# LAVA Dispatcher is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along
# with this program; if not, see <http://www.gnu.org/licenses>.



class FakeConnection(object):  # pylint: disable=too-few-public-methods

    def __init__(self, match):
        self.match = match


class TestPatterns(StdoutTestCase):

    def setUp(self):
        super(TestPatterns, self).setUp()
        self.testdef = os.path.join(os.path.dirname(__file__), 'testdefs', 'params.yaml')
        self.res_data = os.path.join(os.path.dirname(__file__), 'testdefs', 'result-data.txt')
        factory = Factory()
        self.job = factory.create_kvm_job("sample_jobs/kvm.yaml")
        self.job.logger = DummyLogger()
        self.job.validate()
        self.ret = False
        test_retry = [action for action in self.job.pipeline.actions if action.name == 'lava-test-retry'][0]
        self.test_shell = [action for action in test_retry.internal_pipeline.actions if action.name == 'lava-test-shell'][0]

        self.test_shell.logger = DummyLogger()