def test_failed_create_spec(): pf = ParserFactory(class_map={}) pf.register_all([IntParser, StringParser]) pf.class_map['something'] = 1 with pytest.raises(ActorCreationFailException): pf.create_from_spec(ParserSpec(name='myvar')) with pytest.raises(ActorCreationFailException): pf.create_from_spec(ParserSpec(name='something'))
def test_fail_extraction_creation(simple_path: str): template = ExcoTemplate.from_excel(simple_path) spec = template.to_raw_excel_processor_spec() spec.cell_specs[CellLocation(sheet_name='TestSheet', coordinate='Z1')] = [ CellExtractionSpec(locator=LocatorSpec(name="right_of"), apv=APVSpec(key="something", parser=ParserSpec(name='int'), source=UnknownSource(), validations={}, fallback=None)) ] with pytest.raises(ExtractionTaskCreationException): ExcelProcessorFactory.default().create_from_spec( spec=spec).process_workbook(None)
def from_dict(cls, d: Dict[str, Any], source: source) -> 'APVSpec': return APVSpec( key=d[st.k_key], parser=ParserSpec.from_dict(d), fallback=d.get(st.k_fallback, st.default_fallback_value), validations={ v[st.k_key]: ValidatorSpec.from_dict(v) for v in d.get(st.k_validations, []) }, assumptions={ v[st.k_key]: AssumptionSpec.from_dict(v) for v in d.get(st.k_assumptions, []) }, metadata=d.get(st.k_metadata, {}), source=source if source is not None else UnknownSource())
def test_create_simple_spec(): spec = ParserSpec(name='int') fac = ParserFactory.default() parser = fac.create_from_spec(spec=spec) assert parser.__class__.__name__ == "IntParser"
def test_parser_spec(): spec = ParserSpec.from_dict({'parser': 'int', 'params': {}}) assert spec.name == 'int' assert spec.params == {}
def test_parser_spec_no_param(): spec = ParserSpec.from_dict({ 'parser': 'int', }) assert spec.params == {}
def test_parser_spec_no_name(): with pytest.raises(ParserSpecCreationException): ParserSpec.from_dict({'parserrr': 'int', 'params': {}})