def test_write_segment_alphanumeric_standard_value_example(eci): # See ISO/IEC 18004:2006(E) -- 6.4.3 Numeric mode - EXAMPLE (page 26) s = b'AC-42' seg = encoder.make_segment(s, consts.MODE_ALPHANUMERIC) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('00100000001010011100111011100111001000010') == buff.getbits()
def test_write_segment_alphanumeric_thonky(eci): # <http://www.thonky.com/qr-code-tutorial/data-encoding/#step-3-encode-using-the-selected-mode> s = b'HELLO WORLD' seg = encoder.make_segment(s, consts.MODE_ALPHANUMERIC, None) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci) assert bits('00100000010110110000101101111000110100010111001011011100010011010100001101') == buff.getbits()
def test_write_segment_numeric_standard_value_example2(eci): # See ISO/IEC 18004:2006(E) -- 6.4.3 Numeric mode - EXAMPLE 2 (page 25) s = b'0123456789012345' seg = encoder.make_segment(s, consts.MODE_NUMERIC) buff = Buffer() v, vrange = consts.VERSION_M3, consts.VERSION_M3 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('0010000000000110001010110011010100110111000010100111010100101') == buff.getbits()
def test_write_segment_numeric_standard_value_i3(eci): # See ISO/IEC 18004:2006(E) -- I.3 Encoding a Micro QR Code symbol (page 96) s = b'01234567' seg = encoder.make_segment(s, consts.MODE_NUMERIC) buff = Buffer() v, vrange = consts.VERSION_M2, consts.VERSION_M2 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('01000000000110001010110011000011') == buff.getbits()
def test_write_segment_eci_standard_value(): # See ISO/IEC 18004:2006(E) -- 6.4.2.1 ECI Designator - EXAMPLE (page 24) encoding = 'ISO-8859-7' #TODO: ? # NOTE: ISO/IEC 18004:2006(E) uses "ΑΒΓΔΕ" but text says: # (character values A1HEX, A2HEX, A3HEX, A4HEX, A5HEX) and result seems # to use the A...HEX values as well s = '\u2018\u2019\u00A3\u20AC\u20AF'.encode(encoding) seg = encoder.make_segment(s, consts.MODE_BYTE, encoding) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, True) expected = bits('0111 00001001 0100 00000101 10100001 10100010 10100011 10100100 10100101') result = buff.getbits() assert len(expected) == len(result) assert expected == result
def test_write_segment_bytes_thonky(eci): # <http://www.thonky.com/qr-code-tutorial/byte-mode-encoding/> s = b'Hello, world!' seg = encoder.make_segment(s, consts.MODE_BYTE, consts.DEFAULT_BYTE_ENCODING) buff = Buffer() v, vrange = None, consts.VERSION_RANGE_01_09 encoder.write_segment(buff, seg, v, vrange, eci=eci) assert bits('010000001101' '01001000' '01100101' '01101100' '01101100' '01101111' '00101100' '00100000' '01110111' '01101111' '01110010' '01101100' '01100100' '00100001') == buff.getbits()