# Path: tests/testlib.py
# class NoRestartRequiredError(Exception):
# class WaitTimedOutError(Exception):
# class SDKTestCase(unittest.TestCase):
# def to_bool(x):
# def tmpname():
# def wait(predicate, timeout=60, pause_time=0.5):
#     def assertEventuallyTrue(self, predicate, timeout=30, pause_time=0.5,
#                              timeout_message="Operation timed out."):
#     def check_content(self, entity, **kwargs):
#     def check_entity(self, entity):
#     def clear_restart_message(self):
#     def fake_splunk_version(self, version):
#     def install_app_from_collection(self, name):
#     def app_collection_installed(self):
#     def pathInApp(self, appName, pathComponents):
#     def uncheckedRestartSplunk(self, timeout=240):
#     def restartSplunk(self, timeout=240):
#     def setUpClass(cls):
#     def setUp(self):
#     def tearDown(self):
# 
# Path: splunklib/binding.py
# def _log_duration(f):
#     @wraps(f)
#     def new_f(*args, **kwargs):
#         start_time = datetime.now()
#         val = f(*args, **kwargs)
#         end_time = datetime.now()
#         logging.debug("Operation took %s", end_time-start_time)
#         return val
#     return new_f
# 
# class HTTPError(Exception):
#     """This exception is raised for HTTP responses that return an error."""
#     def __init__(self, response, _message=None):
#         status = response.status
#         reason = response.reason
#         body = response.body.read()
#         try:
#             detail = XML(body).findtext("./messages/msg")
#         except ParseError as err:
#             detail = body
#         message = "HTTP %d %s%s" % (
#             status, reason, "" if detail is None else " -- %s" % detail)
#         Exception.__init__(self, _message or message)
#         self.status = status
#         self.reason = reason
#         self.headers = response.headers
#         self.body = body
#         self._response = response


from io import BytesIO
from time import sleep
from tests import testlib
from splunklib.binding import _log_duration, HTTPError
        from datetime import datetime
                    from collections import OrderedDict
                    from splunklib.ordereddict import OrderedDict
                    from collections import OrderedDict
                    from splunklib.ordereddict import OrderedDict
import io
    import unittest2 as unittest
    import unittest
import splunklib.client as client
import splunklib.results as results
import pytest
        import splunklib.client as client
        import splunklib.results as results
        import splunklib.results as results
        import splunklib.client as client
        import splunklib.results as results
        import splunklib.client as client
        import splunklib.results as results
            earliest_time="-1m",
            priority=5,
            latest_time="now")

        # Note: You can only *decrease* the priority (i.e., 5 decreased to 3) of
        # a job unless Splunk is running as root. This is because Splunk jobs
        # are tied up with operating system processes and their priorities.

        if self.service._splunk_version[0] < 6:
            # BUG: Splunk 6 doesn't return priority until job is ready
            old_priority = int(self.job.content['priority'])
            self.assertEqual(5, old_priority)

        new_priority = 3
        self.job.set_priority(new_priority)

        if self.service._splunk_version[0] > 5:
            # BUG: Splunk 6 doesn't return priority until job is ready
            while not self.job.is_ready():
                pass

        def f():
            if self.job.is_done():
                self.fail("Job already done before priority was set.")
            return int(self.job.content['priority']) == new_priority

        self.assertEventuallyTrue(f, timeout=sleep_duration + 5)
        return



# Path: tests/testlib.py
# class NoRestartRequiredError(Exception):
# class WaitTimedOutError(Exception):
# class SDKTestCase(unittest.TestCase):
# def to_bool(x):
# def tmpname():
# def wait(predicate, timeout=60, pause_time=0.5):
#     def assertEventuallyTrue(self, predicate, timeout=30, pause_time=0.5,
#                              timeout_message="Operation timed out."):
#     def check_content(self, entity, **kwargs):
#     def check_entity(self, entity):
#     def clear_restart_message(self):
#     def fake_splunk_version(self, version):
#     def install_app_from_collection(self, name):
#     def app_collection_installed(self):
#     def pathInApp(self, appName, pathComponents):
#     def uncheckedRestartSplunk(self, timeout=240):
#     def restartSplunk(self, timeout=240):
#     def setUpClass(cls):
#     def setUp(self):
#     def tearDown(self):
# 
# Path: splunklib/binding.py
# def _log_duration(f):
#     @wraps(f)
#     def new_f(*args, **kwargs):
#         start_time = datetime.now()
#         val = f(*args, **kwargs)
#         end_time = datetime.now()
#         logging.debug("Operation took %s", end_time-start_time)
#         return val
#     return new_f
# 
# class HTTPError(Exception):
#     """This exception is raised for HTTP responses that return an error."""
#     def __init__(self, response, _message=None):
#         status = response.status
#         reason = response.reason
#         body = response.body.read()
#         try:
#             detail = XML(body).findtext("./messages/msg")
#         except ParseError as err:
#             detail = body
#         message = "HTTP %d %s%s" % (
#             status, reason, "" if detail is None else " -- %s" % detail)
#         Exception.__init__(self, _message or message)
#         self.status = status
#         self.reason = reason
#         self.headers = response.headers
#         self.body = body
#         self._response = response


# Path: tests/test_job.py
from io import BytesIO
from time import sleep
from tests import testlib
from splunklib.binding import _log_duration, HTTPError
        from datetime import datetime
                    from collections import OrderedDict
                    from splunklib.ordereddict import OrderedDict
                    from collections import OrderedDict
                    from splunklib.ordereddict import OrderedDict
import io
    import unittest2 as unittest
    import unittest
import splunklib.client as client
import splunklib.results as results
import pytest
        import splunklib.client as client
        import splunklib.results as results
        import splunklib.results as results
        import splunklib.client as client
        import splunklib.results as results
        import splunklib.client as client
        import splunklib.results as results

            earliest_time="-1m",
            priority=5,
            latest_time="now")

        # Note: You can only *decrease* the priority (i.e., 5 decreased to 3) of
        # a job unless Splunk is running as root. This is because Splunk jobs
        # are tied up with operating system processes and their priorities.

        if self.service._splunk_version[0] < 6:
            # BUG: Splunk 6 doesn't return priority until job is ready
            old_priority = int(self.job.content['priority'])
            self.assertEqual(5, old_priority)

        new_priority = 3
        self.job.set_priority(new_priority)

        if self.service._splunk_version[0] > 5:
            # BUG: Splunk 6 doesn't return priority until job is ready
            while not self.job.is_ready():
                pass

        def f():
            if self.job.is_done():
                self.fail("Job already done before priority was set.")
            return int(self.job.content['priority']) == new_priority

        self.assertEventuallyTrue(f, timeout=sleep_duration + 5)
        return



class TestJob(testlib.SDKTestCase):