tests: integration tests for qvm-convert-img
Actual tool is in separate repository, but the backend module is here. Also, other tests for imgconverter are already here. QubesOS/qubes-issues#3085
This commit is contained in:
parent
34e3c3acf3
commit
2b1f8931a6
95
imgconverter/qubesimgconverter/test_integ.py
Normal file
95
imgconverter/qubesimgconverter/test_integ.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
# vim: fileencoding=utf-8
|
||||||
|
|
||||||
|
#
|
||||||
|
# The Qubes OS Project, https://www.qubes-os.org/
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017
|
||||||
|
# Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import qubes.tests.extra
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyPep8Naming
|
||||||
|
class TC_00_ImgConverter(qubes.tests.extra.ExtraTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TC_00_ImgConverter, self).setUp()
|
||||||
|
# noinspection PyAttributeOutsideInit
|
||||||
|
self.vm = self.create_vms(["vm"])[0]
|
||||||
|
self.vm.start()
|
||||||
|
|
||||||
|
self.image_size = 16
|
||||||
|
# RGB data for the image
|
||||||
|
self.image_data = [
|
||||||
|
(0xff // self.image_size * x, 0x80, 0xff // self.image_size * y,
|
||||||
|
0xff)
|
||||||
|
for x in range(self.image_size)
|
||||||
|
for y in range(self.image_size)]
|
||||||
|
|
||||||
|
def create_img(self, filename):
|
||||||
|
'''Create image file with given sample content
|
||||||
|
|
||||||
|
:param filename: output filename
|
||||||
|
'''
|
||||||
|
p = self.vm.run(
|
||||||
|
'convert -size {}x{} -depth 8 rgba:- "{}" 2>&1'.format(
|
||||||
|
self.image_size, self.image_size, filename),
|
||||||
|
passio_popen=True)
|
||||||
|
bytes_data = bytes(bytearray(itertools.chain(*self.image_data)))
|
||||||
|
(stdout, _) = p.communicate(bytes_data)
|
||||||
|
if p.returncode != 0:
|
||||||
|
self.skipTest('failed to create test image: {}'.format(stdout))
|
||||||
|
|
||||||
|
def assertCorrectlyTransformed(self, orig_filename, trusted_filename):
|
||||||
|
self.assertEquals(
|
||||||
|
self.vm.run('test -r "{}"'.format(trusted_filename), wait=True), 0)
|
||||||
|
self.assertEquals(
|
||||||
|
self.vm.run('test -r "{}"'.format(orig_filename), wait=True), 0)
|
||||||
|
# retrieve original image too, to compensate for compression
|
||||||
|
p = self.vm.run('convert "{}" rgb:-'.format(orig_filename),
|
||||||
|
passio_popen=True)
|
||||||
|
orig_image_data, _ = p.communicate()
|
||||||
|
p = self.vm.run('convert "{}" rgb:-'.format(trusted_filename),
|
||||||
|
passio_popen=True)
|
||||||
|
trusted_image_data, _ = p.communicate()
|
||||||
|
self.assertEquals(orig_image_data, trusted_image_data)
|
||||||
|
|
||||||
|
def test_000_png(self):
|
||||||
|
self.create_img('test.png')
|
||||||
|
p = self.vm.run('qvm-convert-img test.png trusted.png 2>&1',
|
||||||
|
passio_popen=True)
|
||||||
|
(stdout, _) = p.communicate()
|
||||||
|
self.assertEquals(p.returncode, 0, 'qvm-convert-img failed: {}'.format(
|
||||||
|
stdout))
|
||||||
|
self.assertCorrectlyTransformed('test.png', 'trusted.png')
|
||||||
|
|
||||||
|
def test_010_filename_with_spaces(self):
|
||||||
|
self.create_img('test with spaces.png')
|
||||||
|
p = self.vm.run('qvm-convert-img "test with spaces.png" '
|
||||||
|
'"trusted with spaces.png" 2>&1',
|
||||||
|
passio_popen=True)
|
||||||
|
(stdout, _) = p.communicate()
|
||||||
|
self.assertEquals(p.returncode, 0, 'qvm-convert-img failed: {}'.format(
|
||||||
|
stdout))
|
||||||
|
self.assertCorrectlyTransformed(
|
||||||
|
'test with spaces.png', 'trusted with spaces.png')
|
||||||
|
|
||||||
|
|
||||||
|
def list_tests():
|
||||||
|
tests = [TC_00_ImgConverter]
|
||||||
|
return tests
|
@ -9,6 +9,11 @@ setuptools.setup(
|
|||||||
license='GPL2+',
|
license='GPL2+',
|
||||||
url='https://www.qubes-os.org/',
|
url='https://www.qubes-os.org/',
|
||||||
packages=['qubesimgconverter'],
|
packages=['qubesimgconverter'],
|
||||||
|
entry_points={
|
||||||
|
'qubes.tests.extra.for_template':
|
||||||
|
'qubesimgconverter = qubesimgconverter.test_integ:list_tests',
|
||||||
|
}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# vim: ts=4 sts=4 sw=4 et
|
# vim: ts=4 sts=4 sw=4 et
|
||||||
|
@ -117,13 +117,15 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
%{python_sitelib}/qubesimgconverter/__init__.py*
|
%{python_sitelib}/qubesimgconverter/__init__.py*
|
||||||
%{python_sitelib}/qubesimgconverter/imggen.py*
|
%{python_sitelib}/qubesimgconverter/imggen.py*
|
||||||
%{python_sitelib}/qubesimgconverter/test.py*
|
%{python_sitelib}/qubesimgconverter/test.py*
|
||||||
%{python_sitelib}/qubesimgconverter-%{version}-py?.?.egg-info/*
|
%{python_sitelib}/qubesimgconverter/test_integ.py*
|
||||||
|
%{python_sitelib}/qubesimgconverter-%{version}-py?.?.egg-info
|
||||||
|
|
||||||
%files -n python3-qubesimgconverter
|
%files -n python3-qubesimgconverter
|
||||||
%{python3_sitelib}/qubesimgconverter/__init__.py
|
%{python3_sitelib}/qubesimgconverter/__init__.py
|
||||||
%{python3_sitelib}/qubesimgconverter/imggen.py
|
%{python3_sitelib}/qubesimgconverter/imggen.py
|
||||||
%{python3_sitelib}/qubesimgconverter/test.py
|
%{python3_sitelib}/qubesimgconverter/test.py
|
||||||
%{python3_sitelib}/qubesimgconverter-%{version}-py?.?.egg-info/*
|
%{python3_sitelib}/qubesimgconverter/test_integ.py
|
||||||
|
%{python3_sitelib}/qubesimgconverter-%{version}-py?.?.egg-info
|
||||||
%{python3_sitelib}/qubesimgconverter/__pycache__
|
%{python3_sitelib}/qubesimgconverter/__pycache__
|
||||||
|
|
||||||
%files libs
|
%files libs
|
||||||
|
Loading…
Reference in New Issue
Block a user