# Path: stackimpact/runtime.py
# class runtime_info(object):
#     OS_LINUX = (sys.platform.startswith('linux'))
#     OS_DARWIN = (sys.platform == 'darwin')
#     OS_WIN = (sys.platform == 'win32')
#     PYTHON_2 = (sys.version_info.major == 2)
#     PYTHON_3 = (sys.version_info.major == 3)
#     GEVENT = False
# 
# def register_signal(signal_number, handler_func, once=False):
#     prev_handler = None
# 
#     def _handler(signum, frame):
#         skip_prev = handler_func(signum, frame)
# 
#         if not skip_prev:
#             if callable(prev_handler):
#                 if once:
#                     signal.signal(signum, prev_handler)
#                 prev_handler(signum, frame)
#             elif prev_handler == signal.SIG_DFL and once:
#                 signal.signal(signum, signal.SIG_DFL)
#                 os.kill(os.getpid(), signum)
# 
#     prev_handler = signal.signal(signal_number, _handler)


import unittest
import signal
import os
import stackimpact
from stackimpact.runtime import runtime_info, register_signal



class RuntimeTestCase(unittest.TestCase):

    def test_register_signal(self):
        if runtime_info.OS_WIN:
            return

        result = {'handler': 0}

        def _handler(signum, frame):
            result['handler'] += 1

        register_signal(signal.SIGUSR1, _handler)

        os.kill(os.getpid(), signal.SIGUSR1)
        os.kill(os.getpid(), signal.SIGUSR1)


# Path: stackimpact/runtime.py
# class runtime_info(object):
#     OS_LINUX = (sys.platform.startswith('linux'))
#     OS_DARWIN = (sys.platform == 'darwin')
#     OS_WIN = (sys.platform == 'win32')
#     PYTHON_2 = (sys.version_info.major == 2)
#     PYTHON_3 = (sys.version_info.major == 3)
#     GEVENT = False
# 
# def register_signal(signal_number, handler_func, once=False):
#     prev_handler = None
# 
#     def _handler(signum, frame):
#         skip_prev = handler_func(signum, frame)
# 
#         if not skip_prev:
#             if callable(prev_handler):
#                 if once:
#                     signal.signal(signum, prev_handler)
#                 prev_handler(signum, frame)
#             elif prev_handler == signal.SIG_DFL and once:
#                 signal.signal(signum, signal.SIG_DFL)
#                 os.kill(os.getpid(), signum)
# 
#     prev_handler = signal.signal(signal_number, _handler)


# Path: tests/runtime_test.py
import unittest
import signal
import os
import stackimpact
from stackimpact.runtime import runtime_info, register_signal




class RuntimeTestCase(unittest.TestCase):

    def test_register_signal(self):
        if runtime_info.OS_WIN:
            return

        result = {'handler': 0}

        def _handler(signum, frame):
            result['handler'] += 1

        register_signal(signal.SIGUSR1, _handler)

        os.kill(os.getpid(), signal.SIGUSR1)
        os.kill(os.getpid(), signal.SIGUSR1)


        signal.signal(signal.SIGUSR1, signal.SIG_DFL)