Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Feb 25, 2023
1 parent d60fda8 commit 6d3a0ec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
8 changes: 3 additions & 5 deletions tests_old/test_opener.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# SPDX-FileCopyrightText: 2023 geisserml <[email protected]>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

import os
import io
import re
import shutil
import tempfile
import traceback
from pathlib import Path
import PIL.Image
from os.path import join, abspath
import pypdfium2 as pdfium
import pypdfium2.raw as pdfium_c
import pytest
Expand Down Expand Up @@ -126,15 +124,15 @@ def test_open_encrypted():
def test_open_nonascii():

tempdir = tempfile.TemporaryDirectory(prefix="pypdfium2_")
nonascii_file = join(tempdir.name, "tên file chứakýtự éèáàçß 发短信.pdf")
nonascii_file = Path(tempdir.name) / "tên file chứakýtự éèáàçß 发短信.pdf"
shutil.copy(TestFiles.render, nonascii_file)

pdf = pdfium.PdfDocument(nonascii_file)
_check_general(pdf)

# FIXME cleanup permission error on Windows
try:
os.remove(nonascii_file)
nonascii_file.unlink()
tempdir.cleanup()
except Exception:
traceback.print_exc()
Expand Down
16 changes: 6 additions & 10 deletions tests_old/test_pageobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

import io
from os.path import (
join,
exists,
)
import pytest
import PIL.Image
import pypdfium2 as pdfium
Expand Down Expand Up @@ -111,7 +107,7 @@ def test_new_image_from_jpeg():
page.gen_content()
out_path = OutputDir / "image_jpeg.pdf"
pdf.save(out_path)
assert exists(out_path)
assert out_path.exists()

page._finalizer()
pdf._finalizer()
Expand Down Expand Up @@ -178,7 +174,7 @@ def test_replace_image_with_jpeg():
page.gen_content()
output_path = OutputDir / "replace_images.pdf"
pdf.save(output_path)
assert exists(output_path)
assert output_path.exists()


@pytest.mark.parametrize(
Expand Down Expand Up @@ -211,20 +207,20 @@ def test_image_get_bitmap(render):
assert bitmap.height == 90
assert bitmap.stride == 864
assert bitmap.rev_byteorder is False
output_path = join(OutputDir, "extract_rendered.png")
output_path = OutputDir / "extract_rendered.png"
else:
assert bitmap.format == pdfium_c.FPDFBitmap_Gray
assert bitmap.n_channels == 1
assert bitmap.width == 115
assert bitmap.height == 48
assert bitmap.stride == 116
assert bitmap.rev_byteorder is False
output_path = join(OutputDir, "extract.png")
output_path = OutputDir / "extract.png"

pil_image = bitmap.to_pil()
assert isinstance(pil_image, PIL.Image.Image)
pil_image.save(output_path)
assert exists(output_path)
assert output_path.exists()


def test_remove_image():
Expand All @@ -247,4 +243,4 @@ def test_remove_image():

output_path = OutputDir / "test_remove_objects.pdf"
pdf.save(output_path)
assert exists(output_path)
assert output_path.exists()
2 changes: 0 additions & 2 deletions tests_old/test_renderer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SPDX-FileCopyrightText: 2023 geisserml <[email protected]>
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

import io
import re
import math
import numpy
import PIL.Image
Expand Down
5 changes: 2 additions & 3 deletions tests_old/test_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

import io
from os.path import join, isfile
import pypdfium2 as pdfium
import pypdfium2.raw as pdfium_c
from .conftest import TestFiles, OutputDir
Expand All @@ -22,9 +21,9 @@ def test_save():
page = new_pdf.get_page(0)
assert page.get_size() == (595, 842)

output_file = join(OutputDir, "tiling.pdf")
output_file = OutputDir / "tiling.pdf"
new_pdf.save(output_file)
assert isfile(output_file)
assert output_file.exists()


def test_save_withversion():
Expand Down
2 changes: 1 addition & 1 deletion utilities/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

set -v

autoflake src/ tests/ --recursive --remove-all-unused-imports --ignore-pass-statements --exclude "src/pypdfium2/_namespace.py,src/pypdfium2/__init__.py,src/pypdfium2/_helpers/__init__.py"
autoflake src/ setupsrc/ tests/ tests_old/ setup.py docs/source/conf.py --recursive --remove-all-unused-imports --ignore-pass-statements --exclude "src/pypdfium2/__init__.py,src/pypdfium2/_helpers/__init__.py"
codespell --skip="./docs/build,./tests/resources,./tests/output,./tests_old/output,./data,./sourcebuild,./dist,./.git,__pycache__,.mypy_cache,.hypothesis" -L "tabe,splitted,fith,flate"
reuse lint

0 comments on commit 6d3a0ec

Please sign in to comment.