10
10
HERE = Path (__file__ ).resolve ().parent
11
11
12
12
13
- def test_add_font_non_existing ():
13
+ def test_add_font_non_existing_file ():
14
14
pdf = FPDF ()
15
- for uni in (True , False ):
16
- with pytest .raises (FileNotFoundError ) as error :
17
- pdf .add_font ("non-existing" , uni = uni )
18
- expected_msg = "[Errno 2] No such file or directory: 'non-existing.pkl'"
19
- assert str (error .value ) == expected_msg
15
+ with pytest .raises (FileNotFoundError ) as error :
16
+ pdf .add_font ("MyFont" , fname = "non-existing-file.ttf" )
17
+ expected_msg = "TTF Font file not found: non-existing-file.ttf"
18
+ assert str (error .value ) == expected_msg
19
+
20
+
21
+ def test_add_font_non_existing_file_pkl ():
22
+ pdf = FPDF ()
23
+ with pytest .raises (FileNotFoundError ) as error :
24
+ pdf .add_font ("MyFont" , fname = "non-existing-file.pkl" )
25
+ expected_msg = "[Errno 2] No such file or directory: 'non-existing-file.pkl'"
26
+ assert str (error .value ) == expected_msg
20
27
21
28
22
29
def test_deprecation_warning_for_FPDF_CACHE_DIR ():
@@ -54,7 +61,7 @@ def test_add_font_unicode_with_path_fname_ok(tmp_path):
54
61
for font_cache_dir in (True , tmp_path , None ):
55
62
pdf = FPDF (font_cache_dir = font_cache_dir )
56
63
font_file_path = HERE / "Roboto-Regular.ttf"
57
- pdf .add_font ("Roboto-Regular" , fname = str (font_file_path ))
64
+ pdf .add_font ("Roboto-Regular" , fname = str (font_file_path ), uni = True )
58
65
pdf .set_font ("Roboto-Regular" , size = 64 )
59
66
pdf .add_page ()
60
67
pdf .cell (txt = "Hello World!" )
@@ -65,7 +72,7 @@ def test_add_font_unicode_with_str_fname_ok(tmp_path):
65
72
for font_cache_dir in (True , str (tmp_path ), None ):
66
73
pdf = FPDF (font_cache_dir = font_cache_dir )
67
74
font_file_path = HERE / "Roboto-Regular.ttf"
68
- pdf .add_font ("Roboto-Regular" , fname = str (font_file_path ))
75
+ pdf .add_font ("Roboto-Regular" , fname = str (font_file_path ), uni = True )
69
76
pdf .set_font ("Roboto-Regular" , size = 64 )
70
77
pdf .add_page ()
71
78
pdf .cell (txt = "Hello World!" )
@@ -79,15 +86,14 @@ def teardown():
79
86
80
87
81
88
def test_add_core_fonts ():
82
- """Try to add core fonts. This shouldn't add any fonts, as core fonts like
83
- Helvetica are built-in"""
89
+ font_file_path = HERE / "Roboto-Regular.ttf"
84
90
pdf = FPDF ()
85
91
pdf .add_page ()
86
- pdf .add_font ("Helvetica" )
87
- pdf .add_font ("Helvetica" , style = "B" )
88
- pdf .add_font ("helvetica" , style = "IB" )
89
- pdf .add_font ("times" , style = "" )
90
- pdf .add_font ("courier" )
92
+ pdf .add_font ("Helvetica" , fname = font_file_path )
93
+ pdf .add_font ("Helvetica" , style = "B" , fname = font_file_path )
94
+ pdf .add_font ("helvetica" , style = "IB" , fname = font_file_path )
95
+ pdf .add_font ("times" , style = "" , fname = font_file_path )
96
+ pdf .add_font ("courier" , fname = font_file_path )
91
97
assert not pdf .fonts # No fonts added, as all of them are core fonts
92
98
93
99
0 commit comments