-
-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest fails on Windows 7 #587
Comments
OMG
OMG
OMG ❤️ BEST BUG REPORT EVER ❤️ |
I think we can close that issue. With the current master branch and when Python is up-to-date (>= V 3.6) and Cairo is up-to-date (>= V 1.15.10) and has a working fontconfig then all pytests pass. Maybe in documents.py another warning could be issued: if sys.platform.startswith('win'):
if cairo.cairo_version() < 11510 and sys.getfilesystemencoding() != 'utf-8':
warnings.warn('expect funny Unicode filenames') |
For the record: b5c1840 fixes the encoding problem in cairocffi. |
Running unit tests on a clean fresh clone reported lots of failures. Installing Ahem font reduced the failings to 22.
They can be grouped into 4 categories:
@font-face
on WindowsAfter de-bugging to the best of my knowledge I was able to reduce the failing test number to 8.
Tested with Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) on Windows 7 (64 bits) and Cairo 1.15.6.
Updating Cairo to 1.15.10 didn't help a lot (passed +=1).
CairoError
Exploring the reason for the 55 occurences of
I finally spotted the culprit in
test_api.py
at line 635 intest_bookmarks()
:The
font-size: 0
kills Pango and provokes the CairoErrors in subsquent unit tests.Inside pytest the Pango-WARNING isn't visible. When I run the snippet outside of pytest I see
Why doesn't this happen on Linux machines? Don't know. On Windows it's probably related to the way how DLLs are loaded. I guess, Python loads Pango/Cairo only once at startup/when required...
In any case, replacing
font-size: 0
withline-height:0
left me with 12 failures.No
@font-face
on WindowsThe 3 tests in test_fonts.py cannot pass on Windows because of:
Out of curiosity I installed the weasyprint.otf from the ./resources/ folder and have the sneaking suspicion that this font must be loaded via special treatment (using FontConfig instead of Cairo) because otherwise not even the kernings and ligatures (being on by default) are respected, let alone turning them on and off via
font-feature-settings
orfont-variant
.Thats how "kkliga", styled with font-family weasyprint, looks when rendered as PDF or in a M$Word 2010 document:
Red color applied to "liga" for clarification.
All the letters have the same shape/kerning/ligature, no wonder that the box.widths are bigger than expected.
Out of more curiosity I enabled
@font-face
by letting weasyprint/fonts.py load thelibfontconfig-1.dll
andlibpangoft2-1.0-0.dll
present in my GTK3.Only drawback seems to be:
FontConfiguration
can't cleanup the temporary files it created because the library has still open file handles when the object is__del__
eted.On Unix
os.remove()
a file that is in use works fine, on Windows a PermissionError is raised.No, not the only drawback.
Although the tests in test_fonts.py now pass, 19 new failures emerge, failures seemingly unrelatet to
@font-face
, so I guess there's actually a good reason not to use libfontconfig/libpangoft2 on Windows.Encoding and other platform specific issues
1. UnicodeDecodeError
Opening an utf-8 encoded file without specifying 'utf-8' fails.
In test_api.test_html_parsing
If encoding is not specified, the default is platform dependent -- which in my western Windows case is 'cp1252'. Giving 'utf-8' solves the problem:
2. path2url on Windows
b'filename'
to urlIn test_api.test_html_parsing, test_api.test_command_line_render, test_api.test_unicode_filenames, test_pdf.test_embedded_files
Had a hard time finding the offending code -- it's Python's
nturl2path.pathname2url()
cutting off trailing path separators and being unable to handle binary b'path'.Altered
weasyprint/urls.py
for the rescue:3. Filenames in Cairo on Windows
Cairo < 1.15.10 treats filenames as being in the current locale aka ANSI aka 'mcbs'. Python >= 3.6 defaults Windows filesystem encoding to UTF-8.
In test_api.test_unicode_filenames
Indeed, there is no such file, no file named 'Unicödé'. Instead there is a file named 'Unicödé' (Huh, looks familiar to me).
The concerned filename is generated in
cairocffi.surfaces._encode_filename()
to generate achar[]
, suitable for Cairo.Contemplating the mental state of C programmers and taking into account PEP 529, I finally came up with the following patch, suitable for all Cairo versions:
When using Cairo < 1.15.10 this patch makes
test_unicode_filenames
pass on my machine because the strange letters in 'Unicödé' exist in cp1252. With a 'Cyrillicкири́ллица' filename the test would probably succeed in Russia.To bugfix this within WeasyPrint (instead of altering cairocffi) all code, calling
cairo.ImageSurface
with astr
filename, should instead pass properly encodedbytes
.Rendering issues
1. Superfluous space
In test_draw.test_visibility
BTW: At the first, second and third glance my eyes didn't spot the difference between the PNGs, not even at maximum magnification.
That's the breeding html:
Looking at the
<div>
s Linebox reveals that the first TextBox is not empty:It's been a little while since I encountered such unexpected pixels in WebDesign. I usually switched to Zen-Design or removed the triggering linebreaks.
Indeed, the 1-pixel-relocation can be avoided by eliminating the linebreak after the first
<img>
tag, but that would probably contradict the test's purpose.2. Shifted InlineBox
The box.position_y is greater than expexted.
In test_layout.test_linebox_positions
Further investigation revealed that it's alway and only the last
<InlineBox strong>
. Though, thanks totests_ua.css
no strong formatting is applied. And always 6 pixels too far down.With a blue background applied to the
<strong>
, the failing html-snipped renders like this:The blue rectangle is the displaced InlineBox. Its child, the TextBox has the correct
position_y
. Confirmed in debugger.3. Semitransparent pixels
Looks like Ahem has no chance to be rendered precisely.
In test_tables.test_table_vertical_align
The semitransparent and protruding pixels in the PNG are probably a result of Windows' ClearTyping or suchlike. Whatever the reason,
assert_pixels_equal()
is doomed to fail.4. Broken fonts
Both, my Liberation Sans and my DejaVu Sans, seem to be broken when used with WeasyPrint. They work perfectly well when used in the browser or in M$Word...maybe another Cairo feature?
Liberation Sans
In test_layout.test_page_and_linebox_breaking
The snippet should produce 2 pages. Instead it produces the following ugly output:
After forcing another, working font, everything was fine.
DejaVu Sans
In test_layout.test_font_stretch
Similar issue with DejaVu Sans -- seems the renderer doesn't get the charcters' heights right. Pointless to expect a proper
font-stretch
.Using e.g Lucida Console,
font-stretch:condensed
works, but the y-position is definitely wrong.Applied blue background to the floating paragraphs.
5. Surprise!
Acid test fails.
In test_draw.test_acid2
Summary:
Most of the issues mentioned here can be circumvented. By avoiding special chars in filenames, only using proper fonts with simple properties and switching to Zen-Mode.
I suggest, pytest should skip the tests that require
@font-face
, whensys.platform.startswith('win')
.The text was updated successfully, but these errors were encountered: