def _read_rule_set(path: str) -> RewriteRule:
    logging.info("reading rewrite rules from %r", path)
    # Below read call might throw IOError.
    lines = morphotactics_reader.read_rule_definitions(path)

    for index, line in lines.items():
      try:
        morphotactics_validator.validate(line)
      except morphotactics_validator.InvalidMorphotacticsRuleError as error:
        raise MorphotacticsCompilerError(
            f"Rewrite rule at line {index} of '{path}' is illformed. {error}")

    return morphotactics_parser.parse(list(lines.values()))
 def test_raises_exception(self, rule_definition, error):
     with self.assertRaisesRegexp(validator.InvalidMorphotacticsRuleError,
                                  error):
         validator.validate(rule_definition)
 def test_success(self, rule_definition):
     self.assertIsNone(validator.validate(rule_definition))