Skip to content

Commit eb2354b

Browse files
authored
Pylint for test folder (#94)
1 parent a84f7c5 commit eb2354b

49 files changed

Lines changed: 1261 additions & 1176 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/continuous-integration-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
python -m pip install --upgrade pip
2929
pip install . -r test/requirements.txt -r docs/requirements.txt
3030
- name: Statically checking code 🔎
31-
run: pylint fpdf
31+
run: pylint fpdf test
3232
- name: Ensure code has been autoformatted with black 🖌️
3333
run: black --check .
3434
- name: Checking all PDF samples ☑

.pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[MESSAGES CONTROL]
2-
disable = attribute-defined-outside-init, blacklisted-name, fixme, invalid-name, method-hidden, missing-docstring, multiple-imports, too-few-public-methods, too-many-arguments, too-many-instance-attributes, too-many-nested-blocks, too-many-branches, too-many-lines, too-many-locals, too-many-public-methods, too-many-statements, wrong-import-order, wrong-import-position
3-
max-line-length = 180
2+
disable = attribute-defined-outside-init, blacklisted-name, fixme, invalid-name, method-hidden, missing-docstring, too-few-public-methods, too-many-arguments, too-many-instance-attributes, too-many-nested-blocks, too-many-branches, too-many-lines, too-many-locals, too-many-public-methods, too-many-statements, wrong-import-order
3+
max-line-length=88
44

55
[SIMILARITIES]
66
# Restricting duplicate-code check:

fpdf/fpdf.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ def rotate(self, angle, x=None, y=None):
781781
Use `rotation` instead.
782782
"""
783783
warnings.warn(
784-
"rotate() can produces malformed PDFs and is deprecated. Use the rotation() context manager instead.",
784+
"rotate() can produces malformed PDFs and is deprecated. "
785+
"Use the rotation() context manager instead.",
785786
PendingDeprecationWarning,
786787
)
787788
if x is None:
@@ -816,8 +817,8 @@ def rotation(self, angle, x=None, y=None):
816817
Notes
817818
-----
818819
819-
Only the rendering is altered. The `get_x()` and `get_y()` methods are not affected,
820-
nor the automatic page break mechanism.
820+
Only the rendering is altered. The `get_x()` and `get_y()` methods are not
821+
affected, nor the automatic page break mechanism.
821822
"""
822823
if x is None:
823824
x = self.x
@@ -850,12 +851,13 @@ def cell(self, w, h=0, txt="", border=0, ln=0, align="", fill=False, link=""):
850851
txt (str): String to print. Default value: empty string.
851852
border: Indicates if borders must be drawn around the cell.
852853
The value can be either a number (`0`: no border ; `1`: frame)
853-
or a string containing some or all of the following characters (in any order):
854+
or a string containing some or all of the following characters
855+
(in any order):
854856
`L`: left ; `T`: top ; `R`: right ; `B`: bottom. Default value: 0.
855857
ln (int): Indicates where the current position should go after the call.
856-
Possible values are: `0`: to the right ; `1`: to the beginning of the next line ;
857-
`2`: below. Putting 1 is equivalent to putting 0 and calling `ln` just after.
858-
Default value: 0.
858+
Possible values are: `0`: to the right ; `1`: to the beginning of the
859+
next line ; `2`: below. Putting 1 is equivalent to putting 0 and calling
860+
`ln` just after. Default value: 0.
859861
align (str): Allows to center or align the text. Possible values are:
860862
`L` or empty string: left align (default value) ; `C`: center ;
861863
`R`: right align
@@ -869,7 +871,8 @@ def cell(self, w, h=0, txt="", border=0, ln=0, align="", fill=False, link=""):
869871
raise FPDFException("No font set, you need to call set_font() beforehand")
870872
if isinstance(border, int) and border not in (0, 1):
871873
warnings.warn(
872-
'Integer values for "border" parameter other than 1 are currently ignored'
874+
'Integer values for "border" parameter other than 1 are currently '
875+
"ignored"
873876
)
874877
border = 1
875878
page_break_triggered = False
@@ -1026,31 +1029,34 @@ def multi_cell(
10261029
max_line_height=None,
10271030
):
10281031
"""
1029-
Output text with line breaks, cf. https://pyfpdf.github.io/fpdf2/reference/multi_cell.html
1032+
Output text with line breaks, cf.
1033+
https://pyfpdf.github.io/fpdf2/reference/multi_cell.html
10301034
10311035
Args:
10321036
w (int): cells width. If 0, they extend up to the right margin of the page.
10331037
h (int): cells height.
10341038
txt (str): strign to print.
10351039
border: Indicates if borders must be drawn around the cell.
10361040
The value can be either a number (`0`: no border ; `1`: frame)
1037-
or a string containing some or all of the following characters (in any order):
1041+
or a string containing some or all of the following characters
1042+
(in any order):
10381043
`L`: left ; `T`: top ; `R`: right ; `B`: bottom. Default value: 0.
10391044
align (str): Allows to center or align the text. Possible values are:
10401045
`L` or empty string: left align (default value) ; `C`: center ;
10411046
`R`: right align
10421047
fill (bool): Indicates if the cell background must be painted (`True`)
10431048
or transparent (`False`). Default value: False.
1044-
split_only (bool): if `True`, does not output anything, only perform word-wrapping
1045-
and return the resulting multi-lines array of strings.
1049+
split_only (bool): if `True`, does not output anything, only perform
1050+
word-wrapping and return the resulting multi-lines array of strings.
10461051
link (str): optional link to add
10471052
ln (int): Indicates where the current position should go after the call.
1048-
Possible values are: `0`: to the bottom right ; `1`: to the beginning of the next line ;
1049-
`2`: below with the same horizontal offset ; `3`: to the right with the same vertical offset.
1050-
Default value: 0.
1053+
Possible values are: `0`: to the bottom right ; `1`: to the beginning
1054+
of the next line ; `2`: below with the same horizontal offset ;
1055+
`3`: to the right with the same vertical offset. Default value: 0.
10511056
max_line_height (int): optional maximum height of each sub-cell generated
10521057
1053-
Using `ln=3` and `maximum height=pdf.font_size` is useful to build tables with multiline text in cells.
1058+
Using `ln=3` and `maximum height=pdf.font_size` is useful to build tables
1059+
with multiline text in cells.
10541060
10551061
Returns: a boolean indicating if page break was triggered.
10561062
"""
@@ -1330,7 +1336,8 @@ def image(
13301336
Put an image on the page
13311337
13321338
Args:
1333-
name: either a string representing a file path to an image, or a instance of `PIL.Image.Image`
1339+
name: either a string representing a file path to an image, or a instance of
1340+
`PIL.Image.Image`
13341341
x (int): optional horizontal position where to put the image on the page
13351342
y (int): optional vertical position where to put the image on the page
13361343
w (int): optional width of the image
@@ -1395,7 +1402,8 @@ def image(
13951402
def ln(self, h=None):
13961403
"""
13971404
Line Feed.
1398-
The current abscissa goes back to the left margin and the ordinate increases by the amount passed as parameter.
1405+
The current abscissa goes back to the left margin and the ordinate increases by
1406+
the amount passed as parameter.
13991407
14001408
Args:
14011409
h (int): The height of the break.

fpdf/html.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def __init__(self, pdf, image_map=None, table_line_separators=False):
3232
"""
3333
Args:
3434
pdf (FPDF): an instance of `fpdf.FPDF`
35-
image_map (function): an optional one-argument function that map <img> "src" to new image URLs
35+
image_map (function): an optional one-argument function that map <img> "src"
36+
to new image URLs
3637
table_line_separators (bool): enable horizontal line separators in <table>
3738
"""
3839
super().__init__()

fpdf/template.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def split_multicell(self, text, element_name):
155155
def render(self, outfile=None, dest=None):
156156
"""
157157
Args:
158-
outfile (str): optional output PDF file path.
159-
If ommited, the `.pdf.output(...)` method can be manuallyy called afterwise.
158+
outfile (str): optional output PDF file path. If ommited, the
159+
`.pdf.output(...)` method can be manuallyy called afterwise.
160160
dest (str): [**DEPRECATED**] unused, will be removed in a later version
161161
"""
162162
if dest:
@@ -294,7 +294,8 @@ def barcode(
294294
if font == "interleaved 2of5 nt":
295295
pdf.interleaved2of5(text, x1, y1, w=size, h=y2 - y1)
296296

297-
# Added by Derek Schwalenberg Schwalenberg1013@gmail.com to allow (url) links in templates (using write method) 2014-02-22
297+
# Added by Derek Schwalenberg Schwalenberg1013@gmail.com to allow (url) links in
298+
# templates (using write method) 2014-02-22
298299
@staticmethod
299300
def write(
300301
pdf,

fpdf/ttfonts.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def calcChecksum(data):
6969

7070
class TTFontFile:
7171
def __init__(self):
72-
self.maxStrLenRead = 200000 # Maximum size of glyf table to read in as string (otherwise reads each glyph from file)
72+
# Maximum size of glyph table to read in as string
73+
# (otherwise reads each glyph from file)
74+
self.maxStrLenRead = 200000
7375

7476
def getMetrics(self, file):
7577
self.filename = file
@@ -277,7 +279,8 @@ def extractInfo(self):
277279
raise RuntimeError(f"Unknown glyph data format {glyphDataFormat}")
278280

279281
# hhea metrics table
280-
# ttf2t1 seems to use this value rather than the one in OS/2 - so put in for compatibility
282+
# ttf2t1 seems to use this value rather than the one in OS/2 - so put in for
283+
# compatibility
281284
if "hhea" in self.tables:
282285
self.seek_table("hhea")
283286
self.skip(4)
@@ -396,9 +399,9 @@ def extractInfo(self):
396399

397400
if not unicode_cmap_offset and not unicode_cmap_offset12:
398401
raise RuntimeError(
399-
"Font ("
400-
+ self.filename
401-
+ ") does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 3, encoding 10, format 12, or platform 0, any encoding, format 4)"
402+
f"Font ({self.filename}) does not have cmap for Unicode (platform 3, "
403+
f"encoding 1, format 4, or platform 3, encoding 10, format 12, or "
404+
f"platform 0, any encoding, format 4)"
402405
)
403406

404407
glyphToChar = {}
@@ -473,9 +476,9 @@ def makeSubset(self, file, subset):
473476

474477
if not unicode_cmap_offset and not unicode_cmap_offset12:
475478
raise RuntimeError(
476-
"Font ("
477-
+ self.filename
478-
+ ") does not have cmap for Unicode (platform 3, encoding 1, format 4, or platform 3, encoding 10, format 12, or platform 0, any encoding, format 4)"
479+
f"Font ({self.filename}) does not have cmap for Unicode "
480+
f"(platform 3, encoding 1, format 4, or platform 3, encoding 10, "
481+
f"format 12, or platform 0, any encoding, format 4)"
479482
)
480483

481484
glyphToChar = {}
@@ -511,7 +514,9 @@ def makeSubset(self, file, subset):
511514
subsetglyphs.sort()
512515
glyphSet = {}
513516
n = 0
514-
fsLastCharIndex = 0 # maximum Unicode index (character code) in this font, according to the cmap subtable for platform ID 3 and platform- specific encoding ID 0 or 1.
517+
# maximum Unicode index (character code) in this font, according to the cmap
518+
# subtable for platform ID 3 and platform- specific encoding ID 0 or 1.
519+
fsLastCharIndex = 0
515520
for originalGlyphIdx, uni in subsetglyphs:
516521
fsLastCharIndex = max(fsLastCharIndex, uni)
517522
glyphSet[originalGlyphIdx] = n # old glyphID to new glyphID
@@ -624,7 +629,7 @@ def makeSubset(self, file, subset):
624629
for subrange in range_:
625630
cmap.append(
626631
0
627-
) # idRangeOffset[segCount] Offset in bytes to glyph indexArray, or 0
632+
) # idRangeOffset[segCount] Offset in bytes to glyph indexArray, or 0
628633

629634
cmap.append(0) # idRangeOffset of last Segment
630635
for subrange, glidx in range_:
@@ -639,7 +644,8 @@ def makeSubset(self, file, subset):
639644
try:
640645
cmapstr += pack(">h", cm)
641646
except StructError:
642-
# cmap value too big to fit in a short (h), putting it in an unsigned short (H):
647+
# cmap value too big to fit in a short (h),
648+
# putting it in an unsigned short (H):
643649
cmapstr += pack(">H", -cm)
644650
self.add("cmap", cmapstr)
645651

@@ -835,7 +841,8 @@ def resize_cw(size, default):
835841
if glyph in glyphToChar or glyph == 0:
836842
if aw >= (1 << 15):
837843
aw = 0 # 1.03 Some (arabic) fonts have -ve values for width
838-
# although should be unsigned value - comes out as e.g. 65108 (intended -50)
844+
# although should be unsigned value
845+
# - comes out as e.g. 65108 (intended -50)
839846
if glyph == 0:
840847
self.defaultWidth = scale * aw
841848
continue

fpdf/util/syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""PDF Syntax Helpers
22
33
Functions in this module take variable input and produce PDF Syntax features
4-
as they are described in the Adobe PDF Reference Manual, found
5-
[here](http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf).
4+
as they are described in the Adobe PDF Reference Manual, found here:
5+
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
66
77
Most of what happens in a PDF happens in objects, which are formatted like so:
88
<pre>

test/barcodes/test_barcodes.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
HERE = Path(__file__).resolve().parent
77

88

9-
class TestBarcodes:
10-
def test_code39(self, tmp_path):
11-
pdf = FPDF()
12-
pdf.add_page()
13-
pdf.code39("fpdf2", x=50, y=50, w=4, h=20)
14-
pdf.set_font("courier", "B", size=36)
15-
pdf.text(x=80, y=80, txt="fpdf2")
16-
assert_pdf_equal(pdf, HERE / "barcodes_code39.pdf", tmp_path)
9+
def test_code39(tmp_path):
10+
pdf = FPDF()
11+
pdf.add_page()
12+
pdf.code39("fpdf2", x=50, y=50, w=4, h=20)
13+
pdf.set_font("courier", "B", size=36)
14+
pdf.text(x=80, y=80, txt="fpdf2")
15+
assert_pdf_equal(pdf, HERE / "barcodes_code39.pdf", tmp_path)
1716

18-
def test_interleaved2of5(self, tmp_path):
19-
pdf = FPDF()
20-
pdf.add_page()
21-
pdf.interleaved2of5("1337", x=65, y=50, w=4, h=20)
22-
pdf.set_font("courier", "B", size=36)
23-
pdf.text(x=80, y=80, txt="1337")
24-
assert_pdf_equal(pdf, HERE / "barcodes_interleaved2of5.pdf", tmp_path)
17+
18+
def test_interleaved2of5(tmp_path):
19+
pdf = FPDF()
20+
pdf.add_page()
21+
pdf.interleaved2of5("1337", x=65, y=50, w=4, h=20)
22+
pdf.set_font("courier", "B", size=36)
23+
pdf.text(x=80, y=80, txt="1337")
24+
assert_pdf_equal(pdf, HERE / "barcodes_interleaved2of5.pdf", tmp_path)

0 commit comments

Comments
 (0)