Exemple #1
0
if log_destination == 'file':
    logs_basedir = "%s/logs" % basedir
    if not os.path.exists(logs_basedir):
        os.mkdir(logs_basedir)
    logfile = "%s/piautomator.log" % logs_basedir
    formatting = logging.Formatter(log_format, None)
    handler = RotatingFileHandler(logfile, maxBytes=1024 * 1024 * 100, backupCount=3)
    handler.setFormatter(formatting)
    logging.root.addHandler(handler)
else:
    logging.basicConfig(format=log_format)

# Initialize all components
global automation_context
automation_context = AutomationContext(config)
automation_context.receivers = receivers.init(automation_context)
automation_context.inputs = inputs.init(automation_context)
automation_context.rule_context = rules.init(automation_context)

automation_context.start()

# Setup the handler that will terminate our event loops.
global running
running = True

def signal_handler(signal, frame):
    global running
    running = False
    automation_context.stop()
    print 'Terminated'
Exemple #2
0
 def setUp(self):
     mock = Mock()
     mock.getSetting = MagicMock(return_value = False)
     self.context = AutomationContext(mock)
     self.context.__start_publish_queue__()
Exemple #3
0
    logs_basedir = "%s/logs" % basedir
    if not os.path.exists(logs_basedir):
        os.mkdir(logs_basedir)
    logfile = "%s/piautomator.log" % logs_basedir
    formatting = logging.Formatter(log_format, None)
    handler = RotatingFileHandler(logfile,
                                  maxBytes=1024 * 1024 * 100,
                                  backupCount=3)
    handler.setFormatter(formatting)
    logging.root.addHandler(handler)
else:
    logging.basicConfig(format=log_format)

# Initialize all components
global automation_context
automation_context = AutomationContext(config)
automation_context.receivers = receivers.init(automation_context)
automation_context.inputs = inputs.init(automation_context)
automation_context.rule_context = rules.init(automation_context)

automation_context.start()

# Setup the handler that will terminate our event loops.
global running
running = True


def signal_handler(signal, frame):
    global running
    running = False
    automation_context.stop()
Exemple #4
0
class TestAutomationContext(TestCase):

    def setUp(self):
        mock = Mock()
        mock.getSetting = MagicMock(return_value = False)
        self.context = AutomationContext(mock)
        self.context.__start_publish_queue__()

    def test_ads_value(self):
        self.context.publishValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertEqual(self.context.getValue("test.my.value"), 123123)

    def test_does_context_search_input(self):
        self.context.publishInputValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertEqual(self.context.getValue("test.my.value"), 123123)
        self.assertEqual(self.context.getValue("input.test.my.value"), 123123)

    def test_does_context_search_rules(self):
        self.context.publishRuleValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertEqual(self.context.getValue("test.my.value"), 123123)
        self.assertEqual(self.context.getValue("rule.test.my.value"), 123123)

    def test_does_context_search_receiver(self):
        self.context.publishReceiverValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertEqual(self.context.getValue("test.my.value"), 123123)
        self.assertEqual(self.context.getValue("receiver.test.my.value"), 123123)

    def test_publishing_values_changes_state(self):
        self.assertTrue(self.context.trigger.qsize() == 0)
        self.context.publishReceiverValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertTrue(self.context.trigger.qsize() == 1)
        self.assertTrue(self.context.trigger.get())

    def test_publishing_same_values_changes_no_state_for_rules(self):
        self.context.publishRuleValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertTrue(self.context.trigger.get())
        self.context.publishRuleValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertTrue(self.context.trigger.qsize() == 0)

    def test_publishing_same_values_changes_change_time_for_inputs(self):
        self.context.publishInputValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        self.assertTrue(self.context.trigger.get())
        current_time = self.context.getValue("test.my.value").change_time
        self.context.publishInputValues("test.my", {'value':123123})
        self.context.publish_queue.join()
        updated_time = self.context.getValue("test.my.value").change_time
        self.assertGreater(updated_time, current_time, "Change time should be updated")