File python-ghostscript-update-tests.patch of Package python-ghostscript
diff -Nru ghostscript-0.7/MANIFEST.in ghostscript-0.7-update-tests/MANIFEST.in
--- ghostscript-0.7/MANIFEST.in 2021-03-06 12:54:56.000000000 -0300
+++ ghostscript-0.7-update-tests/MANIFEST.in 2024-09-16 09:39:36.434531108 -0300
@@ -1,5 +1,5 @@
include COPYING
include README.txt
exclude .gitgnore
-recursive-include test *.xml *.py *.bmp
+recursive-include test *.xml *.py *.bmp *.ps
#recursive-include doc *.html *.1
Binary files ghostscript-0.7/test/hello_world.bmp and ghostscript-0.7-update-tests/test/hello_world.bmp differ
diff -Nru ghostscript-0.7/test/test_highlevel.py ghostscript-0.7-update-tests/test/test_highlevel.py
--- ghostscript-0.7/test/test_highlevel.py 2021-03-06 12:54:56.000000000 -0300
+++ ghostscript-0.7-update-tests/test/test_highlevel.py 2024-09-16 10:10:16.046587248 -0300
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of python-ghostscript.
-# Copyright 2010-2021 by Hartmut Goebel <h.goebel@crazy-compilers.com>
+# Copyright 2010-2023 by Hartmut Goebel <h.goebel@crazy-compilers.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
@@ -14,39 +14,33 @@
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
-__copyright__ = "Copyright 2010-2021 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
+__copyright__ = "Copyright 2010-2023 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
import io
-import sys, os
-import locale # required to encode file paths
import binascii
+import pathlib
import warnings
-import py, pytest
+import pytest
import ghostscript as gslib
-postscript_img = b"""
- /Helvetica findfont 12 scalefont setfont
- 0 0 moveto
- (Hello World) show
- showpage
- """
-
HELLO_WORLD = ''.join(('%x' % ord(c) for c in 'Hello World'))
postscript_doc = ('<%s> = flush' % HELLO_WORLD).encode('ascii')
STDARGS = ['test.py', '-dNOPAUSE', '-dBATCH', '-dSAFER', '-q',
- '-sDEVICE=bmp16', '-g80x12']
+ '-sDEVICE=bmp16', '-g80x20']
-TEST_PIC_FILENAME = os.path.join(os.path.dirname(__file__), 'hello_world.bmp')
-TEST_PIC_DATA = py.path.local(TEST_PIC_FILENAME).read('rb')
+POSTSCRIPT_FILE = pathlib.Path(__file__).with_name('testimage.ps')
+POSTSCRIPT_DATA = POSTSCRIPT_FILE.read_bytes()
+TEST_PIC = POSTSCRIPT_FILE.with_suffix('.bmp')
+TEST_PIC_DATA = TEST_PIC.read_bytes()
# Ensure the instanse is removed after all high-level tests have been
@@ -71,7 +65,7 @@
def test_revision_instance(instance):
- with gslib.Ghostscript('-dBATCH', '-q') as gs:
+ with gslib.Ghostscript('test.py', '-dBATCH', '-q') as gs:
rev1 = gs.revision()
rev2 = gslib.revision()
assert rev1 == rev2
@@ -80,7 +74,7 @@
def test_simple(instance, tmpdir):
"""Let ghostscript read from a file and write to a file"""
infile = tmpdir.join('in.ps')
- infile.write(postscript_img)
+ infile.write(POSTSCRIPT_DATA)
outfile = tmpdir.join('out.bmp')
# Using a context with an empty body looks not like good code, So
@@ -95,7 +89,7 @@
def test_unicode_arguments(instance, tmpdir):
"""Let ghostscript read from a file and write to a file"""
infile = tmpdir.join('in-äöü.ps')
- infile.write(postscript_img)
+ infile.write(POSTSCRIPT_DATA)
outfile = tmpdir.join('outäöü.bmp')
gs = gslib.Ghostscript(*STDARGS, '-sOutputFile=%s' % outfile, str(infile))
@@ -108,7 +102,7 @@
def test_run_string_empty(instance, tmpdir):
"""Let ghostscript read from a file and write to a file"""
infile = tmpdir.join('in.ps')
- infile.write(postscript_img)
+ infile.write(POSTSCRIPT_DATA)
outfile = tmpdir.join('out.bmp')
with gslib.Ghostscript(*STDARGS, '-sOutputFile=%s' % outfile) as gs:
@@ -128,7 +122,7 @@
outfile = tmpdir.join('out.bmp')
with gslib.Ghostscript(*STDARGS, '-sOutputFile=%s' % outfile) as gs:
- gs.run_string(postscript_img)
+ gs.run_string(POSTSCRIPT_DATA)
data = outfile.read('rb')
assert data == TEST_PIC_DATA
@@ -138,7 +132,7 @@
"""Let ghostscript read from stdin and write to a file"""
outfile = tmpdir.join('out.bmp')
gs = gslib.Ghostscript(*STDARGS, '-sOutputFile=%s' % outfile, '-',
- stdin=io.BytesIO(postscript_img))
+ stdin=io.BytesIO(POSTSCRIPT_DATA))
gs.exit()
data = outfile.read('rb')
@@ -176,15 +170,13 @@
keep stdout on the console.
"""
stderr = io.BytesIO() # buffer for collecting stderr
- try:
+ with pytest.raises(gslib.GhostscriptError):
+ # this call is expected to fail due to the intended error in
+ # the postscript code
with gslib.Ghostscript(*STDARGS, '-',
stdin=io.BytesIO(b'foobar'),
stderr=stderr):
- # this call is expected to fail due to the intended error in
- # the postscript code
pass
- except gslib.GhostscriptError:
- pass
data = stderr.getvalue()
assert b'Unrecoverable error' in data
@@ -197,15 +189,13 @@
"""
stdout = io.BytesIO() # buffer for collecting the output
stderr = io.BytesIO() # buffer for collecting stderr
- try:
+ with pytest.raises(gslib.GhostscriptError):
+ # this call is expected to fail due to the intended error in
+ # the postscript code
with gslib.Ghostscript(*STDARGS, '-',
stdin=io.BytesIO(b'foobar'),
stdout=stdout, stderr=stderr):
- # this call is expected to fail due to the intended error in
- # the postscript code
pass
- except gslib.GhostscriptError:
- pass
data = stdout.getvalue()
assert b'Error: /undefined in foobar' in data
@@ -219,8 +209,9 @@
# Cause all warnings to always be triggered
warnings.simplefilter("always")
# Trigger the warning
- with gslib.Ghostscript(b'-dBATCH', b'-q') as gs:
+ with gslib.Ghostscript(b'test.py', b'-dBATCH', b'-q') as gs:
pass
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "deprecated" in str(w[-1].message)
+
Binary files ghostscript-0.7/test/testimage.bmp and ghostscript-0.7-update-tests/test/testimage.bmp differ
diff -Nru ghostscript-0.7/test/testimage.ps ghostscript-0.7-update-tests/test/testimage.ps
--- ghostscript-0.7/test/testimage.ps 1969-12-31 21:00:00.000000000 -0300
+++ ghostscript-0.7-update-tests/test/testimage.ps 2024-09-16 09:42:20.618536118 -0300
@@ -0,0 +1,22 @@
+%!PS-Adobe-3.0
+%%BoundingBox: 0 0 80 50
+newpath
+0 0 moveto
+0 20 rlineto
+40 0 rlineto
+closepath
+gsave
+0.5 setgray
+fill
+grestore
+newpath
+40 0 moveto
+0 20 rlineto
+40 0 rlineto
+closepath
+gsave
+0.7 setgray
+fill
+grestore
+showpage
+
diff -Nru ghostscript-0.7/test/test_lowlevel.py ghostscript-0.7-update-tests/test/test_lowlevel.py
--- ghostscript-0.7/test/test_lowlevel.py 2021-03-06 12:54:56.000000000 -0300
+++ ghostscript-0.7-update-tests/test/test_lowlevel.py 2024-09-16 10:08:18.602583664 -0300
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of python-ghostscript.
-# Copyright 2010-2021 by Hartmut Goebel <h.goebel@crazy-compilers.com>
+# Copyright 2010-2023 by Hartmut Goebel <h.goebel@crazy-compilers.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
@@ -14,41 +14,41 @@
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
__author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>"
-__copyright__ = "Copyright 2010-2021 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
+__copyright__ = "Copyright 2010-2023 by Hartmut Goebel <h.goebel@crazy-compilers.com>"
__licence__ = "GNU General Public License version 3 (GPL v3)"
import io
-import sys, os
-import locale # required to encode file paths
+import locale # required to encode arguments
import binascii
+import pathlib
-import py
+import pytest
import ghostscript._gsprint as gs
-postscript_img = b"""
- /Helvetica findfont 12 scalefont setfont
- 0 0 moveto
- (Hello World) show
- showpage
- """
HELLO_WORLD = ''.join(('%x' % ord(c) for c in 'Hello World'))
#HELLO_WORLD = binascii.hexlify('Hello World')
postscript_doc = ('<%s> = flush' % HELLO_WORLD).encode('ascii')
+# For the low-level interface arguments have to be bytes. Encode them
+# using local encoding to save calling set_arg_encoding().
STDARGS = [b'test.py', b'-dNOPAUSE', b'-dBATCH', b'-dSAFER', b'-q',
- b'-sDEVICE=bmp16', b'-g80x12']
+ b'-sDEVICE=bmp16', b'-g80x20']
-TEST_PIC_FILENAME = os.path.join(os.path.dirname(__file__), 'hello_world.bmp')
-TEST_PIC_DATA = py.path.local(TEST_PIC_FILENAME).read('rb')
+POSTSCRIPT_FILE = pathlib.Path(__file__).with_name('testimage.ps')
+POSTSCRIPT_DATA = POSTSCRIPT_FILE.read_bytes()
+TEST_PIC = POSTSCRIPT_FILE.with_suffix('.bmp')
+TEST_PIC_DATA = TEST_PIC.read_bytes()
def _encode(*args):
+ # For the low-level interface arguments have to be bytes. Encode
+ # them using local encoding to save calling set_arg_encoding().
encoding = locale.getpreferredencoding()
return [a.encode(encoding) for a in args]
@@ -70,8 +70,8 @@
instance = gs.new_instance()
try:
- gs.init_with_args(instance, args)
- gs.run_string(instance, postscript_img)
+ assert gs.init_with_args(instance, args) == 0
+ assert gs.run_string(instance, POSTSCRIPT_DATA) == 0
finally:
gs.exit(instance)
gs.delete_instance(instance)
@@ -80,17 +80,33 @@
assert data == TEST_PIC_DATA
+def test_run_bugyy_string(tmpdir):
+ """
+ Test whether the program flow (try/finally, gs.exit,
+ gs.delete_instance) is correct if executing fails.
+ """
+ args = STDARGS
+ instance = gs.new_instance()
+ try:
+ assert gs.init_with_args(instance, args) == 0
+ with pytest.raises(gs.GhostscriptError):
+ gs.run_string(instance, b"invalid postscript code")
+ finally:
+ gs.exit(instance)
+ gs.delete_instance(instance)
+
+
def test_simple(tmpdir):
"""Let ghostscript read from a file and write to a file"""
infile = tmpdir.join('in.ps')
- infile.write(postscript_img)
+ infile.write(POSTSCRIPT_DATA)
outfile = tmpdir.join('out.bmp')
args = STDARGS + _encode('-sOutputFile=%s' % outfile, str(infile))
instance = gs.new_instance()
try:
- gs.init_with_args(instance, args)
+ assert gs.init_with_args(instance, args) == 0
finally:
gs.exit(instance)
gs.delete_instance(instance)
@@ -103,7 +119,7 @@
instance = gs.new_instance()
# wrappers like in
- # http://ghostscript.com/doc/8.54/API.htm#Example_usage
+ # https://ghostscript.readthedocs.io/en/gs10.0.0/API.html#Example_usage
if stdin is not None: stdin = gs._wrap_stdin(stdin)
if stdout is not None: stdout = gs._wrap_stdout(stdout)
if stderr is not None: stderr = gs._wrap_stderr(stderr)
@@ -122,7 +138,7 @@
args = STDARGS + _encode('-sOutputFile=%s' % outfile, '-')
- _gs_stdio(args, stdin=io.BytesIO(postscript_img))
+ _gs_stdio(args, stdin=io.BytesIO(POSTSCRIPT_DATA))
data = outfile.read('rb')
assert data == TEST_PIC_DATA
@@ -164,12 +180,10 @@
stderr = io.BytesIO() # buffer for collecting stderr
- try:
+ with pytest.raises(gs.GhostscriptError):
# this call is expected to fail due to the intended error in
# the postscript code
_gs_stdio(args, stdin=io.BytesIO(b'foobar'), stderr=stderr)
- except gs.GhostscriptError:
- pass
data = stderr.getvalue()
assert b'Unrecoverable error' in data
@@ -185,13 +199,11 @@
stdout = io.BytesIO() # buffer for collecting the output
stderr = io.BytesIO() # buffer for collecting stderr
- try:
+ with pytest.raises(gs.GhostscriptError):
# this call is expected to fail due to the intended error in
# the postscript code
_gs_stdio(args,
stdin=io.BytesIO(b'foobar'), stdout=stdout, stderr=stderr)
- except gs.GhostscriptError:
- pass
data = stdout.getvalue()
assert b'Error: /undefined in foobar' in data
@@ -206,10 +218,11 @@
Use command line ghostscript to generate the image used in testing
"""
import subprocess
- outfile = TEST_PIC_FILENAME
+ args = ['gs'] + STDARGS[1:] + _encode('-sOutputFile=%s' % TEST_PIC,
+ str(POSTSCRIPT_FILE))
+ subprocess.Popen(args).wait()
- args = ['gs'] + STDARGS[1:] + _encode('-sOutputFile=%s' % outfile, '-')
- subprocess.Popen(args).communicate(postscript_doc)
if __name__ == '__main__':
generate_test_picture()
+