def __init__(self, content_loader): """ The Nexus is the 'glue code' of Caster. It is where the things reside which manage global state. It is also an access point to those things for other things which need them. This access should be limited. """ '''CasterState is used for impl of the asynchronous actions''' self.state = CasterState() '''rpc class for interacting with Caster UI elements via xmlrpclib''' self.comm = Communicator() '''tracks both which rules are enabled and the rules' order''' rules_config = RulesConfig() '''does post-instantiation configuration on selfmodrules''' smrc = SelfModRuleConfigurer() '''hooks runner: receives and runs events, manages its hooks''' hooks_config = HooksConfig() hooks_runner = HooksRunner(hooks_config) smrc.set_hooks_runner(hooks_runner) '''does transformations on rules when rules are activated''' transformers_config = TransformersConfig() transformers_runner = TransformersRunner(transformers_config) '''the ccrmerger -- only merges MergeRules''' self._merger = Nexus._create_merger(smrc, transformers_runner) '''unified loading mechanism for [rules, transformers, hooks] from [caster starter locations, user dir]''' self._content_loader = content_loader '''mapping rule maker: like the ccrmerger, but doesn't merge and isn't ccr''' mapping_rule_maker = MappingRuleMaker(transformers_runner, smrc) '''the grammar manager -- probably needs to get broken apart more''' self._grammar_manager = Nexus._create_grammar_manager(self._merger, self._content_loader, hooks_runner, rules_config, smrc, mapping_rule_maker, transformers_runner) '''tracks engine grammar exclusivity and mic states -- TODO Grammar exclusivity should be managed through grammar manager''' self._engine_modes_manager = EngineModesManager() '''ACTION TIME:''' self._load_and_register_all_content(rules_config, hooks_runner, transformers_runner) self._grammar_manager.initialize() self._engine_modes_manager.initialize()
def setUp(self): settings_mocking.prevent_initialize() settings_mocking.prevent_save() from tests.test_util import utilities_mocking utilities_mocking.mock_toml_files() from castervoice.lib import utilities # do most imports here so that nothing imports and initializes settings from castervoice.lib.ctrl.ccr_toggle import CCRToggle from castervoice.lib.ctrl.companion.companion_config import CompanionConfig from castervoice.lib.ctrl.grammar_activator import GrammarActivator from castervoice.lib.ctrl.grammar_manager import GrammarManager from castervoice.lib.ctrl.loading.reload.manual_reload_observable import ManualReloadObservable from castervoice.lib.ctrl.rule_maker.mapping_rule_maker import MappingRuleMaker from castervoice.lib.ctrl.rules_config import RulesConfig from castervoice.lib.ctrl.nexus import Nexus from castervoice.lib.merge.ccrmerging2.hooks.hooks_config import HooksConfig from castervoice.lib.merge.ccrmerging2.hooks.hooks_runner import HooksRunner from castervoice.lib.merge.ccrmerging2.transformers.transformers_config import TransformersConfig from castervoice.lib.merge.ccrmerging2.transformers.transformers_runner import TransformersRunner from castervoice.lib.merge.mergerule import MergeRule from castervoice.lib.merge.selfmod.smr_configurer import SelfModRuleConfigurer from tests.lib.ctrl.grammar_container.fake_grammar_container import FakeGrammarContainer self._setup_config_file( utilities, ["paths", "RULES_CONFIG_PATH"], TestGrammarManager._MOCK_PATH_RULES_CONFIG, { RulesConfig._ENABLED_ORDERED: [], RulesConfig._INTERNAL: [], RulesConfig._WHITELISTED: {} }) self._setup_config_file( utilities, ["paths", "TRANSFORMERS_CONFIG_PATH"], TestGrammarManager._MOCK_PATH_TRANSFORMERS_CONFIG, {"TextReplacerTransformer": False}) self._setup_config_file(utilities, ["paths", "HOOKS_CONFIG_PATH"], TestGrammarManager._MOCK_PATH_HOOKS_CONFIG, {}) self._setup_config_file(utilities, ["paths", "COMPANION_CONFIG_PATH"], TestGrammarManager._MOCK_PATH_COMPANION_CONFIG, {}) self._set_setting(["miscellaneous", "max_ccr_repetitions"], 2) self._set_setting(["miscellaneous", "ccr_on"], True) self._rule_config = RulesConfig() smrc = SelfModRuleConfigurer() hooks_config = HooksConfig() self._hooks_runner = HooksRunner(hooks_config) smrc.set_hooks_runner(self._hooks_runner) transformers_config = TransformersConfig() self._transformers_runner = TransformersRunner(transformers_config) merger = Nexus._create_merger(smrc, self._transformers_runner) self._content_loader = Mock() mapping_rule_maker = MappingRuleMaker(self._transformers_runner, smrc) ccr_toggle = CCRToggle() ccr_rule_validator = Nexus._create_ccr_rule_validator() details_validator = Nexus._create_details_validator() combo_validator = Nexus._create_combo_validator() observable = ManualReloadObservable() grammars_container = FakeGrammarContainer() activator = GrammarActivator(lambda rule: isinstance(rule, MergeRule)) companion_config = CompanionConfig() self._gm = GrammarManager(self._rule_config, merger, self._content_loader, ccr_rule_validator, details_validator, observable, activator, mapping_rule_maker, grammars_container, self._hooks_runner, ccr_toggle, smrc, self._transformers_runner, companion_config, combo_validator)
def test_contains(self): tc = TransformersConfig() self.assertTrue("MockTransformer" in tc)
def test_is_transformer_active(self): tc = TransformersConfig() self.assertTrue(tc.is_transformer_active("MockTransformer")) self.assertFalse(tc.is_transformer_active("OffTransformer"))
def test_set_transformer_active(self): tc = TransformersConfig() self.assertFalse(tc.is_transformer_active("OffTransformer")) tc.set_transformer_active("OffTransformer", True) self.assertTrue(tc.is_transformer_active("OffTransformer"))