Skip to content

Commit 8aa440c

Browse files
authored
DEV: Add mutmut (#760)
1 parent eda50ac commit 8aa440c

File tree

8 files changed

+47
-28
lines changed

8 files changed

+47
-28
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ build
77
*.egg-info/
88
dist/*
99

10+
#
11+
.mutmut-cache
12+
mutmut-results.*
13+
1014
# Code coverage artifacts
1115
.coverage*
1216
coverage.xml

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ clean:
1515

1616
test:
1717
pytest Tests --cov --cov-report term-missing -vv --cov-report html
18+
19+
mutation-test:
20+
mutmut run
21+
22+
mutmut-results:
23+
mutmut junitxml --suspicious-policy=ignore --untested-policy=ignore > mutmut-results.xml
24+
junit2html mutmut-results.xml mutmut-results.html

PyPDF2/filters.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ def decode(data, decodeParms):
157157
# unsupported predictor
158158
raise PdfReadError("Unsupported flatedecode predictor %r" % predictor)
159159
return data
160-
decode = staticmethod(decode)
160+
decode = staticmethod(decode) # type: ignore
161161

162162
def encode(data):
163163
return compress(data)
164-
encode = staticmethod(encode)
164+
encode = staticmethod(encode) # type: ignore
165165

166166

167167
class ASCIIHexDecode(object):
@@ -183,7 +183,7 @@ def decode(data, decodeParms=None):
183183
x += 1
184184
assert char == ""
185185
return retval
186-
decode = staticmethod(decode)
186+
decode = staticmethod(decode) # type: ignore
187187

188188

189189
class LZWDecode(object):
@@ -339,17 +339,17 @@ def decode(data, decodeParms=None):
339339
out += struct.pack(b'>L',b)[:n-1]
340340
break
341341
return bytes(out)
342-
decode = staticmethod(decode)
342+
decode = staticmethod(decode) # type: ignore
343343

344344
class DCTDecode(object):
345345
def decode(data, decodeParms=None):
346346
return data
347-
decode = staticmethod(decode)
347+
decode = staticmethod(decode) # type: ignore
348348

349349
class JPXDecode(object):
350350
def decode(data, decodeParms=None):
351351
return data
352-
decode = staticmethod(decode)
352+
decode = staticmethod(decode) # type: ignore
353353

354354
class CCITTFaxDecode(object):
355355
def decode(data, decodeParms=None, height=0):
@@ -384,7 +384,7 @@ def decode(data, decodeParms=None, height=0):
384384

385385
return tiffHeader + data
386386

387-
decode = staticmethod(decode)
387+
decode = staticmethod(decode) # type: ignore
388388

389389
def decodeStreamData(stream):
390390
from .generic import NameObject

PyPDF2/generic.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# vim: sw=4:expandtab:foldmethod=marker
2-
#
31
# Copyright (c) 2006, Mathieu Fenniak
42
# All rights reserved.
53
#
@@ -114,7 +112,7 @@ def readFromStream(stream):
114112
if nulltxt != b_("null"):
115113
raise utils.PdfReadError("Could not read Null object")
116114
return NullObject()
117-
readFromStream = staticmethod(readFromStream)
115+
readFromStream = staticmethod(readFromStream) # type: ignore
118116

119117

120118
class BooleanObject(PdfObject):
@@ -136,7 +134,7 @@ def readFromStream(stream):
136134
return BooleanObject(False)
137135
else:
138136
raise utils.PdfReadError('Could not read Boolean object')
139-
readFromStream = staticmethod(readFromStream)
137+
readFromStream = staticmethod(readFromStream) # type: ignore
140138

141139

142140
class ArrayObject(list, PdfObject):
@@ -166,7 +164,7 @@ def readFromStream(stream, pdf):
166164
# read and append obj
167165
arr.append(readObject(stream, pdf))
168166
return arr
169-
readFromStream = staticmethod(readFromStream)
167+
readFromStream = staticmethod(readFromStream) # type: ignore
170168

171169

172170
class IndirectObject(PdfObject):
@@ -219,7 +217,7 @@ def readFromStream(stream, pdf):
219217
if r != b_("R"):
220218
raise utils.PdfReadError("Error reading indirect object reference at byte %s" % utils.hexStr(stream.tell()))
221219
return IndirectObject(int(idnum), int(generation), pdf)
222-
readFromStream = staticmethod(readFromStream)
220+
readFromStream = staticmethod(readFromStream) # type: ignore
223221

224222

225223
class FloatObject(decimal.Decimal, PdfObject):
@@ -270,7 +268,7 @@ def readFromStream(stream):
270268
return FloatObject(num)
271269
else:
272270
return NumberObject(num)
273-
readFromStream = staticmethod(readFromStream)
271+
readFromStream = staticmethod(readFromStream) # type: ignore
274272

275273

276274
def createStringObject(string):
@@ -391,7 +389,7 @@ def readStringFromStream(stream):
391389
return createStringObject(txt)
392390

393391

394-
class ByteStringObject(utils.bytes_type, PdfObject):
392+
class ByteStringObject(utils.bytes_type, PdfObject): # type: ignore
395393
"""
396394
Represents a string object where the text encoding could not be determined.
397395
This occurs quite often, as the PDF spec doesn't provide an alternate way to
@@ -413,7 +411,7 @@ def writeToStream(self, stream, encryption_key):
413411
stream.write(b_(">"))
414412

415413

416-
class TextStringObject(utils.string_type, PdfObject):
414+
class TextStringObject(utils.string_type, PdfObject): # type: ignore
417415
"""
418416
Represents a string object that has been decoded into a real unicode string.
419417
If read from a PDF document, this string appeared to match the
@@ -497,7 +495,7 @@ def readFromStream(stream, pdf):
497495
else:
498496
raise utils.PdfReadError("Illegal character in Name Object")
499497

500-
readFromStream = staticmethod(readFromStream)
498+
readFromStream = staticmethod(readFromStream) # type: ignore
501499

502500

503501
class DictionaryObject(dict, PdfObject):
@@ -642,7 +640,7 @@ def readFromStream(stream, pdf):
642640
retval = DictionaryObject()
643641
retval.update(data)
644642
return retval
645-
readFromStream = staticmethod(readFromStream)
643+
readFromStream = staticmethod(readFromStream) # type: ignore
646644

647645

648646
class TreeObject(DictionaryObject):
@@ -802,7 +800,7 @@ def initializeFromDictionary(data):
802800
del data["/Length"]
803801
retval.update(data)
804802
return retval
805-
initializeFromDictionary = staticmethod(initializeFromDictionary)
803+
initializeFromDictionary = staticmethod(initializeFromDictionary) # type: ignore
806804

807805
def flateEncode(self):
808806
if "/Filter" in self:

PyPDF2/pdf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ def createBlankPage(pdf=None, width=None, height=None):
22242224
RectangleObject([0, 0, width, height]))
22252225

22262226
return page
2227-
createBlankPage = staticmethod(createBlankPage)
2227+
createBlankPage = staticmethod(createBlankPage) # type: ignore
22282228

22292229
def rotateClockwise(self, angle):
22302230
"""
@@ -2266,7 +2266,7 @@ def _mergeResources(res1, res2, resource):
22662266
elif key not in newRes:
22672267
newRes[key] = page2Res.raw_get(key)
22682268
return newRes, renameRes
2269-
_mergeResources = staticmethod(_mergeResources)
2269+
_mergeResources = staticmethod(_mergeResources) # type: ignore
22702270

22712271
def _contentStreamRename(stream, rename, pdf):
22722272
if not rename:
@@ -2286,7 +2286,7 @@ def _contentStreamRename(stream, rename, pdf):
22862286
else:
22872287
raise KeyError ("type of operands is %s" % type (operands))
22882288
return stream
2289-
_contentStreamRename = staticmethod(_contentStreamRename)
2289+
_contentStreamRename = staticmethod(_contentStreamRename) # type: ignore
22902290

22912291
def _pushPopGS(contents, pdf):
22922292
# adds a graphics state "push" and "pop" to the beginning and end
@@ -2296,7 +2296,7 @@ def _pushPopGS(contents, pdf):
22962296
stream.operations.insert(0, [[], "q"])
22972297
stream.operations.append([[], "Q"])
22982298
return stream
2299-
_pushPopGS = staticmethod(_pushPopGS)
2299+
_pushPopGS = staticmethod(_pushPopGS) # type: ignore
23002300

23012301
def _addTransformationMatrix(contents, pdf, ctm):
23022302
# adds transformation matrix at the beginning of the given
@@ -2307,7 +2307,7 @@ def _addTransformationMatrix(contents, pdf, ctm):
23072307
FloatObject(c), FloatObject(d), FloatObject(e),
23082308
FloatObject(f)], " cm"])
23092309
return contents
2310-
_addTransformationMatrix = staticmethod(_addTransformationMatrix)
2310+
_addTransformationMatrix = staticmethod(_addTransformationMatrix) # type: ignore
23112311

23122312
def getContents(self):
23132313
"""

PyPDF2/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@
3535
import sys
3636

3737
try:
38-
import __builtin__ as builtins
39-
except ImportError: # Py3
4038
import builtins
39+
from typing import Dict
40+
except ImportError: # Py2.7
41+
import __builtin__ as builtins # type: ignore
4142

4243
ERR_STREAM_TRUNCATED_PREMATURELY = "Stream has ended unexpectedly"
4344
xrange_fn = getattr(builtins, "xrange", range)
4445
_basestring = getattr(builtins, "basestring", str)
4546

4647
bytes_type = type(bytes()) # Works the same in Python 2.X and 3.X
4748
string_type = getattr(builtins, "unicode", str)
48-
int_types = (int, long) if sys.version_info[0] < 3 else (int,) # noqa
49+
int_types = (int, long) if sys.version_info[0] < 3 else (int,) # type: ignore # noqa
4950

5051

5152
# Make basic type tests more consistent
@@ -227,7 +228,7 @@ class PdfStreamError(PdfReadError):
227228
def b_(s):
228229
return s
229230
else:
230-
B_CACHE = {}
231+
B_CACHE = {} # type: Dict[str, bytes]
231232

232233
def b_(s):
233234
bc = B_CACHE

Tests/test_pagerange.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ def test_parse_filename_page_ranges(params, expected):
5858
def test_parse_filename_page_ranges_err():
5959
with pytest.raises(ValueError):
6060
parse_filename_page_ranges(["1:5", "foo.pdf"])
61+
62+
63+
def test_page_range_help():
64+
from PyPDF2.pagerange import PAGE_RANGE_HELP
65+
assert len(PAGE_RANGE_HELP) > 20
66+
assert "0:3" in PAGE_RANGE_HELP
67+
assert PAGE_RANGE_HELP.endswith("\n")

mutmut-test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash -e
2+
pytest -x

0 commit comments

Comments
 (0)