summarylogtreecommitdiffstats
path: root/pdf2djvu-tests-python-3.patch
blob: 3783fe6aa5c9e9a9c5a13f09704f3eca7eb87758 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-labels-null.py src/pdf2djvu-0.9.19/tests/test-labels-null.py
--- src/pdf2djvu-0.9.19/tests.orig/test-labels-null.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-labels-null.py	2022-09-06 19:33:44.393368987 +0200
@@ -25,9 +25,9 @@
         self.pdf2djvu().assert_()
         r = self.ls()
         r.assert_(stdout=re.compile(
-            ur'\n'
-            ur'\s*1\s+P\s+\d+\s+[\w.]+\s+T=\uFFFDnul\uFFFDl\uFFFD\n'
-            ur'\s*2\s+P\s+\d+\s+[\w.]+\s+T=1\n'.encode('UTF-8')
+            r'\n'
+            r'\s*1\s+P\s+\d+\s+[\w.]+\s+T=\uFFFDnul\uFFFDl\uFFFD\n'
+            r'\s*2\s+P\s+\d+\s+[\w.]+\s+T=1\n'
         ))
 
 # vim:ts=4 sts=4 sw=4 et
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-nfkc-apf.py src/pdf2djvu-0.9.19/tests/test-nfkc-apf.py
--- src/pdf2djvu-0.9.19/tests.orig/test-nfkc-apf.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-nfkc-apf.py	2022-09-06 19:33:44.390035653 +0200
@@ -25,8 +25,10 @@
     # + fixed in 0.8
 
     text = u'\N{LATIN SMALL LIGATURE FL}uorogra\N{LATIN SMALL LIGATURE FI}a'
-    text_nfkc = unicodedata.normalize('NFKC', text).encode('UTF-8')
-    text_no_nfkc = text.encode('UTF-8')
+    #text_nfkc = unicodedata.normalize('NFKC', text).encode('UTF-8')
+    #text_no_nfkc = text.encode('UTF-8').decode('UTF-8')
+    text_nfkc = unicodedata.normalize('NFKC', text)
+    text_no_nfkc = text
 
     def test_nfkc(self):
         self.pdf2djvu().assert_()
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-nfkc.py src/pdf2djvu-0.9.19/tests/test-nfkc.py
--- src/pdf2djvu-0.9.19/tests.orig/test-nfkc.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-nfkc.py	2022-09-06 19:33:44.386702321 +0200
@@ -25,7 +25,7 @@
 
     text = u'¾'
     text_nfkc = '3⁄4'
-    text_no_nfkc = text.encode('UTF-8')
+    text_no_nfkc = text
 
     def test_nfkc(self):
         self.pdf2djvu().assert_()
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-nonascii.py src/pdf2djvu-0.9.19/tests/test-nonascii.py
--- src/pdf2djvu-0.9.19/tests.orig/test-nonascii.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-nonascii.py	2022-09-06 19:33:44.380035654 +0200
@@ -29,7 +29,7 @@
     def test_nonascii(self):
         locale_encoding = locale.getpreferredencoding()
         try:
-            curr_sign = u'\xA4'.encode(locale_encoding)
+            curr_sign = u'\xA4'.encode(locale_encoding).decode(locale_encoding)
         except UnicodeError:
             raise SkipTest('locale that can encode U+00A4 CURRENCY SIGN is required')
         tmpdir = tempfile.mkdtemp(prefix='pdf2djvu.test.')
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-title.py src/pdf2djvu-0.9.19/tests/test-title.py
--- src/pdf2djvu-0.9.19/tests.orig/test-title.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-title.py	2022-09-06 19:33:44.393368987 +0200
@@ -56,7 +56,7 @@
 
     def test_bad_encoding(self):
         self.require_feature('POSIX')
-        template = '{page}\xBA'
+        template = b'{page}\xBA'
         r = self.pdf2djvu('--page-title-template', template, encoding='UTF-8')
         r.assert_(stderr=re.compile('^Unable to convert page title to UTF-8:'), rc=1)
 
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-symbol.py src/pdf2djvu-0.9.19/tests/test-symbol.py
--- src/pdf2djvu-0.9.19/tests.orig/test-symbol.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-symbol.py	2022-09-06 19:33:44.393368987 +0200
@@ -45,7 +45,7 @@
         image = self.decode(fmt='pgm')
         print_pgm(image)
         for line in image:
-            sig = str.join('', (pixel for (pixel, _) in itertools.groupby(line)))
+            sig = str.join('', (chr(pixel) for (pixel, _) in itertools.groupby(line)))
             if sig not in {'\xff', '\xff\x00\xff', '\xff\x00\xff\x00\xff'}:
                 assert_fail('image does not look like uppercase delta')
 
diff -aur src/pdf2djvu-0.9.19/tests.orig/test-vector-fg.py src/pdf2djvu-0.9.19/tests/test-vector-fg.py
--- src/pdf2djvu-0.9.19/tests.orig/test-vector-fg.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/test-vector-fg.py	2022-09-06 19:33:44.393368987 +0200
@@ -30,6 +30,6 @@
         image = self.decode()
         image = self.decode(mode='foreground')
         colors = count_colors(image)
-        assert_greater(colors.get('\xFF\0\0', 0), 5000)
+        assert_greater(colors.get(b'\xFF\0\0', 0), 5000)
 
 # vim:ts=4 sts=4 sw=4 et
diff -aur src/pdf2djvu-0.9.19/tests.orig/tools.py src/pdf2djvu-0.9.19/tests/tools.py
--- src/pdf2djvu-0.9.19/tests.orig/tools.py	2022-09-06 19:33:28.200035175 +0200
+++ src/pdf2djvu-0.9.19/tests/tools.py	2022-09-06 19:33:44.393368987 +0200
@@ -14,6 +14,7 @@
 # General Public License for more details.
 
 from __future__ import print_function
+from builtins import bytes
 
 import ast
 import codecs
@@ -42,9 +42,6 @@
     assert_true,
 )
 
-if {0} and not isinstance(b'', str):  # Python 2.7 is required
-    raise RuntimeError('Python 2.7 is required')
-
 re_type = type(re.compile(''))
 
 def assert_fail(msg):
@@ -69,7 +69,7 @@
             del data['SIGCLD']
     except KeyError:
         pass
-    return dict((no, name) for name, no in data.iteritems())
+    return dict((no, name) for name, no in data.items())
 
 class _ipc_rc(int):
 
@@ -164,7 +163,8 @@
                 continue
             raise TypeError('{key!r} is an invalid keyword argument for this function'.format(key=key))
         env['LANGUAGE'] = 'en'
-        print('$', str.join(' ', map(pipes.quote, commandline)))
+        cmd_arr = [ele if isinstance(ele, str) else ele.decode('utf-8','surrogateescape') for ele in commandline]
+        print('$', str.join(' ', map(pipes.quote, cmd_arr)))
         try:
             child = ipc.Popen(list(commandline),
                 stdout=ipc.PIPE,
@@ -175,7 +174,7 @@
             exc.filename = commandline[0]
             raise
         stdout, stderr = child.communicate()
-        return ipc_result(stdout, stderr, child.returncode)
+        return ipc_result(stdout.decode('utf-8','surrogateescape'), stderr.decode('utf-8'), child.returncode)
 
     def _pdf2djvu(self, *args, **kwargs):
         quiet = ('-q',) if kwargs.pop('quiet', True) else ()
@@ -304,7 +304,7 @@
     (width, height, pixels) = match.groups()
     width = int(width)
     height = int(height)
-    pixels = memoryview(pixels)
+    pixels = memoryview(pixels.encode('utf8','surrogateescape'))
     pixels = [
         [
             pixels[(i + j):(i + j + 3)].tobytes()
@@ -331,7 +331,7 @@
     (width, height, pixels) = match.groups()
     width = int(width)
     height = int(height)
-    pixels = memoryview(pixels)
+    pixels = memoryview(pixels.encode('utf8','surrogateescape'))
     pixels = [
         pixels[i:(i + width)]
         for i in range(0, len(pixels), width)