def test_hexify(): h = hexify.Hexify(16).hexify(b'\xAB\xCD', 0xBEAF) assert next(h) == header1 assert next(h) == header2 assert next( h ) == '0000BEAF 00000000 AB CD |..|\n'
def test_hexify_multiline_data(): h = hexify.Hexify(16).hexify_data(range(17), 0xC0DE) assert next( h ) == '0000C0DE 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |................|\n' assert next( h ) == '0000C0EE 00000010 10 |.|\n'
async def transfer_logger(conn_n, from_writer_stream, to_writer_stream, queue): to_writer_info = format_peer_info(to_writer_stream) from_writer_info = format_peer_info(from_writer_stream) thread_id = threading.get_ident() now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') log_name = f"log-{now}-{conn_n:04}.{thread_id}-{from_writer_info}-{to_writer_info}.log" hexifier = hexify.Hexify(16) with open(log_name, 'w') as log: async for msg in queue: if isinstance(msg, str): log.write(msg) log.write('\n') elif isinstance(msg, list): bytes, offset = msg log.writelines(hexifier.hexify(bytes, offset))
def test_constructor_parameters(): h = hexify.Hexify(16) assert h.width == 16 assert len(h.padding_legend) == len(h.padding_separator) assert isinstance(h.printables, list) assert len(h.printables) == 256
def test_printable(): h = hexify.Hexify(16) assert h.printable(0) == '.' assert h.printable(32) == ' ' assert h.printable(255) == '.'
def test_hexify_data(): h = hexify.Hexify(16).hexify_data(b'*\xAB\xCD', 0x80001234) assert next( h ) == '80001234 00000000 2A AB CD |*..|\n'
def test_hexify_empty_data(): h = hexify.Hexify(16).hexify_data("", -1) with pytest.raises(StopIteration): assert next(h)
def test_header(): h = hexify.Hexify(16).header() assert next(h) == header1 assert next(h) == header2