def test__logging(self): from tornado_crontab import CronTabCallback from tornado_crontab._crontab import log_crontab def _func(arg1, arg2): pass _crontab = CronTabCallback( functools.partial(_func, "value1", arg2="value2"), "* * * * *") _crontab._running = True _stream = StringIO() log_crontab.addHandler(logging.StreamHandler(_stream)) _crontab._logging(logging.DEBUG) _log = _stream.getvalue() # for windows if os.name == "nt": user = os.environ.get("USERNAME") # for other os else: import pwd user = pwd.getpwuid(os.geteuid()).pw_name self.assertEqual( " ".join([ "tornado-crontab[%d]:" % os.getpid(), "(%s)" % user, "FUNC (_func ['value1'] {'arg2': 'value2'})\n" ]), _log)
def test__get_func_spec_no_args(self): from tornado_crontab import CronTabCallback def _func(): pass _crontab = CronTabCallback(_func, "* * * * *") self.assertEqual((_func, [], {}), _crontab._get_func_spec())
def test__get_func_spec_kwargs(self): from tornado_crontab import CronTabCallback def _func(arg1, arg2): pass _kwargs = {"arg1": "value1", "arg2": "value2"} _crontab = CronTabCallback(functools.partial(_func, **_kwargs), "* * * * *") self.assertEqual((_func, [], _kwargs), _crontab._get_func_spec()) _crontab = CronTabCallback( functools.partial(functools.partial(_func, arg1="value1"), arg2="value2"), "* * * * *") self.assertEqual((_func, [], _kwargs), _crontab._get_func_spec())
def test__get_func_spec_args(self): from tornado_crontab import CronTabCallback def _func(arg1, arg2): pass _args = ["value1", "value2"] _crontab = CronTabCallback(functools.partial(_func, *_args), "* * * * *") self.assertEqual((_func, _args, {}), _crontab._get_func_spec()) _crontab = CronTabCallback( functools.partial(functools.partial(_func, _args[0]), _args[1]), "* * * * *") self.assertEqual((_func, _args, {}), _crontab._get_func_spec())
def _target(self, schedule): from tornado_crontab import CronTabCallback pc = CronTabCallback(self.crontab_task, schedule, self.io_loop) pc.start()