Commits

Tetsuya Morimoto committed 5225262

added HeartBeatTask component tests

  • Participants
  • Parent commits aa6d681

Comments (0)

Files changed (2)

src/traccron/task.py

 # -*- encoding: UTF-8 -*-
-'''
+"""
 Created on 28 oct. 2010
 
 @author: thierry
-'''
+"""
 ###############################################################################
 ##
 ##             O U T    O F    T H E    B O X    T A S K
 from traccron.api import ICronTask
 from traccron.core import CronConfig
 
+
 class HeartBeatTask(Component, ICronTask):
     """
     This is a simple task for testing purpose.
     def wake_up(self, *args):
         if len(args) > 0:
             for arg in args:
-                self.env.log.debug('Heart beat: ' + arg)
+                self.env.log.debug('Heart beat: %s' % arg)
         else:
             self.env.log.debug('Heart beat: boom boom !!!')
 

tests/test_heart_beat_task.py

+# -*- coding: utf-8 -*-
+import logging
+
+import pytest
+from utils import has_log_message
+
+
+def pytest_funcarg__heart_beat_task(request, component):
+    heart_beat_task = component['heart_beat_task']
+    return heart_beat_task
+
+def test_heart_beat_task_getId(heart_beat_task):
+    assert 'heart_beat' == heart_beat_task.getId()
+
+
+def test_heart_beat_task_wake_up(heart_beat_task, caplog):
+    caplog.setLevel(logging.DEBUG, logger=heart_beat_task.env.log.name)
+    heart_beat_task.wake_up()
+    expected_messages = ['Heart beat: boom boom !!!']
+    assert has_log_message(caplog, expected_messages)
+
+
+@pytest.mark.parametrize('args', [
+    (),
+    ('test',),
+    ('test', 'data'),
+])
+def test_heart_beat_task_wake_up_with_args(heart_beat_task, caplog, args):
+    caplog.setLevel(logging.DEBUG, logger=heart_beat_task.env.log.name)
+    heart_beat_task.wake_up(*args)
+    expected_messages = ['Heart beat: ']
+    assert has_log_message(caplog, expected_messages)