def test_config_section(): normalizer = core.Config(StringIO("test1\n[normalization]\nlowercase"), section='normalization') assert normalizer.normalize('ToLowerCase') == 'tolowercase' with pytest.raises(core.ConfigSectionNotFoundError): core.Config(StringIO("test1\n[normalization]\nlowercase"), section='sectiondoesntexist')
def test_logs(caplog): caplog.set_level(logging.DEBUG) config = ''' # using a simple config file lowercase lowercase Regex ./resources/test/normalizers/doublequotestosinglequotes.regex # 'ni' -> 'ecky ecky ecky' Replace ./resources/test/normalizers/nitoeckyecky.replace ''' assert core.Config._default_section is 'normalization' normalizer = core.Config(StringIO(config), section=core.Config.MAIN_SECTION) normalized = normalizer.normalize('No! Not the Knights Who Say "Ni"!') assert normalized == "no! not the knights who say 'ecky ecky ecky'!" assert len(caplog.records) == 0, \ "logs shouldn't be propagated unless we register our own handlers"
def test_configfile(): file = './resources/test/normalizers/configfile.conf' normalizer = core.Config(file, section=core.Config.MAIN_SECTION) assert normalizer.normalize('Ee ecky thump!') == 'aa ackY Thump!'
def test_invalid_normalizer_config(): with pytest.raises(ValueError) as e: core.Config(StringIO("[normalization]\nunknownnormalizer")) assert 'Unknown normalizer' in str(e)