def test_types_read():
    f = io.BytesIO('FormatVersion=5.0 // Do not edit this line!\nTitle="Types Test"\n\n{ENUMS}\nenum EnumAnimals(0="Cat", // An enum value for cats\n  1="Dog", // An enum value for dogs\n  2="Horse", 3="Monkey", \n  4="Lion")// An enum with a comment for the final value\n\n{SENDRECEIVE}\n\n[SymbolLengths]\nID=000h\nDLC=8\nVar="1Bit" unsigned 0,1\nVar="3Bits" unsigned 1,3\nVar="4Bits" unsigned 4,4\nVar="21Bits" unsigned 8,21\nVar="6Bits" unsigned 29,6\nVar="29Bits" unsigned 35,29\n\n[SymbolTypes]\nID=001h\nDLC=8\nVar=Bit bit 0,1\nVar=Char char 1,8\nVar=String string 16,16\nVar=Signed signed 32,4\nVar=Unsigned unsigned 36,4\nVar=Enum EnumAnimals 40,4\n\nVar=Raw raw 48,16\n\n[SymbolDouble]\nID=002h\nDLC=8\nVar=Double double 0,64\t// Must be 8 Bytes according to PCAN Symbol Editor V5\n\n[SymbolFloat]\nID=003h\nDLC=4\nVar=Float float 0,32\t// Must be 4 Bytes according to PCAN Symbol Editor V5\n'.encode('utf-8'))
    matrix = canmatrix.formats.sym.load(f)
    assert (matrix.load_errors == [])
    f_out = io.BytesIO()
    canmatrix.formats.sym.dump(matrix, f_out)
    f_out_bytes = f_out.getvalue()
    f_out_string = f_out_bytes.decode('utf-8')
    assert ('Var=Bit bit' in f_out_string)
    assert ('Var=Char char' in f_out_string)
    assert ('Var=String string' in f_out_string)
    assert ('Var=Signed signed' in f_out_string)
    assert ('Var="21Bits" unsigned' in f_out_string)
    assert ('Var=Float float' in f_out_string)
    assert ('Var=Double double' in f_out_string)
    f_in = io.BytesIO(f_out_bytes)
    new_matrix = canmatrix.formats.sym.load(f_in)
    assert (new_matrix.load_errors == [])
    frames = [f.name for f in matrix.frames]
    new_frames = [f.name for f in new_matrix.frames]
    assert (sorted(frames) == sorted(new_frames))
    signals = chain(*[[s.name for s in frame.signals] for frame in matrix.frames])
    new_signals = chain(*[[s.name for s in frame.signals] for frame in new_matrix.frames])
    assert (sorted(signals) == sorted(new_signals) == sorted(['1Bit', '3Bits', '4Bits', '21Bits', '6Bits', '29Bits', 'Bit', 'Char', 'String', 'Signed', 'Unsigned', 'Enum', 'Raw', 'Double', 'Float']))
def test_types_read():
    f = io.BytesIO('FormatVersion=5.0 // Do not edit this line!\nTitle="Types Test"\n\n{ENUMS}\nenum EnumAnimals(0="Cat", // An enum value for cats\n  1="Dog", // An enum value for dogs\n  2="Horse", 3="Monkey", \n  4="Lion")// An enum with a comment for the final value\n\n{SENDRECEIVE}\n\n[SymbolLengths]\nID=000h\nDLC=8\nVar="1Bit" unsigned 0,1\nVar="3Bits" unsigned 1,3\nVar="4Bits" unsigned 4,4\nVar="21Bits" unsigned 8,21\nVar="6Bits" unsigned 29,6\nVar="29Bits" unsigned 35,29\n\n[SymbolTypes]\nID=001h\nDLC=8\nVar=Bit bit 0,1\nVar=Char char 1,8\nVar=String string 16,16\nVar=Signed signed 32,4\nVar=Unsigned unsigned 36,4\nVar=Enum EnumAnimals 40,4\n\nVar=Raw raw 48,16\n\n[SymbolDouble]\nID=002h\nDLC=8\nVar=Double double 0,64\t// Must be 8 Bytes according to PCAN Symbol Editor V5\n\n[SymbolFloat]\nID=003h\nDLC=4\nVar=Float float 0,32\t// Must be 4 Bytes according to PCAN Symbol Editor V5\n'.encode('utf-8'))
    matrix = canmatrix.formats.sym.load(f)
    assert (matrix.load_errors == [])
    f_out = io.BytesIO()
    canmatrix.formats.sym.dump(matrix, f_out)
    f_out_bytes = f_out.getvalue()
    f_out_string = f_out_bytes.decode('utf-8')
    assert ('Var=Bit bit' in f_out_string)
    assert ('Var=Char char' in f_out_string)
    assert ('Var=String string' in f_out_string)
    assert ('Var=Signed signed' in f_out_string)
    assert ('Var="21Bits" unsigned' in f_out_string)
    assert ('Var=Float float' in f_out_string)
    assert ('Var=Double double' in f_out_string)
    f_in = io.BytesIO(f_out_bytes)
    new_matrix = canmatrix.formats.sym.load(f_in)
    assert (new_matrix.load_errors == [])
    frames = [f.name for f in matrix.frames]
    new_frames = [f.name for f in new_matrix.frames]
    assert (sorted(frames) == sorted(new_frames))
    signals = chain(*[[s.name for s in frame.signals] for frame in matrix.frames])
    new_signals = chain(*[[s.name for s in frame.signals] for frame in new_matrix.frames])
    assert (sorted(signals) == sorted(new_signals) == sorted(['1Bit', '3Bits', '4Bits', '21Bits', '6Bits', '29Bits', 'Bit', 'Char', 'String', 'Signed', 'Unsigned', 'Enum', 'Raw', 'Double', 'Float']))