コード例 #1
0
ファイル: test_grammarManager.py プロジェクト: lahwran/Caster
    def test_internal_rules_dont_create_duplicates(self):
        from castervoice.lib import utilities
        from castervoice.lib.ctrl.rules_config import RulesConfig
        from castervoice.rules.core.alphabet_rules import alphabet

        # "write" the rules.toml file:
        self._setup_rules_config_file(
            loadable_true=["Alphabet"],
            enabled=["GrammarActivatorRule", "ManualGrammarReloadRule"])

        # check that the mock file changes were written
        self.assertEqual(
            2, len(self._rule_config._config[RulesConfig._ENABLED_ORDERED]))

        # initialize the gm
        alphabet_rule = alphabet.get_rule()
        self._initialize(FullContentSet([alphabet_rule], [], []))
        """
        After initialization, there should only be one copy of each of these in rules.toml: 
        GrammarActivatorRule 
        ManualGrammarReloadRule
        """
        config = utilities.load_toml_file(
            TestGrammarManager._MOCK_PATH_RULES_CONFIG)
        enabled_ordered = config[RulesConfig._ENABLED_ORDERED]
        self.assertEqual(1, enabled_ordered.count("GrammarActivatorRule"))
        self.assertEqual(1, enabled_ordered.count("ManualGrammarReloadRule"))
コード例 #2
0
ファイル: test_grammarManager.py プロジェクト: lahwran/Caster
    def test_enable_rule_causes_a_save(self):
        from castervoice.lib import utilities
        from castervoice.lib.ctrl.rules_config import RulesConfig
        from castervoice.rules.core.alphabet_rules import alphabet
        from castervoice.rules.core.punctuation_rules import punctuation

        # "write" the rules.toml file:
        self._setup_rules_config_file(
            loadable_true=["Alphabet", "Punctuation"], enabled=["Alphabet"])

        # check that the mock file changes were written
        self.assertEqual(
            1, len(self._rule_config._config[RulesConfig._ENABLED_ORDERED]))

        # initialize the gm
        a, b = alphabet.get_rule(), punctuation.get_rule()
        self._initialize(FullContentSet([a, b], [], []))

        # simulate a spoken "enable" command from the GrammarActivator:
        self._gm._change_rule_enabled("Punctuation", True)
        # afterwards, the config should have both Alphabet and Punctuation enabled
        config = utilities.load_toml_file(
            TestGrammarManager._MOCK_PATH_RULES_CONFIG)
        self.assertIn("Alphabet", config[RulesConfig._ENABLED_ORDERED])
        self.assertIn("Punctuation", config[RulesConfig._ENABLED_ORDERED])
コード例 #3
0
ファイル: test_grammarManager.py プロジェクト: lahwran/Caster
 def test_initialize_one_mergerule(self):
     from castervoice.rules.core.alphabet_rules import alphabet
     self._setup_rules_config_file(loadable_true=["Alphabet"],
                                   enabled=["Alphabet"])
     one_rule = alphabet.get_rule()
     self._initialize(FullContentSet([one_rule], [], []))
     self.assertEqual(2, len(self._gm._grammars_container.non_ccr.keys()))
     self.assertEqual(1, len(self._gm._grammars_container.ccr))
コード例 #4
0
ファイル: test_grammarManager.py プロジェクト: lahwran/Caster
    def test_knockout_with_companions_saves_correctly(self):
        from castervoice.lib import utilities
        from castervoice.lib.ctrl.rules_config import RulesConfig
        from castervoice.rules.ccr.java_rules import java
        from castervoice.rules.ccr.java_rules import java2
        from castervoice.rules.ccr.python_rules import python
        from castervoice.rules.ccr.python_rules import python2
        from castervoice.rules.core.alphabet_rules import alphabet
        from castervoice.rules.apps.microsoft_office import outlook

        # "write" the companion config file
        self._setup_config_file(utilities, ["paths", "COMPANION_CONFIG_PATH"],
                                TestGrammarManager._MOCK_PATH_COMPANION_CONFIG,
                                {
                                    "Java": ["JavaNon"],
                                    "Python": ["PythonNon"]
                                })

        # "write" the rules.toml file:
        self._setup_rules_config_file(
            loadable_true=[
                "Alphabet", "OutlookRule", "Java", "JavaNon", "Python",
                "PythonNon"
            ],
            enabled=["Alphabet", "OutlookRule", "Java", "JavaNon"])

        # check that the mock file changes were written
        self.assertEqual(
            4, len(self._rule_config._config[RulesConfig._ENABLED_ORDERED]))

        # initialize the gm
        alphabet_rule, outlook_rule = alphabet.get_rule(), outlook.get_rule()
        python_rule, pythonnon_rule = python.get_rule(), python2.get_rule()
        java_rule, javanon_rule = java.get_rule(), java2.get_rule()
        self._initialize(
            FullContentSet([
                alphabet_rule, outlook_rule, python_rule, pythonnon_rule,
                java_rule, javanon_rule
            ], [], []))

        # simulate a spoken "enable" command from the GrammarActivator:
        self._gm._change_rule_enabled("Python", True)
        """
        Afterwards, all of the following should be true:
        1. Python and PythonNon should each be in rules.toml exactly once
        2. Java and JavaNon should be in rules.toml zero times
        3. Alphabet and Outlook should still be in rules.toml
        """
        config = utilities.load_toml_file(
            TestGrammarManager._MOCK_PATH_RULES_CONFIG)
        enabled_ordered = config[RulesConfig._ENABLED_ORDERED]
        self.assertEqual(1, enabled_ordered.count("Python"))
        self.assertEqual(1, enabled_ordered.count("PythonNon"))
        self.assertEqual(0, enabled_ordered.count("Java"))
        self.assertEqual(0, enabled_ordered.count("JavaNon"))
        self.assertEqual(1, enabled_ordered.count("Alphabet"))
        self.assertEqual(1, enabled_ordered.count("OutlookRule"))
コード例 #5
0
ファイル: test_grammarManager.py プロジェクト: lahwran/Caster
 def test_initialize_two_compatible_global_mergerules(self):
     from castervoice.rules.core.alphabet_rules import alphabet
     from castervoice.rules.core.punctuation_rules import punctuation
     self._setup_rules_config_file(
         loadable_true=["Alphabet", "Punctuation"],
         enabled=["Alphabet", "Punctuation"])
     a = alphabet.get_rule()
     b = punctuation.get_rule()
     self._initialize(FullContentSet([a, b], [], []))
     self.assertEqual(2, len(self._gm._grammars_container.non_ccr.keys()))
     self.assertEqual(1, len(self._gm._grammars_container.ccr))