def test_to_yaml_no_defaults(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: dynamic: variables: gettime: programy.dynamic.variables.datetime.GetTime sets: number: programy.dynamic.sets.numeric.IsNumeric roman: programy.dynamic.sets.roman.IsRomanNumeral maps: romantodec: programy.dynamic.maps.roman.MapRomanToDecimal dectoroman: programy.dynamic.maps.roman.MapDecimalToRoman """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".") data = {} dynamic_config.to_yaml(data, defaults=False) self.assertEquals({'GETTIME': 'programy.dynamic.variables.datetime.GetTime'}, data['variables']) self.assertEquals({'NUMBER': 'programy.dynamic.sets.numeric.IsNumeric', 'ROMAN': 'programy.dynamic.sets.roman.IsRomanNumeral'}, data['sets']) self.assertEquals({'ROMANTODEC': 'programy.dynamic.maps.roman.MapRomanToDecimal', 'DECTOROMAN': 'programy.dynamic.maps.roman.MapDecimalToRoman'}, data['maps'])
def test_load_from_configuration_no_data(self): collection = DynamicsCollection() self.assertIsNotNone(collection) yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: dynamic: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamics_config = BrainDynamicsConfiguration() dynamics_config.load_config_section(yaml, brain_config, ".") collection.load_from_configuration(dynamics_config) self.assertIsNotNone(collection.dynamic_sets) self.assertTrue(collection.is_dynamic_set("NUMBER")) self.assertIsNotNone(collection.dynamic_maps) self.assertTrue(collection.is_dynamic_map("PLURAL")) self.assertTrue(collection.is_dynamic_map("SINGULAR")) self.assertTrue(collection.is_dynamic_map("PREDECESSOR")) self.assertTrue(collection.is_dynamic_map("SUCCESSOR")) self.assertIsNotNone(collection.dynamic_vars)
def test_to_yaml_no_defaults_no_data(self): yaml = {} dynamic_config = BrainDynamicsConfiguration() dynamic_config.to_yaml(yaml, defaults=False) self.assertEquals({}, yaml['variables']) self.assertEquals({}, yaml['sets']) self.assertEquals({}, yaml['maps'])
def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults) self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._security = BrainSecuritiesConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() self._debugfiles = BrainDebugFilesConfiguration() BaseContainerConfigurationData.__init__(self, section_name)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".")
def test_to_yaml_defaults(self): yaml = {} dynamic_config = BrainDynamicsConfiguration() dynamic_config.to_yaml(yaml, defaults=True) self.assertEquals({'GETTIME': 'programy.dynamic.variables.datetime.GetTime'}, yaml['variables']) self.assertEquals({'NUMBER': 'programy.dynamic.sets.numeric.IsNumeric', 'ROMAN': 'programy.dynamic.sets.roman.IsRomanNumeral', 'STOPWORD': 'programy.dynamic.sets.stopword.IsStopWord', 'SYNSETS': 'programy.dynamic.sets.synsets.IsSynset'}, yaml['sets']) self.assertEquals({'ROMANTODDEC': 'programy.dynamic.maps.roman.MapRomanToDecimal', 'DECTOROMAN': 'programy.dynamic.maps.roman.MapDecimalToRoman', 'LEMMATIZE': 'programy.dynamic.maps.lemmatize.LemmatizeMap', 'STEMMER': 'programy.dynamic.maps.stemmer.StemmerMap'}, yaml['maps'])
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: dynamic: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".") self.assertEquals({}, dynamic_config.dynamic_vars) self.assertEquals({}, dynamic_config.dynamic_sets) self.assertEquals({}, dynamic_config.dynamic_maps)
def __init__(self, section_name="brain"): self._bot_name = None self._manager_name = None self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() self._debugfiles = BrainDebugFilesConfiguration() self._nlu = BrainNluConfiguration() BaseContainerConfigurationData.__init__(self, section_name)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: dynamic: variables: gettime: programy.dynamic.variables.datetime.GetTime sets: number: programy.dynamic.sets.numeric.IsNumeric roman: programy.dynamic.sets.roman.IsRomanNumeral maps: romantodec: programy.dynamic.maps.roman.MapRomanToDecimal dectoroman: programy.dynamic.maps.roman.MapDecimalToRoman """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".")
def test_load_from_configuration(self): collection = DynamicsCollection() self.assertIsNotNone(collection) yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: dynamic: variables: gettime: programy.dynamic.variables.datetime.GetTime sets: roman: programy.dynamic.sets.roman.IsRomanNumeral maps: romantodec: programy.dynamic.maps.roman.MapRomanToDecimal """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamics_config = BrainDynamicsConfiguration() dynamics_config.load_config_section(yaml, brain_config, ".") collection.load_from_configuration(dynamics_config) self.assertIsNotNone(collection.dynamic_sets) self.assertTrue(collection.is_dynamic_set("ROMAN")) self.assertTrue(collection.is_dynamic_set("NUMBER")) self.assertIsNotNone(collection.dynamic_maps) self.assertTrue(collection.is_dynamic_map("ROMANTODEC")) self.assertTrue(collection.is_dynamic_map("PLURAL")) self.assertTrue(collection.is_dynamic_map("SINGULAR")) self.assertTrue(collection.is_dynamic_map("PREDECESSOR")) self.assertTrue(collection.is_dynamic_map("SUCCESSOR")) self.assertIsNotNone(collection.dynamic_vars) self.assertTrue(collection.is_dynamic_var("GETTIME"))
def test_defaults(self): dynamic_config = BrainDynamicsConfiguration() data = {} dynamic_config.to_yaml(data, True) BrainDynamicsConfigurationTests.assert_defaults(self, data)