# Path: seal/lib/mr/test_utils.py
# class map_context(object):
# 
#   def __init__(self, jc, input_split):
#     self.job_conf = jc
#     self.input_split = input_split
#     self.counters = {}
#     self.emitted = {}
#     self.status_messages = []
#     self._input_key = None
#     self._input_value = None
# 
#   def getJobConf(self):
#     return self.job_conf
# 
#   def getInputSplit(self):
#     return self.input_split
# 
#   def getInputKey(self):
#     return self._input_key
# 
#   def getInputValue(self):
#     return self._input_value
# 
#   def getCounter(self, group, name):
#     k = '%s:%s' % (group, name)
#     self.counters[k] = 0
#     return k
# 
#   def incrementCounter(self, counter, amount):
#     self.counters[counter] += amount
# 
#   def emit(self, k, v):
#     if not isinstance(k, str):
#       raise TypeError("key must be a string (it's a %s)" % type(k))
#     if not isinstance(v, str):
#       raise TypeError("value must be a string (it's a %s)" % type(v))
# 
#     if not self.emitted.has_key(k):
#       self.emitted[k] = []
#     self.emitted[k].append(v)
# 
#   def progress(self):
#     pass
# 
#   def setStatus(self, status):
#     self.status_messages.append(status)
# 
#   # for compatibility with pydoop 1
#   @property
#   def key(self):
#     return self._input_key
# 
#   @property
#   def value(self):
#     return self._input_value
# 
#   def set_input_key(self, k):
#     self._input_key = k
# 
#   def set_input_value(self, v):
#     self._input_value = v
# 
# class SavingLogger(object):
#     DEBUG = 50
#     INFO = 40
#     WARNING = 30
#     ERROR = 20
#     CRITICAL = 10
# 
#     def __init__(self):
#         self.output = StringIO.StringIO()
#         self.log_level = type(self).DEBUG
# 
#     def contents(self):
#         return self.output.getvalue()
# 
#     def debug(self, *args):
#         if self.log_level >= type(self).DEBUG:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def info(self, *args):
#         if self.log_level >= type(self).INFO:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def warning(self, *args):
#         if self.log_level >= type(self).WARNING:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def error(self, *args):
#         if self.log_level >= type(self).ERROR:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def critical(self, *args):
#         if self.log_level >= type(self).CRITICAL:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")


import re
import time
import unittest
from seal.lib.mr.hadoop_event_monitor import *
from seal.lib.mr.test_utils import map_context, SavingLogger
        # extract the measured time and ensure it's > 0
        m = re.search("done with test_start_stop\s+\(\s*(-?[0-9.]+\s*)", self.map_ctx.status_messages[-1])
        self.assertTrue(m is not None, "couldn't extract time from timing status message")
        self.assertTrue(float(m.group(1)) > 0)

    def test_time_block(self):
        with self.monitor.time_block("test_time_block"):
            # in block
            time.sleep(0.5)

        self.assertTrue( re.match('done with test_time_block.*', self.logger.contents()) is not None)
        self.assertTrue( re.match('done with test_time_block.*', self.map_ctx.status_messages[-1]) is not None)
        # extract the measured time and ensure it's > 0
        m = re.search("done with test_time_block\s+\(\s*(-?[0-9.]+\s*)", self.map_ctx.status_messages[-1])
        self.assertTrue(m is not None, "couldn't extract time from timing status message")
        self.assertTrue(float(m.group(1)) > 0)

    def test_count_default(self):
        # this corresponds to how the mock context creates the counter ids,
        # and the event monitor makes the name uppercase.
        counter_id = "%s:%s" % (self.count_group, "TEST_COUNT")
        self.monitor.count("test_count")
        self.assertEqual(1, self.map_ctx.counters[counter_id])
        self.monitor.count("test_count")
        self.assertEqual(2, self.map_ctx.counters[counter_id])

    def test_count_nondefault_value(self):
        counter_id = "%s:%s" % (self.count_group, "TEST_COUNT")
        self.monitor.count("test_count", 8)
        self.assertEqual(8, self.map_ctx.counters[counter_id])

# Path: seal/lib/mr/test_utils.py
# class map_context(object):
# 
#   def __init__(self, jc, input_split):
#     self.job_conf = jc
#     self.input_split = input_split
#     self.counters = {}
#     self.emitted = {}
#     self.status_messages = []
#     self._input_key = None
#     self._input_value = None
# 
#   def getJobConf(self):
#     return self.job_conf
# 
#   def getInputSplit(self):
#     return self.input_split
# 
#   def getInputKey(self):
#     return self._input_key
# 
#   def getInputValue(self):
#     return self._input_value
# 
#   def getCounter(self, group, name):
#     k = '%s:%s' % (group, name)
#     self.counters[k] = 0
#     return k
# 
#   def incrementCounter(self, counter, amount):
#     self.counters[counter] += amount
# 
#   def emit(self, k, v):
#     if not isinstance(k, str):
#       raise TypeError("key must be a string (it's a %s)" % type(k))
#     if not isinstance(v, str):
#       raise TypeError("value must be a string (it's a %s)" % type(v))
# 
#     if not self.emitted.has_key(k):
#       self.emitted[k] = []
#     self.emitted[k].append(v)
# 
#   def progress(self):
#     pass
# 
#   def setStatus(self, status):
#     self.status_messages.append(status)
# 
#   # for compatibility with pydoop 1
#   @property
#   def key(self):
#     return self._input_key
# 
#   @property
#   def value(self):
#     return self._input_value
# 
#   def set_input_key(self, k):
#     self._input_key = k
# 
#   def set_input_value(self, v):
#     self._input_value = v
# 
# class SavingLogger(object):
#     DEBUG = 50
#     INFO = 40
#     WARNING = 30
#     ERROR = 20
#     CRITICAL = 10
# 
#     def __init__(self):
#         self.output = StringIO.StringIO()
#         self.log_level = type(self).DEBUG
# 
#     def contents(self):
#         return self.output.getvalue()
# 
#     def debug(self, *args):
#         if self.log_level >= type(self).DEBUG:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def info(self, *args):
#         if self.log_level >= type(self).INFO:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def warning(self, *args):
#         if self.log_level >= type(self).WARNING:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def error(self, *args):
#         if self.log_level >= type(self).ERROR:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")
# 
#     def critical(self, *args):
#         if self.log_level >= type(self).CRITICAL:
#             self.output.write(' '.join(map(str, args)))
#             self.output.write("\n")


# Path: tests/tseal/lib/mr/test_hadoop_event_monitor.py
import re
import time
import unittest
from seal.lib.mr.hadoop_event_monitor import *
from seal.lib.mr.test_utils import map_context, SavingLogger

        # extract the measured time and ensure it's > 0
        m = re.search("done with test_start_stop\s+\(\s*(-?[0-9.]+\s*)", self.map_ctx.status_messages[-1])
        self.assertTrue(m is not None, "couldn't extract time from timing status message")
        self.assertTrue(float(m.group(1)) > 0)

    def test_time_block(self):
        with self.monitor.time_block("test_time_block"):
            # in block
            time.sleep(0.5)

        self.assertTrue( re.match('done with test_time_block.*', self.logger.contents()) is not None)
        self.assertTrue( re.match('done with test_time_block.*', self.map_ctx.status_messages[-1]) is not None)
        # extract the measured time and ensure it's > 0
        m = re.search("done with test_time_block\s+\(\s*(-?[0-9.]+\s*)", self.map_ctx.status_messages[-1])
        self.assertTrue(m is not None, "couldn't extract time from timing status message")
        self.assertTrue(float(m.group(1)) > 0)

    def test_count_default(self):
        # this corresponds to how the mock context creates the counter ids,
        # and the event monitor makes the name uppercase.
        counter_id = "%s:%s" % (self.count_group, "TEST_COUNT")
        self.monitor.count("test_count")
        self.assertEqual(1, self.map_ctx.counters[counter_id])
        self.monitor.count("test_count")
        self.assertEqual(2, self.map_ctx.counters[counter_id])

    def test_count_nondefault_value(self):
        counter_id = "%s:%s" % (self.count_group, "TEST_COUNT")
        self.monitor.count("test_count", 8)
        self.assertEqual(8, self.map_ctx.counters[counter_id])

        self.monitor.count("test_count", 5)