mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
parent
620b17a9b3
commit
10a7863332
@ -8,7 +8,7 @@
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
||||
import cairosvg
|
||||
@ -19,8 +19,8 @@ from .text import cairo, pango
|
||||
|
||||
class PrintInfo(argparse.Action):
|
||||
def __call__(*_, **__):
|
||||
uname = os.uname()
|
||||
print('System:', uname.sysname)
|
||||
uname = platform.uname()
|
||||
print('System:', uname.system)
|
||||
print('Machine:', uname.machine)
|
||||
print('Version:', uname.version)
|
||||
print('Release:', uname.release)
|
||||
@ -160,10 +160,7 @@ def main(argv=None, stdout=None, stdin=None):
|
||||
format_ = args.format.lower()
|
||||
|
||||
if args.input == '-':
|
||||
if stdin is None:
|
||||
stdin = sys.stdin
|
||||
# stdin.buffer on Py3, stdin on Py2
|
||||
source = getattr(stdin, 'buffer', stdin)
|
||||
source = stdin or sys.stdin.buffer
|
||||
if args.base_url is None:
|
||||
args.base_url = '.' # current directory
|
||||
elif args.base_url == '':
|
||||
@ -172,10 +169,7 @@ def main(argv=None, stdout=None, stdin=None):
|
||||
source = args.input
|
||||
|
||||
if args.output == '-':
|
||||
if stdout is None:
|
||||
stdout = sys.stdout
|
||||
# stdout.buffer on Py3, stdout on Py2
|
||||
output = getattr(stdout, 'buffer', stdout)
|
||||
output = stdout or sys.stdout.buffer
|
||||
else:
|
||||
output = args.output
|
||||
|
||||
|
@ -313,8 +313,9 @@ def test_command_line_render(tmpdir):
|
||||
# pdf_bytes = html_obj.write_pdf()
|
||||
png_bytes = html_obj.write_png()
|
||||
x2_png_bytes = html_obj.write_png(resolution=192)
|
||||
rotated_png_bytes = FakeHTML(string=combined, base_url='dummy.html',
|
||||
media_type='screen').write_png()
|
||||
rotated_png_bytes = FakeHTML(
|
||||
string=combined, base_url='dummy.html',
|
||||
media_type='screen').write_png()
|
||||
empty_png_bytes = FakeHTML(
|
||||
string=b'<style>' + css + b'</style>').write_png()
|
||||
check_png_pattern(png_bytes)
|
||||
@ -347,11 +348,11 @@ def test_command_line_render(tmpdir):
|
||||
_run(path2url(tmpdir.join('combined.html').strpath) + ' out5.png')
|
||||
assert tmpdir.join('out5.png').read_binary() == png_bytes
|
||||
|
||||
_run('linked.html out6.png') # test relative URLs
|
||||
_run('linked.html --debug out6.png') # test relative URLs
|
||||
assert tmpdir.join('out6.png').read_binary() == png_bytes
|
||||
|
||||
_run('combined.html out7 -f png')
|
||||
_run('combined.html out8 --format pdf')
|
||||
_run('combined.html --verbose out7 -f png')
|
||||
_run('combined.html --quiet out8 --format pdf')
|
||||
assert tmpdir.join('out7').read_binary() == png_bytes
|
||||
# assert tmpdir.join('out8').read_binary(), pdf_bytes
|
||||
|
||||
@ -377,6 +378,8 @@ def test_command_line_render(tmpdir):
|
||||
assert tmpdir.join('out13.png').read_binary() == rotated_png_bytes
|
||||
assert tmpdir.join('out14.png').read_binary() == rotated_png_bytes
|
||||
|
||||
stdout = _run('-f pdf combined.html -')
|
||||
assert stdout.count(b'attachment') == 0
|
||||
stdout = _run('-f pdf combined.html -')
|
||||
assert stdout.count(b'attachment') == 0
|
||||
stdout = _run('-f pdf -a pattern.png combined.html -')
|
||||
@ -398,9 +401,31 @@ def test_command_line_render(tmpdir):
|
||||
assert logs[0].startswith('ERROR: Failed to load image')
|
||||
assert stdout == empty_png_bytes
|
||||
|
||||
with capture_logs() as logs:
|
||||
stdout = _run('--format png --base-url= - -', stdin=combined)
|
||||
assert len(logs) == 1
|
||||
assert logs[0].startswith(
|
||||
'ERROR: Relative URI reference without a base URI')
|
||||
assert stdout == empty_png_bytes
|
||||
|
||||
stdout = _run('--format png --base-url .. - -', stdin=combined)
|
||||
assert stdout == png_bytes
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
_run('--info')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
_run('--version')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
_run('combined.html combined.jpg')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
_run('combined.html combined.pdf --resolution 100')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
_run('combined.html combined.png -a pattern.png')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_unicode_filenames(tmpdir):
|
||||
|
Loading…
Reference in New Issue
Block a user