def test_version(self): base_file_name = "qrfromtext_version" versions = [ None, -1, 0, 41, '-1', '0', '41', 'blabla', 1, '1', 2, '2', 4, '4' ] version_names = ['default'] * 10 + ['2', '2', '4', '4'] for i in range(len(versions)): version = versions[i] print('Testing PNG with version %s' % version) version_name = version_names[i] qr1 = make_embedded_qr_code( TEST_TEXT, QRCodeOptions(version=version, image_format='png')) qr2 = qr_from_text(TEST_TEXT, version=version, image_format='png') qr3 = qr_from_text(TEST_TEXT, version=version, image_format='PNG') qr4 = qr_from_text(TEST_TEXT, options=QRCodeOptions(version=version, image_format='PNG')) result_file_name = '%s_%s' % (base_file_name, version_name) if REFRESH_REFERENCE_IMAGES: match = IMAGE_TAG_BASE64_DATA_RE.search(qr1) source_image_data = match.group('data') write_png_content_to_file(result_file_name, base64.b64decode(source_image_data)) result = base64.b64encode( get_png_content_from_file_name(result_file_name)).decode( 'utf-8') self.assertEqual(qr1, qr2) self.assertEqual(qr1, qr3) self.assertEqual(qr1, qr4) self.assertEqual(qr1, BASE64_PNG_IMAGE_TEMPLATE % result)
def test_size(self): base_ref_file_name = 'qrfromtext_size' sizes = [ 't', 'T', 's', 'S', None, -1, 0, 'm', 'M', 'l', 'L', 'h', 'H', '6', 6, '8', 8, '10', 10 ] size_names = ['tiny'] * 2 + ['small'] * 2 + ['medium'] * 5 + [ 'large' ] * 2 + ['huge'] * 2 + ['6'] * 2 + ['8'] * 2 + ['10'] * 2 for i in range(len(sizes)): size = sizes[i] print('Testing PNG with size %s' % size) size_name = size_names[i] result_file_name = '%s_%s' % (base_ref_file_name, size_name) qr1 = make_embedded_qr_code( TEST_TEXT, QRCodeOptions(size=size, image_format='png')) qr2 = qr_from_text(TEST_TEXT, size=size, image_format='png') qr3 = qr_from_text(TEST_TEXT, options=QRCodeOptions(size=size, image_format='png')) if REFRESH_REFERENCE_IMAGES: match = IMAGE_TAG_BASE64_DATA_RE.search(qr1) source_image_data = match.group('data') write_png_content_to_file(result_file_name, base64.b64decode(source_image_data)) result = base64.b64encode( get_png_content_from_file_name(result_file_name)).decode( 'utf-8') self.assertEqual(qr1, qr2) self.assertEqual(qr1, qr3) self.assertEqual(qr1, BASE64_PNG_IMAGE_TEMPLATE % result)
def test_size(self): base_ref_file_name = 'qrfromtext_size' sizes = [ 't', 'T', 's', 'S', None, -1, 0, 'm', 'M', 'l', 'L', 'h', 'H', '6', 6, '8', 8, '10', 10 ] size_names = ['tiny'] * 2 + ['small'] * 2 + ['medium'] * 5 + [ 'large' ] * 2 + ['huge'] * 2 + ['6'] * 2 + ['8'] * 2 + ['10'] * 2 for i in range(len(sizes)): size = sizes[i] print('Testing SVG with size %s' % size) size_name = size_names[i] qr1 = make_embedded_qr_code(TEST_TEXT, QRCodeOptions(size=size)) qr2 = qr_from_text(TEST_TEXT, size=size) qr3 = qr_from_text(TEST_TEXT, size=size, image_format='svg') qr4 = qr_from_text(TEST_TEXT, options=QRCodeOptions(size=size, image_format='svg')) qr5 = qr_from_text(TEST_TEXT, size=size, image_format='invalid-format-name') result_file_name = '%s_%s' % (base_ref_file_name, size_name) if REFRESH_REFERENCE_IMAGES: write_svg_content_to_file(result_file_name, qr1) result = get_svg_content_from_file_name(result_file_name) self.assertEqual(qr1, qr2) self.assertEqual(qr1, qr3) self.assertEqual(qr1, qr4) self.assertEqual(qr1, qr5) self.assertEqual(qr1, result)
def test_version(self): base_file_name = "qrfromtext_version" versions = [ None, -1, 0, 41, '-1', '0', '41', 'blabla', 1, '1', 2, '2', 4, '4' ] version_names = ['default'] * 10 + ['2', '2', '4', '4'] for i in range(len(versions)): version = versions[i] print('Testing SVG with version %s' % version) version_name = version_names[i] qr1 = make_embedded_qr_code(TEST_TEXT, QRCodeOptions(version=version)) qr2 = qr_from_text(TEST_TEXT, version=version) qr3 = qr_from_text(TEST_TEXT, version=version, image_format='svg') qr4 = qr_from_text(TEST_TEXT, version=version, image_format='SVG') qr5 = qr_from_text(TEST_TEXT, options=QRCodeOptions(version=version, image_format='SVG')) qr6 = qr_from_text(TEST_TEXT, version=version, image_format='invalid-format-name') result_file_name = '%s_%s' % (base_file_name, version_name) if REFRESH_REFERENCE_IMAGES: write_svg_content_to_file(result_file_name, qr1) result = get_svg_content_from_file_name(result_file_name) self.assertEqual(qr1, qr2) self.assertEqual(qr1, qr3) self.assertEqual(qr1, qr4) self.assertEqual(qr1, qr5) self.assertEqual(qr1, qr6) self.assertEqual(qr1, result)
def qr_code(self): return qr_from_text(self.qr_url(), size='3', image_format='png', border=2)