# Path: tests/integration_tests/throwing_plugin.py
# class InitThrowingPlugin(Plugin):
#     name = property(lambda self: "init_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(InitThrowingPlugin, self).__init__(job)
#         raise Exception("Exception in __init__")
# 
#     def process(self, nodemeta, timestamp, data, description):
#         pass
# 
#     def results(self):
#         pass
# 
# class ProcessThrowingPlugin(Plugin):
#     name = property(lambda self: "process_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(ProcessThrowingPlugin, self).__init__(job)
# 
#     def process(self, nodemeta, timestamp, data, description):
#         raise Exception("Exception in process")
# 
#     def results(self):
#         pass
# 
# class ResultsThrowingPlugin(Plugin):
#     name = property(lambda self: "results_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(ResultsThrowingPlugin, self).__init__(job)
# 
#     def process(self, nodemeta, timestamp, data, description):
#         return False
# 
#     def results(self):
#         raise Exception("Exception in results")


import sys
import pytest
from mock import patch
from supremm import summarize_jobs
from mock_preprocessor import MockPreprocessor
from tests.integration_tests.throwing_plugin import InitThrowingPlugin, ProcessThrowingPlugin, ResultsThrowingPlugin



@pytest.mark.parametrize("threads", [1, 3])
def test_plugin_api(threads):
    test_args = "summarize_jobs.py -d -r 2 -j 972366 --fail-fast --threads {}".format(threads).split()
    preprocs = [MockPreprocessor]
    plugins = []
    # this was very non-obvious to me but since summarize_jobs does "from supremm.plugin import loadpreprocs"
    # you have to patch loadpreprocs as if it was in the summarize_jobs module

# Path: tests/integration_tests/throwing_plugin.py
# class InitThrowingPlugin(Plugin):
#     name = property(lambda self: "init_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(InitThrowingPlugin, self).__init__(job)
#         raise Exception("Exception in __init__")
# 
#     def process(self, nodemeta, timestamp, data, description):
#         pass
# 
#     def results(self):
#         pass
# 
# class ProcessThrowingPlugin(Plugin):
#     name = property(lambda self: "process_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(ProcessThrowingPlugin, self).__init__(job)
# 
#     def process(self, nodemeta, timestamp, data, description):
#         raise Exception("Exception in process")
# 
#     def results(self):
#         pass
# 
# class ResultsThrowingPlugin(Plugin):
#     name = property(lambda self: "results_throwing_plugin")
#     mode = property(lambda self: "timeseries")
#     requiredMetrics = property(lambda self: ["hinv.ncpu", "gpfs.fsios.read_bytes"])
#     optionalMetrics = property(lambda self: [])
#     derivedMetrics = property(lambda self: [])
# 
#     def __init__(self, job):
#         super(ResultsThrowingPlugin, self).__init__(job)
# 
#     def process(self, nodemeta, timestamp, data, description):
#         return False
# 
#     def results(self):
#         raise Exception("Exception in results")


# Path: tests/integration_tests/integration_plugin_api.py
import sys
import pytest
from mock import patch
from supremm import summarize_jobs
from mock_preprocessor import MockPreprocessor
from tests.integration_tests.throwing_plugin import InitThrowingPlugin, ProcessThrowingPlugin, ResultsThrowingPlugin




@pytest.mark.parametrize("threads", [1, 3])
def test_plugin_api(threads):
    test_args = "summarize_jobs.py -d -r 2 -j 972366 --fail-fast --threads {}".format(threads).split()
    preprocs = [MockPreprocessor]
    plugins = []
    # this was very non-obvious to me but since summarize_jobs does "from supremm.plugin import loadpreprocs"
    # you have to patch loadpreprocs as if it was in the summarize_jobs module

    with patch.object(sys, "argv", test_args), patch("supremm.summarize_jobs.loadpreprocessors",  return_value=preprocs), patch("supremm.summarize_jobs.loadplugins", return_value=plugins):