Beispiel #1
0
def parse_test_data(class_name: Type[KaitaiStruct],
                    glob_string: str,
                    pretty_print: bool = True) -> Optional[KaitaiStruct]:
    """
    :param class_name: type of struct to expect
    :param glob_string: glob for test files
    :param pretty_print: if set to false, will dump vars instead
    :return KaitaiStruct last tested file
    """
    from glob import glob

    testfile = None
    print("parseTestData: path: %s" % glob_string)
    for testfile in sorted(glob(glob_string)):
        print("----------")
        print("parseTestData: testfile: %s" % testfile)
        instance = class_name.from_file(testfile)
        if pretty_print:
            from tests.prettyprint import prettyprint

            prettyprint(instance)
        else:
            print(vars(instance))

    return testfile
#!/usr/bin/env python3

if __name__ == "__main__":
    import sys
    import os

    if len(sys.argv) < 2:
        print("use as %s <hexstring>" % sys.argv[0])
        exit(0)

    sys.path.append(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

    from tests.prettyprint import prettyprint
    from kaitai.hytera_radio_network_protocol import HyteraRadioNetworkProtocol

    packet = HyteraRadioNetworkProtocol.from_bytes(bytes.fromhex(sys.argv[1]))
    prettyprint(packet)