forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start progress adding test for fonts
- Loading branch information
1 parent
06134df
commit 0da34c0
Showing
7 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""This package contains font tests | ||
fonts from https://filesamples.com/formats/ttf | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""respect_user_path.py""" | ||
|
||
import fpdf | ||
import os | ||
import pathlib | ||
import six | ||
import shutil | ||
import sys | ||
import traceback | ||
import unittest | ||
|
||
|
||
# python -m unittest test.fonts.respect_user_path.UserPathTest | ||
|
||
from test.utilities import relative_path_to, set_doc_date_0 | ||
|
||
class UserPathTest(unittest.TestCase): | ||
def test_regular_add_font_dir(self): | ||
pdf = fpdf.FPDF() | ||
set_doc_date_0(pdf) | ||
pdf.add_page() | ||
|
||
with self.assertRaises(fpdf.errors.FPDFUndefinedFontException) as raised: | ||
pdf.set_font('abc') | ||
|
||
ex = raised.exception | ||
self.assertEqual(str(ex), 'Undefined font: abc') | ||
self.assertEqual(repr(ex), "FPDFUndefinedFontException('abc', '')") | ||
|
||
def test_regular_add_font_dir(self): | ||
# where fpdf will try to look | ||
dn, join = os.path.dirname, os.path.join | ||
font_tests = dn(os.path.abspath(__file__)) | ||
repo = dn(dn(font_tests)) | ||
regular_folder = join(repo, 'fpdf', 'font') | ||
|
||
os.mkdir(regular_folder) | ||
testing_output = relative_path_to('test_regular_add_font_dir.pdf') | ||
|
||
def cp_to_regular_folder(f): | ||
shutil.copyfile(join(font_tests, f), join(regular_folder, f)) | ||
|
||
|
||
try: | ||
cp_to_regular_folder('slick.ttf') | ||
pdf = fpdf.FPDF() | ||
set_doc_date_0(pdf) | ||
pdf.add_page() | ||
pdf.add_font('slick', '', 'slick.ttf', True) | ||
pdf.set_font('slick', '', 12) | ||
pdf.write(12, 'hello world hello world hello world hello world') | ||
pdf.output(testing_output) | ||
|
||
try: | ||
os.system('ls -la ' + regular_folder) | ||
os.system('file ' + regular_folder) | ||
os.system('evince {}'.format(testing_output)) | ||
except Exception as e: | ||
print('os system errors') | ||
except Exception as e: | ||
traceback.print_exc() | ||
# (''.join(traceback.format_stack())) | ||
finally: | ||
try: | ||
shutil.rmtree(regular_folder) | ||
os.unlink(testing_output) | ||
except Exception as e: | ||
print('\n\nproblems unlinking\n\n') | ||
|
||
|
||
os.system('ls -la ' + regular_folder) | ||
|
Binary file not shown.
1 comment
on commit 0da34c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#14 needs tests, this is clearly not the completely correct approach...
🥴