コード例 #1
0
    def test_filtering(self):
        """ Verify that log messages are filtered according to level. """
        log.setup_log()
        logger = logging.getLogger("grammar")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = ["grammar (WARNING): test_filtering - warning",
                    "grammar (ERROR): test_filtering - error"]
        self.assertEqual(self._output.lines, expected)

        self._output.clear()
        logger = logging.getLogger("grammar.begin")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = ["grammar.begin (INFO): test_filtering - info",
                    "grammar.begin (WARNING): test_filtering - warning",
                    "grammar.begin (ERROR): test_filtering - error"]
        self.assertEqual(self._output.lines, expected)

        self._output.clear()
        logger = logging.getLogger("grammar.load")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = ["grammar.load (WARNING): test_filtering - warning",
                    "grammar.load (ERROR): test_filtering - error"]
        self.assertEqual(self._output.lines, expected)
コード例 #2
0
ファイル: test_log.py プロジェクト: daanzu/dragonfly-old
    def test_filtering(self):
        """ Verify that log messages are filtered according to level. """
        log.setup_log()
        logger = logging.getLogger("grammar")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = [
            "grammar: test_filtering - warning",
            "grammar: test_filtering - error"
        ]
        self.assertEqual(self._output.lines, expected)

        self._output.clear()
        logger = logging.getLogger("grammar.begin")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = [
            "grammar.begin: test_filtering - info",
            "grammar.begin: test_filtering - warning",
            "grammar.begin: test_filtering - error"
        ]
        self.assertEqual(self._output.lines, expected)

        self._output.clear()
        logger = logging.getLogger("grammar.load")
        logger.debug("test_filtering - debug")
        logger.info("test_filtering - info")
        logger.warning("test_filtering - warning")
        logger.error("test_filtering - error")
        expected = [
            "grammar.load: test_filtering - warning",
            "grammar.load: test_filtering - error"
        ]
        self.assertEqual(self._output.lines, expected)
コード例 #3
0
    def func_wrapper():
        set_interval(func, sec)
        func()
    t = threading.Timer(sec, func_wrapper)
    t.start()
    return t

if False:
    # Debugging logging for reporting trouble
    logging.basicConfig(level=10)
    logging.getLogger('grammar.decode').setLevel(20)
    logging.getLogger('grammar.begin').setLevel(20)
    logging.getLogger('compound').setLevel(20)
    logging.getLogger('kaldi.compiler').setLevel(10)
else:
    setup_log()

def noop():
    #noop
    pass

def readIni(propName):
    iniURL = r"C:\Users\loves\programming\humanInterface\ahk\inis\globals.ini"
    confparser = ConfigParser()
    confparser.read(iniURL)
    return confparser.get('globals', propName)

def writeIni(propName,propValue):
    iniURL = r"C:\Users\loves\programming\humanInterface\ahk\inis\globals.ini"
    confparser = ConfigParser()
    confparser.read(iniURL)
コード例 #4
0
import logging
from dragonfly import log, CompoundRule, Grammar

log.setup_log()
# log.setup_tracing()


class LoggingRule(CompoundRule):
    spec = "is logging enabled"  # Spoken form of command.

    def _process_recognition(self, node,
                             extras):  # Callback when command is spoken.
        print 'Yes, looging should be enabled.'

        testlog = logging.getLogger("dfly.test")
        testlog.debug("Test the dragonfly test log.")

        engine_log = logging.getLogger("engine")
        engine_log.info("The file log should see this, but not stdout.")
        engine_log.warning("Both file and stdout logs should see this.")


#Create a grammar which contains and loads the command rule.
logging_rule = LoggingRule()
grammar = Grammar("example grammar")
grammar.add_rule(logging_rule)
grammar.load()


def unload():
    global grammar
コード例 #5
0
ファイル: test_rpc.py プロジェクト: swipswaps/dragonfly
                              "register_history", [])

            # Send a mimic and check that it is returned by the
            # 'get_recognition_history()' method.
            self.send_request("mimic", ["test history"])
            response = self.send_request("get_recognition_history", [])
            self.assertIn("result", response)
            self.assertListEqual(response["result"], [["test", "history"]])

            # Test 'unregister_observer()'.
            response = self.send_request("unregister_history", [])
            self.assertIn("result", response)

            # Test that the method raises an error if used when the observer
            # is not registered.
            self.assertRaises(RuntimeError, self.send_request,
                              "unregister_history", [])
        finally:
            g.set_exclusiveness(False)
            g.unload()


if __name__ == '__main__':
    # Use the "text" engine by default and disable timer manager callbacks
    # to avoid race conditions.
    get_engine("text")._timer_manager.disable()

    from dragonfly.log import setup_log
    setup_log()  # tests require sane logging levels
    unittest.main()
コード例 #6
0
import logging
from dragonfly import log, CompoundRule, Grammar

log.setup_log()
# log.setup_tracing()

class LoggingRule(CompoundRule):
    spec = "is logging enabled"                  # Spoken form of command.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print 'Yes, looging should be enabled.'

        testlog = logging.getLogger("dfly.test")
        testlog.debug("Test the dragonfly test log.")

        engine_log = logging.getLogger("engine")
        engine_log.info("The file log should see this, but not stdout.")
        engine_log.warning("Both file and stdout logs should see this.")

#Create a grammar which contains and loads the command rule.
logging_rule = LoggingRule()
grammar = Grammar("example grammar")
grammar.add_rule(logging_rule)
grammar.load()

def unload():
    global grammar
    if grammar: grammar.unload()
    grammar = None
コード例 #7
0
# TODO Have a simple GUI for pausing, resuming, cancelling and stopping
# recognition, etc

import os.path
import logging


from dragonfly import RecognitionObserver, get_engine
from dragonfly.loader import CommandModuleDirectory
from dragonfly.log import setup_log

# --------------------------------------------------------------------------
# Set up basic logging.

setup_log()


# --------------------------------------------------------------------------
# Simple recognition observer class.

class Observer(RecognitionObserver):
    def on_begin(self):
        print("Speech started.")

    def on_recognition(self, words):
        print(" ".join(words))

    def on_failure(self):
        print("Sorry, what was that?")