/usr/lib/python2.7/dist-packages/pyavm/tests/test_io.py is in python-pyavm 0.9.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | from __future__ import print_function, division
import os
import glob
import warnings
import pytest
try:
from PIL import Image
except ImportError:
try:
import Image
except ImportError:
pytest.skip()
try:
import numpy as np
except ImportError:
pytest.skip()
from .. import AVM
ROOT = os.path.dirname(os.path.abspath(__file__))
XML_FILES = glob.glob(os.path.join(ROOT, 'data', '*.xml'))
@pytest.mark.parametrize('xml_file', XML_FILES)
def test_io_png(tmpdir, xml_file):
avm = AVM.from_xml_file(xml_file)
filename_in = tmpdir.join('test_in.png').strpath
filename_out = tmpdir.join('test_out.png').strpath
i = Image.fromarray(np.ones((16, 16), dtype=np.uint8))
i.save(filename_in)
avm.embed(filename_in, filename_out, verify=True)
@pytest.mark.parametrize('xml_file', XML_FILES)
def test_io_jpeg(tmpdir, xml_file):
avm = AVM.from_xml_file(xml_file)
filename_in = tmpdir.join('test_in.jpg').strpath
filename_out = tmpdir.join('test_out.jpg').strpath
i = Image.fromarray(np.ones((16, 16), dtype=np.uint8))
i.save(filename_in)
avm.embed(filename_in, filename_out, verify=True)
@pytest.mark.parametrize('xml_file', XML_FILES)
def test_io_png_repeat(tmpdir, xml_file):
warnings.simplefilter('always')
avm = AVM.from_xml_file(xml_file)
filename_in = tmpdir.join('test_in.png').strpath
filename_out_1 = tmpdir.join('test_out_1.png').strpath
filename_out_2 = tmpdir.join('test_out_2.png').strpath
i = Image.fromarray(np.ones((16, 16), dtype=np.uint8))
i.save(filename_in)
with warnings.catch_warnings(record=True) as w:
avm.embed(filename_in, filename_out_1, verify=True)
messages = [str(x.message) for x in w]
assert 'Discarding existing XMP packet from PNG file' not in messages
with warnings.catch_warnings(record=True) as w:
avm.embed(filename_out_1, filename_out_2, verify=True)
messages = [str(x.message) for x in w]
assert 'Discarding existing XMP packet from PNG file' in messages
@pytest.mark.parametrize('xml_file', XML_FILES)
def test_io_jpeg_repeat(tmpdir, xml_file):
warnings.simplefilter('always')
avm = AVM.from_xml_file(xml_file)
filename_in = tmpdir.join('test_in.jpg').strpath
filename_out_1 = tmpdir.join('test_out_1.jpg').strpath
filename_out_2 = tmpdir.join('test_out_2.jpg').strpath
i = Image.fromarray(np.ones((16, 16), dtype=np.uint8))
i.save(filename_in)
with warnings.catch_warnings(record=True) as w:
avm.embed(filename_in, filename_out_1, verify=True)
messages = [str(x.message) for x in w]
assert 'Discarding existing XMP packet from JPEG file' not in messages
with warnings.catch_warnings(record=True) as w:
avm.embed(filename_out_1, filename_out_2, verify=True)
messages = [str(x.message) for x in w]
assert 'Discarding existing XMP packet from JPEG file' in messages
|