def test_thonky_add_format_info(): # <http://www.thonky.com/qr-code-tutorial/format-version-information#put-the-format-string-into-the-qr-code> version = 1 matrix = encoder.make_matrix(version, reserve_regions=False) encoder.add_finder_patterns(matrix, is_micro=False) encoder.add_format_info(matrix, version, consts.ERROR_LEVEL_L, 4) ref_matrix = read_matrix('thonky_format') assert ref_matrix == matrix
def test_thonky_add_format_info(): # <http://www.thonky.com/qr-code-tutorial/format-version-information#put-the-format-string-into-the-qr-code> version = 1 matrix = encoder.make_matrix(version, reserve_regions=False) encoder.add_finder_patterns(matrix, is_micro=False) encoder.add_format_info(matrix, version, consts.ERROR_LEVEL_L, 4) ref_matrix = read_matrix('thonky_format') assert ref_matrix == matrix
def _make_figure22_matrix(): version = consts.VERSION_M4 matrix = encoder.make_matrix(version) for row in matrix: for i in range(len(row)): if row[i] == 0x2: row[i] = 0x0 encoder.add_finder_patterns(matrix, True) return matrix
def _make_figure22_matrix(): version = consts.VERSION_M4 matrix = encoder.make_matrix(version) for row in matrix: for i in range(len(row)): if row[i] == 0x2: row[i] = 0x0 encoder.add_finder_patterns(matrix, True) return matrix
def test_thonky_add_version_info(): # <http://www.thonky.com/qr-code-tutorial/format-version-information> version = 7 matrix = encoder.make_matrix(version, reserve_regions=False) encoder.add_finder_patterns(matrix, is_micro=False) encoder.add_alignment_patterns(matrix, version) encoder.add_version_info(matrix, version) matrix[-8][8] = 0x1 # dark module ref_matrix = read_matrix('thonky_version') assert ref_matrix == matrix
def test_thonky_add_version_info(): # <http://www.thonky.com/qr-code-tutorial/format-version-information> version = 7 matrix = encoder.make_matrix(version, reserve_regions=False) encoder.add_finder_patterns(matrix, is_micro=False) encoder.add_alignment_patterns(matrix, version) encoder.add_version_info(matrix, version) matrix[-8][8] = 0x1 # dark module ref_matrix = read_matrix('thonky_version') assert ref_matrix == matrix
def test_format_info_figure26(): # 7.9.2 Micro QR Code symbols (page 57) version = consts.VERSION_M1 mask = 3 matrix = tuple([bytearray([0x0] * 11) for i in range(11)]) encoder.add_timing_pattern(matrix, is_micro=True) encoder.add_finder_patterns(matrix, is_micro=True) encoder.add_format_info(matrix, version=version, error=None, mask_pattern=mask) ref_matrix = read_matrix('fig-26') assert len(ref_matrix) == len(matrix) assert ref_matrix == matrix
def test_format_info_figure26(): # 7.9.2 Micro QR Code symbols (page 57) version = consts.VERSION_M1 mask = 3 matrix = tuple([bytearray([0x0] * 11) for i in range(11)]) encoder.add_timing_pattern(matrix, is_micro=True) encoder.add_finder_patterns(matrix, is_micro=True) encoder.add_format_info(matrix, version=version, error=None, mask_pattern=mask) ref_matrix = read_matrix('fig-26') assert len(ref_matrix) == len(matrix) assert ref_matrix == matrix
def test_codeword_placement_iso_i3(): # ISO/IEC 18004:2015(E) - page 96 # 01234567 as M2-L symbol s = '01000000 00011000 10101100 11000011 00000000' codewords = Buffer(bits(s)).toints() version = consts.VERSION_M2 buff = encoder.make_final_message(version, consts.ERROR_LEVEL_L, codewords) expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000' expected = bits(expected_s) assert expected == buff.getbits() matrix = encoder.make_matrix(version) encoder.add_finder_patterns(matrix, is_micro=version < 1) encoder.add_codewords(matrix, buff, version=version) ref_matrix = read_matrix('iso-i3_code_placement') assert ref_matrix == matrix
def test_codeword_placement_iso_i3(): # ISO/IEC 18004:2015(E) - page 96 # 01234567 as M2-L symbol s = '01000000 00011000 10101100 11000011 00000000' codewords = Buffer(bits(s)).toints() version = consts.VERSION_M2 buff = encoder.make_final_message(version, consts.ERROR_LEVEL_L, codewords) expected_s = '01000000 00011000 10101100 11000011 00000000 10000110 00001101 00100010 10101110 00110000' expected = bits(expected_s) assert expected == buff.getbits() matrix = encoder.make_matrix(version) encoder.add_finder_patterns(matrix, is_micro=version < 1) encoder.add_codewords(matrix, buff, version=version) ref_matrix = read_matrix('iso-i3_code_placement') assert ref_matrix == matrix
def test_codeword_placement_iso_i2(): # ISO/IEC 18004:2015(E) - page 94 # 01234567 as 1-M symbol s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 00010001 ' \ '11101100 00010001 11101100 00010001 11101100 00010001 11101100 00010001' codewords = Buffer(bits(s)) version = 1 buff = encoder.make_final_message(version, consts.ERROR_LEVEL_M, codewords) expected_s = '00010000 00100000 00001100 01010110 01100001 10000000 11101100 ' \ '00010001 11101100 00010001 11101100 00010001 11101100 00010001 ' \ '11101100 00010001 10100101 00100100 11010100 11000001 11101101 ' \ '00110110 11000111 10000111 00101100 01010101' expected = bits(expected_s) assert expected == buff.getbits() matrix = encoder.make_matrix(version) encoder.add_finder_patterns(matrix, is_micro=version < 1) encoder.add_codewords(matrix, buff, version=version) ref_matrix = read_matrix('iso-i2_code_placement') assert ref_matrix == matrix