def test_parser_events(hsd_input, expected_events): """Test valid parser events""" testhandler = _TestEventHandler() parser = hsd.HsdParser(eventhandler=testhandler) hsdfile = io.StringIO(hsd_input) parser.parse(hsdfile) assert testhandler.events == expected_events
def test_parser_exceptions(hsd_input): """Test exception raised by the parser""" testhandler = _TestEventHandler() parser = hsd.HsdParser(eventhandler=testhandler) hsdfile = io.StringIO(hsd_input) with pytest.raises(hsd.HsdError): parser.parse(hsdfile)
def test_dict_builder_hsdattr(hsdstr, hsddict): """Test transformation from hsd to dictionary with HSD attributes.""" dictbuilder = hsd.HsdDictBuilder(include_hsd_attribs=True) parser = hsd.HsdParser(eventhandler=dictbuilder) fobj = io.StringIO(hsdstr) parser.parse(fobj) assert dictbuilder.hsddict == hsddict
def test_dictbuilder_flat(): dictbuilder = hsd.HsdDictBuilder(flatten_data=True) parser = hsd.HsdParser(eventhandler=dictbuilder) with open(op.join(op.dirname(__file__), "test.hsd"), "r") as fobj: parser.feed(fobj) pyrep = dictbuilder.hsddict print("** Python structure with data flattening:\n") print(pyrep) print("\n** Turning back to HSD:\n") print(hsd.dumps(pyrep))
def test_parser(): parser = hsd.HsdParser() with open(op.join(op.dirname(__file__), "test.hsd"), "r") as fobj: parser.feed(fobj)