def test_plte_colors(): fn = _make_tmp_png_filename() res = cli.main([ '--quiet-zone=green', '--finder-dark=purple', '--finder-light=yellow', '--output={0}'.format(fn), 'test' ]) with open(fn, 'rb') as f: data = io.BytesIO(f.read()) os.unlink(fn) assert 0 == res reader = PNGReader(file=data) reader.preamble() assert not reader.greyscale palette = reader.palette() assert 5 == len(palette) assert (0, 0, 0) in palette assert (255, 255, 255) in palette assert colors._color_to_rgb('green') in palette assert colors._color_to_rgb('purple') in palette assert colors._color_to_rgb('yellow') in palette
def test_plte_colors(): qr = segno.make_qr('test') buff = io.BytesIO() dark = (0, 0, 139) light = (255, 255, 255) qr.save(buff, kind='png', dark=dark, light=light, quiet_zone='green', finder_dark='purple', finder_light='yellow') buff.seek(0) reader = PNGReader(file=buff) reader.preamble() assert not reader.greyscale palette = reader.palette() assert 5 == len(palette) assert dark in palette assert light in palette assert colors._color_to_rgb('green') in palette assert colors._color_to_rgb('purple') in palette assert colors._color_to_rgb('yellow') in palette
def test_rgba_vs_rgb_conflict(): with pytest.raises(ValueError): colors._color_to_rgb('#949494E8')
def test_illegal5(): with pytest.raises(ValueError): colors._color_to_rgb((256, 0, 0))
def test_illegal4(): with pytest.raises(ValueError): colors._color_to_rgb((0, 0, 256))
def test_illegal3(): with pytest.raises(ValueError): colors._color_to_rgb((300, 300, 300))
def test_illegal2(): with pytest.raises(ValueError): colors._color_to_rgb((1, 2, 3, 256))
def test_valid_hexcodes_rgb(name, expected): rgb = colors._color_to_rgb(name) assert 3 == len(rgb) assert expected == rgb
def test_illegal(): with pytest.raises(ValueError): colors._color_to_rgb('unknown')