diff --git a/pypdf/__init__.py b/pypdf/__init__.py index d2812817e..793d4f104 100644 --- a/pypdf/__init__.py +++ b/pypdf/__init__.py @@ -10,7 +10,6 @@ from ._crypt_providers import crypt_provider from ._doc_common import DocumentInformation from ._encryption import PasswordType -from ._merger import PdfMerger from ._page import PageObject, Transformation from ._reader import PdfReader from ._text_extraction import mult @@ -39,7 +38,6 @@ "PageRange", "PaperSize", "PasswordType", - "PdfMerger", "PdfReader", "PdfWriter", "Transformation", diff --git a/pypdf/_doc_common.py b/pypdf/_doc_common.py index 1aef717c5..37eff95eb 100644 --- a/pypdf/_doc_common.py +++ b/pypdf/_doc_common.py @@ -44,7 +44,7 @@ from ._page import PageObject, _VirtualList from ._page_labels import index2label as page_index2page_label from ._utils import ( - deprecate_with_replacement, + deprecation_with_replacement, logger_warning, parse_iso8824_date, ) @@ -1259,7 +1259,7 @@ def decode_permissions( self, permissions_code: int ) -> dict[str, bool]: # pragma: no cover """Take the permissions as an integer, return the allowed access.""" - deprecate_with_replacement( + deprecation_with_replacement( old_name="decode_permissions", new_name="user_access_permissions", removed_in="5.0.0", diff --git a/pypdf/_merger.py b/pypdf/_merger.py deleted file mode 100644 index b6a830402..000000000 --- a/pypdf/_merger.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2006, Mathieu Fenniak -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# * The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - - -from ._utils import ( - deprecation_with_replacement, -) - - -class PdfMerger: - """ - Use :class:`PdfWriter` instead. - - .. deprecated:: 5.0.0 - """ - - def __init__(self) -> None: - deprecation_with_replacement("PdfMerger", "PdfWriter", "5.0.0") diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 243843a3b..a2209c8f4 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -58,9 +58,7 @@ StrByteType, StreamType, _get_max_pdf_version_header, - deprecate, - deprecate_no_replacement, - deprecation_with_replacement, + deprecation_no_replacement, logger_warning, ) from .constants import AnnotationDictionaryAttributes as AA @@ -377,12 +375,12 @@ def xmp_metadata(self, value: Optional[XmpInformation]) -> None: @property def with_as_usage(self) -> bool: - deprecate_no_replacement("with_as_usage", "6.0") + deprecation_no_replacement("with_as_usage", "5.0") return self._with_as_usage @with_as_usage.setter def with_as_usage(self, value: bool) -> None: - deprecate_no_replacement("with_as_usage", "6.0") + deprecation_no_replacement("with_as_usage", "5.0") self._with_as_usage = value def __enter__(self) -> "PdfWriter": @@ -1426,10 +1424,6 @@ def write_stream(self, stream: StreamType) -> None: "It may not be written to correctly.", __name__, ) - # deprecated to be removed in pypdf 6.0.0 : - # if not self._root: - # self._root = self._add_object(self._root_object) - # self._sweep_indirect_references(self._root) self._resolve_links() if self.incremental: @@ -1754,74 +1748,6 @@ def replace_in_obj( for i in compress(range(len(self._objects)), orphans): self._objects[i] = None - def _sweep_indirect_references( - self, - root: Union[ - ArrayObject, - BooleanObject, - DictionaryObject, - FloatObject, - IndirectObject, - NameObject, - PdfObject, - NumberObject, - TextStringObject, - NullObject, - ], - ) -> None: # deprecated - """ - Resolving any circular references to Page objects. - - Circular references to Page objects can arise when objects such as - annotations refer to their associated page. If these references are not - properly handled, the PDF file will contain multiple copies of the same - Page object. To address this problem, Page objects store their original - object reference number. This method adds the reference number of any - circularly referenced Page objects to an external reference map. This - ensures that self-referencing trees reference the correct new object - location, rather than copying in a new copy of the Page object. - - Args: - root: The root of the PDF object tree to sweep. - - """ - deprecate( - "_sweep_indirect_references has been removed, please report to dev team if this warning is observed", - ) - - def _resolve_indirect_object( - self, data: IndirectObject - ) -> IndirectObject: # deprecated - """ - Resolves an indirect object to an indirect object in this PDF file. - - If the input indirect object already belongs to this PDF file, it is - returned directly. Otherwise, the object is retrieved from the input - object's PDF file using the object's ID number and generation number. If - the object cannot be found, a warning is logged and a `NullObject` is - returned. - - If the object is not already in this PDF file, it is added to the file's - list of objects and assigned a new ID number and generation number of 0. - The hash value of the object is then added to the `_idnum_hash` - dictionary, with the corresponding `IndirectObject` reference as the - value. - - Args: - data: The `IndirectObject` to resolve. - - Returns: - The resolved `IndirectObject` in this PDF file. - - Raises: - ValueError: If the input stream is closed. - - """ - deprecate( - "_resolve_indirect_object has been removed, please report to dev team if this warning is observed", - ) - return IndirectObject(0, 0, self) - def get_reference(self, obj: PdfObject) -> IndirectObject: idnum = self._objects.index(obj) + 1 ref = IndirectObject(idnum, 0, self) @@ -3255,17 +3181,6 @@ def find_outline_item( else: return None - def find_bookmark( - self, - outline_item: dict[str, Any], - root: Optional[OutlineType] = None, - ) -> None: # deprecated - """ - .. deprecated:: 2.9.0 - Use :meth:`find_outline_item` instead. - """ - deprecation_with_replacement("find_bookmark", "find_outline_item", "5.0.0") - def reset_translation( self, reader: Union[None, PdfReader, IndirectObject] = None ) -> None: diff --git a/pypdf/annotations/_markup_annotations.py b/pypdf/annotations/_markup_annotations.py index e95bbe394..2654cd1d1 100644 --- a/pypdf/annotations/_markup_annotations.py +++ b/pypdf/annotations/_markup_annotations.py @@ -2,7 +2,6 @@ from abc import ABC from typing import Any, Optional, Union -from .._utils import deprecation_with_replacement from ..constants import AnnotationFlag from ..generic import ArrayObject, DictionaryObject from ..generic._base import ( @@ -217,10 +216,6 @@ def __init__( interior_color: Optional[str] = None, **kwargs: Any, ) -> None: - if "interiour_color" in kwargs: - deprecation_with_replacement("interiour_color", "interior_color", "5.0.0") - interior_color = kwargs["interiour_color"] - del kwargs["interiour_color"] super().__init__(**kwargs) self.update( { @@ -269,10 +264,6 @@ def __init__( interior_color: Optional[str] = None, **kwargs: Any, ) -> None: - if "interiour_color" in kwargs: - deprecation_with_replacement("interiour_color", "interior_color", "5.0.0") - interior_color = kwargs["interiour_color"] - del kwargs["interiour_color"] super().__init__(**kwargs) self.update( diff --git a/pypdf/constants.py b/pypdf/constants.py index 9b3877c36..cdee9fe29 100644 --- a/pypdf/constants.py +++ b/pypdf/constants.py @@ -144,14 +144,6 @@ class Resources: PROPERTIES = "/Properties" # dictionary, optional -class Ressources: # deprecated - """ - Use :class: `Resources` instead. - - .. deprecated:: 5.0.0 - """ - - class PagesAttributes: """ยง7.7.3.2 of the 1.7 and 2.0 reference.""" diff --git a/pypdf/filters.py b/pypdf/filters.py index 2cdb7ff8c..150239f15 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -50,9 +50,7 @@ from ._codecs._codecs import LzwCodec as _LzwCodec from ._utils import ( WHITESPACES_AS_BYTES, - deprecate, - deprecate_with_replacement, - deprecation_no_replacement, + deprecation_with_replacement, logger_warning, ) from .constants import CcittFaxDecodeParameters as CCITT @@ -61,7 +59,7 @@ from .constants import ImageAttributes as IA from .constants import LzwFilterParameters as LZW from .constants import StreamAttributes as SA -from .errors import DependencyError, DeprecationError, PdfReadError, PdfStreamError +from .errors import DependencyError, PdfReadError, PdfStreamError from .generic import ( ArrayObject, BooleanObject, @@ -145,9 +143,6 @@ def decode( PdfReadError: """ - if isinstance(decode_parms, ArrayObject): - raise DeprecationError("decode_parms as ArrayObject is deprecated") - str_data = decompress(data) predictor = 1 @@ -420,7 +415,7 @@ def decode(self) -> bytes: return _LzwCodec().decode(self.data) @staticmethod - def _decodeb( + def decode( data: bytes, decode_parms: Optional[DictionaryObject] = None, **kwargs: Any, @@ -439,27 +434,6 @@ def _decodeb( # decode_parms is unused here return LZWDecode.Decoder(data).decode() - @staticmethod - def decode( - data: bytes, - decode_parms: Optional[DictionaryObject] = None, - **kwargs: Any, - ) -> str: # deprecated - """ - Decode an LZW encoded data stream. - - Args: - data: ``bytes`` or ``str`` text to decode. - decode_parms: a dictionary of parameter values. - - Returns: - decoded data. - - """ - # decode_parms is unused here - deprecate("LZWDecode.decode will return bytes instead of str in pypdf 6.0.0") - return LZWDecode.Decoder(data).decode().decode("latin-1") - class ASCII85Decode: """Decodes string ASCII85-encoded data into a byte format.""" @@ -568,7 +542,7 @@ def __create_old_class_instance( columns: int = 0, rows: int = 0 ) -> CCITTParameters: - deprecate_with_replacement("CCITParameters", "CCITTParameters", "6.0.0") + deprecation_with_replacement("CCITParameters", "CCITTParameters", "6.0.0") return CCITTParameters(K, columns, rows) @@ -619,10 +593,6 @@ def decode( height: int = 0, **kwargs: Any, ) -> bytes: - if isinstance(decode_parms, ArrayObject): # deprecated - deprecation_no_replacement( - "decode_parms being an ArrayObject", removed_in="3.15.5" - ) params = CCITTFaxDecode._get_parameters(decode_parms, height) img_size = len(data) @@ -772,7 +742,7 @@ def decode_stream_data(stream: Any) -> bytes: elif filter_name in (FT.ASCII_85_DECODE, FTA.A85): data = ASCII85Decode.decode(data) elif filter_name in (FT.LZW_DECODE, FTA.LZW): - data = LZWDecode._decodeb(data, params) + data = LZWDecode.decode(data, params) elif filter_name in (FT.FLATE_DECODE, FTA.FL): data = FlateDecode.decode(data, params) elif filter_name in (FT.RUN_LENGTH_DECODE, FTA.RL): diff --git a/pypdf/generic/__init__.py b/pypdf/generic/__init__.py index 2160f1327..bde1628fb 100644 --- a/pypdf/generic/__init__.py +++ b/pypdf/generic/__init__.py @@ -29,11 +29,6 @@ __author__ = "Mathieu Fenniak" __author_email__ = "biziqe@mathieu.fenniak.net" -from typing import Optional, Union - -from .._utils import ( - deprecation_with_replacement, -) from ..constants import OutlineFontFlag from ._base import ( BooleanObject, @@ -77,131 +72,8 @@ PAGE_FIT = Fit.fit() -class AnnotationBuilder: # deprecated - """ - The AnnotationBuilder is deprecated. - - Instead, use the annotation classes in pypdf.annotations. - - See `adding PDF annotations <../user/adding-pdf-annotations.html>`_ for - its usage combined with PdfWriter. - """ - - from ..generic._rectangle import RectangleObject # noqa: PLC0415 - - @staticmethod - def text( - rect: Union[RectangleObject, tuple[float, float, float, float]], - text: str, - open: bool = False, - flags: int = 0, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.text", "pypdf.annotations.Text", "5.0.0" - ) - - @staticmethod - def free_text( - text: str, - rect: Union[RectangleObject, tuple[float, float, float, float]], - font: str = "Helvetica", - bold: bool = False, - italic: bool = False, - font_size: str = "14pt", - font_color: str = "000000", - border_color: Optional[str] = "000000", - background_color: Optional[str] = "ffffff", - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.free_text", "pypdf.annotations.FreeText", "5.0.0" - ) - - @staticmethod - def popup( - *, - rect: Union[RectangleObject, tuple[float, float, float, float]], - flags: int = 0, - parent: Optional[DictionaryObject] = None, - open: bool = False, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.popup", "pypdf.annotations.Popup", "5.0.0" - ) - - @staticmethod - def line( - p1: tuple[float, float], - p2: tuple[float, float], - rect: Union[RectangleObject, tuple[float, float, float, float]], - text: str = "", - title_bar: Optional[str] = None, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.line", "pypdf.annotations.Line", "5.0.0" - ) - - @staticmethod - def polyline( - vertices: list[tuple[float, float]], - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.polyline", "pypdf.annotations.PolyLine", "5.0.0" - ) - - @staticmethod - def rectangle( - rect: Union[RectangleObject, tuple[float, float, float, float]], - interiour_color: Optional[str] = None, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.rectangle", "pypdf.annotations.Rectangle", "5.0.0" - ) - - @staticmethod - def highlight( - *, - rect: Union[RectangleObject, tuple[float, float, float, float]], - quad_points: ArrayObject, - highlight_color: str = "ff0000", - printing: bool = False, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.highlight", "pypdf.annotations.Highlight", "5.0.0" - ) - - @staticmethod - def ellipse( - rect: Union[RectangleObject, tuple[float, float, float, float]], - interiour_color: Optional[str] = None, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.ellipse", "pypdf.annotations.Ellipse", "5.0.0" - ) - - @staticmethod - def polygon(vertices: list[tuple[float, float]]) -> None: - deprecation_with_replacement( - "AnnotationBuilder.polygon", "pypdf.annotations.Polygon", "5.0.0" - ) - - from ._fit import DEFAULT_FIT # noqa: PLC0415 - - @staticmethod - def link( - rect: Union[RectangleObject, tuple[float, float, float, float]], - border: Optional[ArrayObject] = None, - url: Optional[str] = None, - target_page_index: Optional[int] = None, - fit: Fit = DEFAULT_FIT, - ) -> None: - deprecation_with_replacement( - "AnnotationBuilder.link", "pypdf.annotations.Link", "5.0.0" - ) - - __all__ = [ "PAGE_FIT", - "AnnotationBuilder", "ArrayObject", "BooleanObject", "ByteStringObject", diff --git a/pypdf/generic/_base.py b/pypdf/generic/_base.py index 82c8ff7b6..0c4166fd9 100644 --- a/pypdf/generic/_base.py +++ b/pypdf/generic/_base.py @@ -45,8 +45,8 @@ from .._utils import ( StreamType, classproperty, - deprecate_no_replacement, - deprecate_with_replacement, + deprecation_no_replacement, + deprecation_with_replacement, logger_warning, read_non_whitespace, read_until_regex, @@ -225,7 +225,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(b"null") @@ -290,7 +290,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) if self.value: @@ -438,7 +438,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(f"{self.idnum} {self.generation} R".encode()) @@ -527,7 +527,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(self.myrepr().encode("utf8")) @@ -572,7 +572,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(repr(self).encode("utf8")) @@ -627,7 +627,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(b"<") @@ -767,7 +767,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) bytearr = self.get_encoded_bytes() @@ -819,7 +819,7 @@ def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] = None ) -> None: if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) stream.write(self.renumber()) @@ -827,9 +827,9 @@ def write_to_stream( def renumber(self) -> bytes: out = self[0].encode("utf-8") if out != b"/": - deprecate_no_replacement( + deprecation_no_replacement( f"Incorrect first char in NameObject, should start with '/': ({self})", - "6.0.0", + "5.0.0", ) for c in self[1:]: if c > "~": @@ -859,7 +859,7 @@ def _sanitize(self) -> "NameObject": @classproperty def surfix(cls) -> bytes: # noqa: N805 - deprecate_with_replacement("surfix", "prefix", "6.0.0") + deprecation_with_replacement("surfix", "prefix", "5.0.0") return b"/" @staticmethod diff --git a/pypdf/generic/_data_structures.py b/pypdf/generic/_data_structures.py index 8ee6ee819..198d15443 100644 --- a/pypdf/generic/_data_structures.py +++ b/pypdf/generic/_data_structures.py @@ -48,7 +48,6 @@ WHITESPACES, StreamType, deprecation_no_replacement, - deprecation_with_replacement, logger_warning, read_non_whitespace, read_until_regex, @@ -998,12 +997,6 @@ def write_to_stream( stream.write(self._data) stream.write(b"\nendstream") - @staticmethod - def initializeFromDictionary(data: dict[str, Any]) -> None: - deprecation_with_replacement( - "initializeFromDictionary", "initialize_from_dictionary", "5.0.0" - ) # pragma: no cover - @staticmethod def initialize_from_dictionary( data: dict[str, Any] diff --git a/pypdf/xmp.py b/pypdf/xmp.py index 920470d7a..c45f2d183 100644 --- a/pypdf/xmp.py +++ b/pypdf/xmp.py @@ -20,7 +20,7 @@ from xml.parsers.expat import ExpatError from ._protocols import XmpInformationProtocol -from ._utils import StreamType, deprecate_no_replacement, deprecate_with_replacement +from ._utils import StreamType, deprecate_with_replacement, deprecation_no_replacement from .errors import PdfReadError from .generic import ContentStream, PdfObject @@ -251,7 +251,7 @@ def write_to_stream( "6.0.0" ) if encryption_key is not None: # deprecated - deprecate_no_replacement( + deprecation_no_replacement( "the encryption_key parameter of write_to_stream", "5.0.0" ) self.stream.write_to_stream(stream) diff --git a/tests/bench.py b/tests/bench.py index e310060b5..b2dc68bae 100644 --- a/tests/bench.py +++ b/tests/bench.py @@ -11,8 +11,7 @@ import pytest import pypdf -from pypdf import PdfReader, PdfWriter, Transformation -from pypdf._page import PageObject +from pypdf import PageObject, PdfReader, PdfWriter, Transformation from pypdf.generic import Destination, read_string_from_stream from . import get_data_from_url @@ -86,7 +85,7 @@ def merge(): writer.append(reader) # PdfReader object: - writer.append(PdfReader(pdf_path, "rb"), outline_item="True") + writer.append(PdfReader(pdf_path), outline_item="True") # File handle with open(pdf_path, "rb") as fh: diff --git a/tests/test_annotations.py b/tests/test_annotations.py index e28c7a2f6..90835558f 100644 --- a/tests/test_annotations.py +++ b/tests/test_annotations.py @@ -19,7 +19,7 @@ Rectangle, Text, ) -from pypdf.errors import DeprecationError, PdfReadError +from pypdf.errors import PdfReadError from pypdf.generic import ArrayObject, FloatObject, NumberObject from . import get_data_from_url @@ -38,12 +38,6 @@ def test_ellipse(pdf_file_path): writer.add_page(page) # Act - with pytest.raises(DeprecationError): - ellipse_annotation = Ellipse( - rect=(50, 550, 500, 650), - interiour_color="ff0000", - ) - ellipse_annotation = Ellipse( rect=(50, 550, 500, 650), interior_color="ff0000", @@ -219,11 +213,6 @@ def test_rectangle(pdf_file_path): writer.add_page(page) # Act - with pytest.raises(DeprecationError): - square_annotation = Rectangle( - rect=(50, 550, 200, 650), interiour_color="ff0000" - ) - square_annotation = Rectangle( rect=(50, 550, 200, 650), interior_color="ff0000" ) diff --git a/tests/test_filters.py b/tests/test_filters.py index 2fb1d5a77..52120e964 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -84,16 +84,6 @@ def test_flatedecode_unsupported_predictor(): codec.decode(codec.encode(s), DictionaryObject({"/Predictor": predictor})) -@pytest.mark.parametrize("params", [ArrayObject([]), ArrayObject([{"/Predictor": 1}])]) -def test_flate_decode_decompress_with_array_params(params): - """FlateDecode decode() method works correctly with array parameters.""" - codec = FlateDecode() - s = b"" - encoded = codec.encode(s) - with pytest.raises(DeprecationError): - assert codec.decode(encoded, params) == s - - @pytest.mark.parametrize( ("data", "expected"), [ @@ -199,13 +189,11 @@ def test_ascii85decode_five_zero_bytes(): def test_ccitparameters(): - with pytest.warns( - DeprecationWarning, - match="CCITParameters is deprecated and will be removed in pypdf 6.0.0. Use CCITTParameters instead", + with pytest.raises( + DeprecationError, + match="CCITParameters is deprecated and was removed in pypdf 6.0.0. Use CCITTParameters instead", ): - params = CCITParameters() - assert params.K == 0 # zero is the default according to page 78 - assert params.group == 3 + CCITParameters() def test_ccittparameters(): diff --git a/tests/test_generic.py b/tests/test_generic.py index 1135b14bd..8954604a7 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -10,7 +10,7 @@ from pypdf import PdfReader, PdfWriter from pypdf.constants import CheckboxRadioButtonAttributes -from pypdf.errors import PdfReadError, PdfStreamError +from pypdf.errors import DeprecationError, PdfReadError, PdfStreamError from pypdf.generic import ( ArrayObject, BooleanObject, @@ -198,9 +198,9 @@ def test_name_object(caplog): NameObject.read_from_stream(stream, None) assert exc.value.args[0] == "Name read error" - with pytest.warns( - DeprecationWarning, - match="surfix is deprecated and will be removed in pypdf 6.0.0. Use prefix instead.", + with pytest.raises( + DeprecationError, + match="surfix is deprecated and was removed in pypdf 5.0.0. Use prefix instead.", ): _ = NameObject.surfix @@ -246,9 +246,9 @@ def test_name_object(caplog): caplog.clear() b = BytesIO() - with pytest.warns( - expected_warning=DeprecationWarning, - match=r"Incorrect first char in NameObject, should start with '/': \(hello\) is deprecated and will" + with pytest.raises( + expected_exception=DeprecationError, + match=r"Incorrect first char in NameObject, should start with '/': \(hello\) is deprecated and was" ): NameObject("hello").write_to_stream(b) diff --git a/tests/test_merger.py b/tests/test_merger.py index 5c97fc15d..816b33422 100644 --- a/tests/test_merger.py +++ b/tests/test_merger.py @@ -6,8 +6,7 @@ import pytest import pypdf -from pypdf import PdfMerger, PdfReader, PdfWriter -from pypdf.errors import DeprecationError +from pypdf import PdfReader, PdfWriter from pypdf.generic import Destination, Fit from . import get_data_from_url @@ -401,11 +400,6 @@ def test_articles_with_writer(caplog): assert r.threads[0].get_object()["/F"]["/P"] == r.pages[0] -def test_deprecate_pdfmerger(): - with pytest.raises(DeprecationError), PdfMerger() as merger: - merger.append(RESOURCE_ROOT / "crazyones.pdf") - - def test_get_reference(): writer = PdfWriter(RESOURCE_ROOT / "crazyones.pdf") assert writer.get_reference(writer.pages[0]) == writer.pages[0].indirect_reference @@ -505,11 +499,11 @@ def test_named_ref_to_page_that_is_gone(pdf_file_path): source = PdfReader(BytesIO(get_data_from_url(name="named-reference.pdf"))) buf = BytesIO() tmp = PdfWriter() - tmp.add_page(source.pages[2]) # we add only the page with the reference + tmp.add_page(source.pages[2]) # we add only the page with the reference tmp.write(buf) source = PdfReader(buf) writer = PdfWriter() - writer.add_page(source.pages[0]) # now references to non-existent page - writer.write(pdf_file_path) # don't crash + writer.add_page(source.pages[0]) # now references to non-existent page + writer.write(pdf_file_path) # don't crash diff --git a/tests/test_reader.py b/tests/test_reader.py index e31c55fd0..df330e4b6 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -14,6 +14,7 @@ from pypdf.constants import PageAttributes as PG from pypdf.constants import UserAccessPermissions as UAP from pypdf.errors import ( + DeprecationError, EmptyFileError, FileNotDecryptedError, PdfReadError, @@ -742,17 +743,17 @@ def test_decode_permissions(): print_ = base.copy() print_["print"] = True - with pytest.warns( - DeprecationWarning, - match="decode_permissions is deprecated and will be removed in pypdf 5.0.0. Use user_access_permissions instead", # noqa: E501 + with pytest.raises( + DeprecationError, + match="decode_permissions is deprecated and was removed in pypdf 5.0.0. Use user_access_permissions instead", ): assert reader.decode_permissions(4) == print_ modify = base.copy() modify["modify"] = True - with pytest.warns( - DeprecationWarning, - match="decode_permissions is deprecated and will be removed in pypdf 5.0.0. Use user_access_permissions instead", # noqa: E501 + with pytest.raises( + DeprecationError, + match="decode_permissions is deprecated and was removed in pypdf 5.0.0. Use user_access_permissions instead", ): assert reader.decode_permissions(8) == modify diff --git a/tests/test_writer.py b/tests/test_writer.py index a7ddb4748..a0b9b3453 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -20,7 +20,7 @@ Transformation, ) from pypdf.annotations import Link -from pypdf.errors import PageSizeNotDefinedError, PyPdfError +from pypdf.errors import DeprecationError, PageSizeNotDefinedError, PyPdfError from pypdf.generic import ( ArrayObject, ByteStringObject, @@ -2669,17 +2669,17 @@ def test_auto_write(tmp_path): def test_deprecate_with_as(): """Yet another test for #2905""" with PdfWriter() as writer: - with pytest.warns( - expected_warning=DeprecationWarning, - match="with_as_usage is deprecated and will be removed in pypdf 6.0" + with pytest.raises( + expected_exception=DeprecationError, + match="with_as_usage is deprecated and was removed in pypdf 5.0" ): - val = writer.with_as_usage - assert val - with pytest.warns( - expected_warning=DeprecationWarning, - match="with_as_usage is deprecated and will be removed in pypdf 6.0" + _ = writer.with_as_usage + + with pytest.raises( + expected_exception=DeprecationError, + match="with_as_usage is deprecated and was removed in pypdf 5.0" ): - writer.with_as_usage = val # old code allowed setting this, so... + writer.with_as_usage = False # old code allowed setting this, so... @pytest.mark.skipif(GHOSTSCRIPT_BINARY is None, reason="Requires Ghostscript")