def test_dataoverflow(): data = 'A' * 4296 # Version 40: max. 4296 alphanumeric chars seq = segno.make_sequence(data, version=40) assert 1 == len(seq) data += 'B' seq = segno.make_sequence(data, version=40) assert 2 == len(seq)
def test_dataoverflow_error(): data = 'A' * 4296 * 16 # Version 40: max. 4296 alphanumeric chars * 16 symbols data = data[:-4] # Remove some chars taking some SA overhead into account seq = segno.make_sequence(data, version=40) assert 16 == len(seq) data += 'B' with pytest.raises(segno.DataOverflowError) as ex: segno.make_sequence(data, version=40) assert 'does not fit' in str(ex.value)
def test_boosterror(): seq = segno.make_sequence('I read the news today oh boy / About a lucky man ' 'who made the grade', version=2) assert 3 == len(seq) assert 'M' == seq[0].error assert 'M' == seq[1].error assert 'M' == seq[2].error
def test_boosterror2(): seq = segno.make_sequence('I read the news today oh boy / About a lucky man who made the grade', symbol_count=4) assert 4 == len(seq) assert '2-Q' == seq[0].designator assert '2-Q' == seq[1].designator assert '2-Q' == seq[2].designator assert '2-Q' == seq[3].designator
def test_save_one(): directory = tempfile.mkdtemp() assert 0 == len(os.listdir(directory)) seq = segno.make_sequence('ABC', version=1) assert 1 == len(seq) seq.save(os.path.join(directory, 'test.svg')) number_of_files = len(os.listdir(directory)) shutil.rmtree(directory) assert 1 == number_of_files
def test_save_terminal_multiple(): out_multiple = io.StringIO() data = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' seq = segno.make_sequence(data, version=1, error='m') assert 4 == len(seq) seq.terminal(out_multiple) out_single = io.StringIO() for qr in seq: qr.terminal(out_single) assert out_single.getvalue() == out_multiple.getvalue()
def test_save_terminal_one(): out_multiple = io.StringIO() data = 'QR Code Symbol' seq = segno.make_sequence(data, version=1) assert 1 == len(seq) seq.terminal(out_multiple) qr = segno.make_qr(data, version=1) out_single = io.StringIO() qr.terminal(out_single) assert out_single.getvalue() == out_multiple.getvalue()
def test_encode_single(): # ISO/IEC 18004:2015(E) - page 7 # 'QR Code Symbol' as 1-M symbol seq = segno.make_sequence('QR Code Symbol', version=1, error='M', boost_error=False) assert '1-M' == seq.designator ref_matrix = read_matrix('iso-fig-1') assert ref_matrix == seq.matrix qr = seq[0] assert '1-M' == qr.designator ref_matrix = read_matrix('iso-fig-1') assert ref_matrix == qr.matrix
def test_save_multiple(): directory = tempfile.mkdtemp() assert 0 == len(os.listdir(directory)) seq = segno.make_sequence('ABCDEFGHIJKLMN' 'OPQRSTUVWXYZ0123' '456789ABCDEFGHIJ' 'KLMNOPQRSTUVWXYZ', version=1, error='m') assert 4 == len(seq) seq.save(os.path.join(directory, 'test.svg')) number_of_files = len(os.listdir(directory)) shutil.rmtree(directory) assert 4 == number_of_files
def test_encode_multi_by_version_or_symbol_count(version, symbol_count): # ISO/IEC 18004:2015(E) - page 60 seq = segno.make_sequence('ABCDEFGHIJKLMN' 'OPQRSTUVWXYZ0123' '456789ABCDEFGHIJ' 'KLMNOPQRSTUVWXYZ', version=version, symbol_count=symbol_count, error='m', mask=4, boost_error=False) assert 4 == len(seq) ref_matrix = read_matrix('seq-iso-04-01') assert ref_matrix == seq[0].matrix ref_matrix = read_matrix('seq-iso-04-02') assert ref_matrix == seq[1].matrix ref_matrix = read_matrix('seq-iso-04-03') assert ref_matrix == seq[2].matrix ref_matrix = read_matrix('seq-iso-04-04') assert ref_matrix == seq[3].matrix
def test_illegal_version(): with pytest.raises(segno.VersionError): segno.make_sequence('ABCD', version='M4')
def test_illegal_symbolcount(symbol_count): with pytest.raises(ValueError): segno.make_sequence( 'I read the news today oh boy / About a lucky man who made the grade', symbol_count=symbol_count)
def test_toomany_symbols(): with pytest.raises(ValueError): segno.make_sequence('ABCDEF', symbol_count=16)
def test_boosterror_noop(): seq = segno.make_sequence('I read the news today oh boy', version=1) assert 2 == len(seq) assert 'L' == seq[0].error assert 'L' == seq[1].error
def test_int(): data = int('1' * 42) seq = segno.make_sequence(data, version=1) assert 2 == len(seq)
def test_no_version_provided(): with pytest.raises(ValueError): segno.make_sequence('A')