repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
detectron2 | detectron2/structures/boxes.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import math
import numpy as np
from enum import IntEnum, unique
from typing import List, Tuple, Union
import torch
from torch import device
_RawBoxType = Union[List[float], Tuple[float, ...], torch.Tensor, np.ndarray]
@unique
class BoxMode(IntEnum):
"""
Enum... | 426 | 14,429 |
detectron2 | detectron2/structures/rotated_boxes.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import math
from typing import List, Tuple
import torch
from detectron2.layers.rotated_boxes import pairwise_iou_rotated
from .boxes import Boxes
class RotatedBoxes(Boxes):
"""
This structure stores a list of rotated boxes as a Nx5 torch.Tensor.
It supp... | 506 | 19,079 |
detectron2 | detectron2/structures/instances.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import itertools
import warnings
from typing import Any, Dict, List, Tuple, Union
import torch
class Instances:
"""
This class represents a list of instances in an image.
It stores the attributes of instances (e.g., boxes, masks, labels, scores) as "field... | 195 | 6,613 |
detectron2 | detectron2/data/catalog.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import logging
import types
from collections import UserDict
from typing import List
from detectron2.utils.logger import log_first_n
__all__ = ["DatasetCatalog", "MetadataCatalog", "Metadata"]
class _DatasetCatalog(UserDict):
"""
A global dictio... | 237 | 7,224 |
detectron2 | detectron2/data/detection_utils.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Common data processing utilities that are used in a
typical object detection data pipeline.
"""
import logging
import numpy as np
from typing import List, Union
import pycocotools.mask as mask_util
import torch
from PIL import Image
from d... | 663 | 23,330 |
detectron2 | detectron2/data/benchmark.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import logging
import numpy as np
from itertools import count
from typing import List, Tuple
import torch
import tqdm
from fvcore.common.timer import Timer
from detectron2.utils import comm
from .build import build_batch_data_loader
from .common import DatasetFromLis... | 226 | 7,378 |
detectron2 | detectron2/data/__init__.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
from . import transforms # isort:skip
from .build import (
build_batch_data_loader,
build_detection_test_loader,
build_detection_train_loader,
get_detection_dataset_dicts,
load_proposals_into_dataset,
print_instances_class_histogram,
)
from .c... | 20 | 644 |
detectron2 | detectron2/data/common.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import contextlib
import copy
import itertools
import logging
import numpy as np
import pickle
import random
from typing import Callable, Union
import torch
import torch.utils.data as data
from torch.utils.data.sampler import Sampler
from detectron2.utils.serialize im... | 340 | 12,443 |
detectron2 | detectron2/data/dataset_mapper.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import logging
import numpy as np
from typing import List, Optional, Union
import torch
from detectron2.config import configurable
from . import detection_utils as utils
from . import transforms as T
"""
This file contains the default mapping that's appl... | 192 | 8,169 |
detectron2 | detectron2/data/build.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import itertools
import logging
import numpy as np
import operator
import pickle
from collections import OrderedDict, defaultdict
from typing import Any, Callable, Dict, List, Optional, Union
import torch
import torch.utils.data as torchdata
from tabulate import tabula... | 695 | 27,138 |
detectron2 | detectron2/data/datasets/pascal_voc.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
import os
import xml.etree.ElementTree as ET
from typing import List, Tuple, Union
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.structures import BoxMode
from detectron2.utils.file_io import Pa... | 83 | 3,125 |
detectron2 | detectron2/data/datasets/cityscapes_panoptic.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import json
import logging
import os
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.data.datasets.builtin_meta import CITYSCAPES_CATEGORIES
from detectron2.utils.file_io import PathManager
"""
This file contains functions to register the ... | 188 | 7,821 |
detectron2 | detectron2/data/datasets/cityscapes.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import functools
import json
import logging
import multiprocessing as mp
import numpy as np
import os
from itertools import chain
import pycocotools.mask as mask_util
from PIL import Image
from detectron2.structures import BoxMode
from detectron2.utils.comm import get... | 338 | 13,379 |
detectron2 | detectron2/data/datasets/builtin_meta.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Note:
For your custom dataset, there is no need to hard-code metadata anywhere in the code.
For example, for COCO-format dataset, metadata will be obtained automatically
when calling `load_coco_json`. For other dataset, metadata may also be... | 351 | 21,841 |
detectron2 | detectron2/data/datasets/coco_panoptic.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import json
import os
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.utils.file_io import PathManager
from .coco import load_coco_json, load_sem_seg
__all__ = ["register_coco_panoptic", "register_coco_panoptic_separated"]
d... | 229 | 8,977 |
detectron2 | detectron2/data/datasets/builtin.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
"""
This file registers pre-defined datasets at hard-coded paths, and their metadata.
We hard-code metadata for common datasets. This will enable:
1. Consistency check when loading the datasets
2. Use models on these standard datasets directl... | 260 | 10,174 |
detectron2 | detectron2/data/datasets/lvis.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import logging
import os
from fvcore.common.timer import Timer
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.structures import BoxMode
from detectron2.utils.file_io import PathManager
from .builtin_meta import _get_coco_instances_meta
fr... | 251 | 9,717 |
detectron2 | detectron2/data/datasets/coco.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import contextlib
import datetime
import io
import json
import logging
import numpy as np
import os
import shutil
import pycocotools.mask as mask_util
from fvcore.common.timer import Timer
from iopath.common.file_io import file_lock
from PIL import Image
from detectro... | 557 | 23,631 |
detectron2 | detectron2/data/transforms/transform.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
"""
See "Data Augmentation" tutorial for an overview of the system:
https://detectron2.readthedocs.io/tutorials/augmentation.html
"""
import numpy as np
import torch
import torch.nn.functional as F
from fvcore.transforms.transform import (
... | 352 | 12,631 |
detectron2 | detectron2/data/transforms/augmentation_impl.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Implement many useful :class:`Augmentation`.
"""
import numpy as np
import sys
from numpy import random
from typing import Tuple
import torch
from fvcore.transforms.transform import (
BlendTransform,
CropTransform,
HFlipTransform... | 737 | 27,325 |
detectron2 | detectron2/data/transforms/__init__.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
from fvcore.transforms.transform import Transform, TransformList # order them first
from fvcore.transforms.transform import *
from .transform import *
from .augmentation import *
from .augmentation_impl import *
__all__ = [k for k in globals().keys() if not k.startsw... | 15 | 466 |
detectron2 | detectron2/data/transforms/augmentation.py | .py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
import inspect
import numpy as np
import pprint
from typing import Any, List, Optional, Tuple, Union
from fvcore.transforms.transform import Transform, TransformList
"""
See "Data Augmentation" tutorial for an overview of the system:
https://d... | 381 | 14,116 |
detectron2 | detectron2/data/samplers/distributed_sampler.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import itertools
import logging
import math
from collections import defaultdict
from typing import Optional
import torch
from torch.utils.data.sampler import Sampler
from detectron2.utils import comm
logger = logging.getLogger(__name__)
class TrainingSampler(Sample... | 288 | 12,199 |
detectron2 | detectron2/data/samplers/grouped_batch_sampler.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
from torch.utils.data.sampler import BatchSampler, Sampler
class GroupedBatchSampler(BatchSampler):
"""
Wraps another sampler to yield a mini-batch of indices.
It enforces that the batch only contain elements from the same group.
It... | 48 | 1,944 |
detectron2 | detectron2/data/samplers/__init__.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
from .distributed_sampler import (
InferenceSampler,
RandomSubsetTrainingSampler,
RepeatFactorTrainingSampler,
TrainingSampler,
)
from .grouped_batch_sampler import GroupedBatchSampler
__all__ = [
"GroupedBatchSampler",
"TrainingSampler",
... | 18 | 412 |
detectron2 | detectron2/projects/__init__.py | .py | # Copyright (c) Facebook, Inc. and its affiliates.
import importlib.abc
import importlib.util
from pathlib import Path
__all__ = []
_PROJECTS = {
"point_rend": "PointRend",
"deeplab": "DeepLab",
"panoptic_deeplab": "Panoptic-DeepLab",
}
_PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent / "proj... | 35 | 1,177 |
OCRmyPDF | bin/bump_version.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2017-2019 Joe Rickerby and contributors
# SPDX-License-Identifier: BSD-2-Clause
"""Bump the version number in all the right places."""
from __future__ import annotations
import os
import subprocess
import sys
import time
import urllib.parse
from pathlib import Path
i... | 409 | 12,326 |
OCRmyPDF | tests/test_api.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import pickle
from io import BytesIO
from pathlib import Path
import pytest
from pdfminer.high_level import extract_text
import ocrmypdf
import ocrmypdf._pipelines
import ocrmypdf.api
def test_lang... | 262 | 7,972 |
OCRmyPDF | tests/test_concurrency.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
import platform
import pytest
from ocrmypdf import ExitCode
from .conftest import run_ocrmypdf_api
@pytest.mark.skipif(os.name == 'nt', reason="Windows doesn't have SIGKILL")
@pytest.mar... | 30 | 728 |
OCRmyPDF | tests/test_rasterizer.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Tests for the --rasterizer CLI option."""
from __future__ import annotations
from io import BytesIO
import img2pdf
import pikepdf
import pytest
from PIL import Image
from ocrmypdf._exec import ghostscript
from ocrmypdf._options im... | 794 | 28,054 |
OCRmyPDF | tests/test_tesseract.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import os
import subprocess
from os import fspath
from pathlib import Path
import pytest
from ocrmypdf import pdfinfo
from ocrmypdf._exec import tesseract
from ocrmypdf.exceptions impo... | 170 | 5,350 |
OCRmyPDF | tests/test_page_numbers.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import pytest
import ocrmypdf
from ocrmypdf._options import _pages_from_ranges
from ocrmypdf.exceptions import BadArgsError
from ocrmypdf.pdfinfo import PdfInfo
@pytest.mark.parametrize(
'pages,... | 123 | 3,253 |
OCRmyPDF | tests/test_logging.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
from ocrmypdf._pipelines._common import configure_debug_logging
def test_debug_logging(tmp_path):
# Just exercise the debug logger but don't validate it
# See https://github.c... | 19 | 571 |
OCRmyPDF | tests/test_system_font_provider.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for SystemFontProvider and ChainedFontProvider."""
from __future__ import annotations
import sys
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from ocrmypdf.font import (
BuiltinF... | 690 | 27,722 |
OCRmyPDF | tests/test_hocr_parser.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for HocrParser class."""
from __future__ import annotations
from pathlib import Path
from textwrap import dedent
import pytest
from ocrmypdf.hocrtransform import (
HocrParseError,
HocrParser,
OcrClass,
)
@... | 534 | 18,243 |
OCRmyPDF | tests/test_json_serialization.py | .py | """Test JSON serialization of OcrOptions for multiprocessing compatibility."""
from __future__ import annotations
import multiprocessing
from io import BytesIO
from pathlib import Path, PurePath
import pytest
from ocrmypdf._options import OcrOptions
from ocrmypdf.builtin_plugins.tesseract_ocr import TesseractOption... | 164 | 6,003 |
OCRmyPDF | tests/test_strip.py | .py | # SPDX-FileCopyrightText: 2026 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Tests for --mode strip (remove the OCR text layer in place)."""
from __future__ import annotations
import pikepdf
import pytest
from ocrmypdf.exceptions import BadArgsError
from ocrmypdf.pdfinfo import PdfInfo
from .conftest impor... | 72 | 2,573 |
OCRmyPDF | tests/test_verapdf.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: CC-BY-SA-4.0
"""Tests for verapdf wrapper and speculative PDF/A conversion."""
from __future__ import annotations
import pikepdf
import pytest
from pikepdf import Name
from ocrmypdf._exec import verapdf
from ocrmypdf.pdfa import (
_pdfa_p... | 167 | 6,142 |
OCRmyPDF | tests/test_optimize.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from io import BytesIO
from os import fspath
from pathlib import Path
from unittest.mock import patch
import img2pdf
import pikepdf
import pytest
from packaging.version import Version
from pikepdf imp... | 496 | 16,050 |
OCRmyPDF | tests/test_unpaper.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
from os import fspath
from unittest.mock import Mock, patch
import pytest
from packaging.version import Version
from pydantic import ValidationError
from ocrmypdf._exec import unpaper
... | 141 | 3,999 |
OCRmyPDF | tests/test_preprocessing.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from math import isclose
import pytest
from PIL import Image
from ocrmypdf._exec import ghostscript, tesseract
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.helpers import Resolution
from oc... | 165 | 5,082 |
OCRmyPDF | tests/test_hocrtransform.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import re
from io import StringIO
from pathlib import Path
import pytest
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfdocument import PDFDocument
... | 125 | 3,565 |
OCRmyPDF | tests/test_metadata.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import datetime as dt
import warnings
from shutil import copyfile
from unittest.mock import MagicMock, patch
import pikepdf
import pytest
from pikepdf.models.metadata import decode_pdf_date
from ocrm... | 426 | 14,061 |
OCRmyPDF | tests/test_pdfa.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
import pikepdf
import pytest
from pikepdf import Name
from ocrmypdf.exceptions import ExitCode, MissingDependencyError
from ocrmypdf.pdfa import file_claims_pdfa, find_nonembedded_cid_fonts... | 319 | 12,096 |
OCRmyPDF | tests/test_quality.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from ocrmypdf import quality as qual
def test_quality_measurement():
oqd = qual.OcrQualityDictionary(
wordlist=["words", "words", "quick", "brown", "fox", "dog", "lazy"]
)
assert ... | 22 | 630 |
OCRmyPDF | tests/test_soft_error.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
import pytest
from ocrmypdf.exceptions import ExitCode
from .conftest import run_ocrmypdf_api
def test_raster_continue_on_soft_error(resources, outpdf):
exitcode = run_ocrmypdf_api(
... | 68 | 1,881 |
OCRmyPDF | tests/test_pipeline_generate_ocr.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for pipeline support of generate_ocr().
These tests verify that the pipeline supports the new generate_ocr() API
alongside the existing hOCR path.
"""
from __future__ import annotations
import dataclasses
from pathlib im... | 102 | 3,425 |
OCRmyPDF | tests/test_completion.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
from subprocess import run
import pytest
from ocrmypdf.helpers import running_in_docker
pytestmark = pytest.mark.skipif(
running_in_docker(),
reason="docker can't complete",
)
de... | 46 | 1,078 |
OCRmyPDF | tests/test_check_pdf.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from ocrmypdf.helpers import check_pdf
def test_pdf_error(resources):
assert check_pdf(resources / 'blank.pdf')
assert not check_pdf(__file__)
| 12 | 272 |
OCRmyPDF | tests/test_null_ocr_engine.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for NullOcrEngine (--ocr-engine none).
Tests verify that the Null OCR engine exists and functions correctly
for scenarios where users want PDF processing without OCR.
"""
from __future__ import annotations
from pathlib i... | 170 | 5,838 |
OCRmyPDF | tests/test_pipeline.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import warnings
from unittest.mock import Mock
import pikepdf
import pytest
from PIL import Image
from reportlab.lib.units import inch
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen... | 218 | 6,366 |
OCRmyPDF | tests/test_acroform.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import pikepdf
import pytest
import ocrmypdf
from .conftest import check_ocrmypdf
# pylint: disable=redefined-outer-name
@pytest.fixture
def acroform(resources):
return resourc... | 56 | 1,414 |
OCRmyPDF | tests/test_page_boxes.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import pikepdf
import pytest
from ocrmypdf._exec import verapdf
from ocrmypdf._pageboxes import repair_page_boxes
from .conftest import check_ocrmypdf
page_rect = [0, 0, 612, 792]
inset_rect = [200,... | 275 | 8,697 |
OCRmyPDF | tests/test_watcher_security.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for the watcher security helpers."""
from __future__ import annotations
import os
import sys
from pathlib import Path
import pytest
from ocrmypdf._watcher_security import (
WatcherConfigError,
assert_data_dirs_i... | 274 | 8,848 |
OCRmyPDF | tests/test_image_input.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from unittest.mock import patch
import img2pdf
import pikepdf
import pytest
from PIL import Image
import ocrmypdf
from .conftest import check_ocrmypdf, run_ocrmypdf_api
# pylint: disable=redefined-... | 93 | 2,457 |
OCRmyPDF | tests/test_ghostscript.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import secrets
import subprocess
import sys
import zlib
from decimal import Decimal
from unittest.mock import patch
import pikepdf
import pytest
from packaging.version import Version
fr... | 902 | 34,776 |
OCRmyPDF | tests/test_imageops.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import hypothesis.strategies as st
from hypothesis import given
from PIL import Image
from ocrmypdf.imageops import (
_calculate_downsample,
bytes_per_pixel,
calculate_downsample,
down... | 59 | 1,748 |
OCRmyPDF | tests/test_ocr_engine_selection.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for OCR engine selection mechanism.
Tests verify that the --ocr-engine option works correctly and that
engine-specific options are available.
"""
from __future__ import annotations
import pytest
class TestOcrEngineCliO... | 140 | 4,490 |
OCRmyPDF | tests/test_thumbnails.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import pikepdf
import pytest
from pikepdf import Name
from ocrmypdf._graft import discard_page_thumbnails
from .conftest import check_ocrmypdf
# pylint: disable=redefined-outer-name
... | 94 | 2,820 |
OCRmyPDF | tests/test_semfree.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import sys
import pytest
from ocrmypdf.exceptions import ExitCode
from .conftest import is_linux, run_ocrmypdf_api
@pytest.mark.skipif(not is_linux(), reason='semfree plugin only works on Linux')
... | 34 | 949 |
OCRmyPDF | tests/test_annots.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from pikepdf import Array, Dictionary, Name, NameTree, Pdf
from ocrmypdf._annots import remove_broken_goto_annotations
def test_remove_broken_goto_annotations(resources):
with Pdf.open(resources... | 31 | 1,089 |
OCRmyPDF | tests/test_tagged.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import pikepdf
import pytest
from pikepdf import Name
import ocrmypdf
from ocrmypdf.pdfinfo import PdfInfo
def test_block_tagged(resources):
with pytest.raises(ocrmypdf.exceptions.TaggedPDFError... | 98 | 3,296 |
OCRmyPDF | tests/test_validation.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import os
from unittest.mock import patch
import pikepdf
import pytest
from ocrmypdf import _validation as vd
from ocrmypdf._concurrent import NullProgressBar, SerialExecutor
from ocrm... | 341 | 11,024 |
OCRmyPDF | tests/test_graft.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from unittest.mock import patch
import pikepdf
import ocrmypdf
def test_no_glyphless_graft(resources, outdir):
with (
pikepdf.open(resources / 'francais.pdf') as pdf,
pikepdf.op... | 160 | 5,682 |
OCRmyPDF | tests/test_ocr_engine_interface.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for OcrEngine interface extensions.
These tests verify that the OcrEngine ABC has the new generate_ocr() method
and that OcrElement classes are exported from the public API.
"""
from __future__ import annotations
from pa... | 132 | 3,962 |
OCRmyPDF | tests/test_multilingual_direct.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Direct tests for multilingual text rendering with fpdf2 renderer.
This tests the fpdf2 renderer with various language groups:
- Latin (English, French, German with diacritics)
- Arabic (Arabic, Persian - RTL sc... | 616 | 21,325 |
OCRmyPDF | tests/test_stdio.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
from pathlib import Path
from subprocess import DEVNULL, PIPE, run
import pytest
from ocrmypdf.helpers import check_pdf
from .conftest import run_ocrmypdf
def test_stdin(ocrmypdf_exec, r... | 93 | 2,924 |
OCRmyPDF | tests/test_ocr_element.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for OcrElement dataclass and related classes."""
from __future__ import annotations
import pytest
from ocrmypdf.hocrtransform import (
Baseline,
BoundingBox,
FontInfo,
OcrClass,
OcrElement,
)
class ... | 245 | 8,506 |
OCRmyPDF | tests/test_watcher.py | .py | from __future__ import annotations
import datetime as dt
import json
import os
import shutil
import subprocess
import sys
import time
from pathlib import Path
import pikepdf
import pytest
watchfiles = pytest.importorskip('watchfiles')
WATCHER = Path(__file__).parent.parent / 'misc' / 'watcher.py'
def _spawn_watch... | 216 | 6,751 |
OCRmyPDF | tests/test_multi_font_manager.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for MultiFontManager and FontProvider."""
from __future__ import annotations
import logging
from pathlib import Path
import pytest
from ocrmypdf.font import BuiltinFontProvider, FontManager, MultiFontManager
@pytest.f... | 686 | 27,227 |
OCRmyPDF | tests/test_pdfinfo.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import pickle
import warnings
from io import BytesIO
from math import isclose
import img2pdf
import pikepdf
import pytest
from PIL import Image
from reportlab.lib.units import inch
from reportlab.pdfg... | 531 | 16,417 |
OCRmyPDF | tests/test_rotation.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import operator
from io import BytesIO
from math import cos, pi, sin
from os import fspath
from subprocess import run
import img2pdf
import pikepdf
import pytest
from PIL import Image, ImageChops
from... | 427 | 13,042 |
OCRmyPDF | tests/test_search_index.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import pikepdf
import pytest
from pikepdf import Dictionary, Name, String
from ocrmypdf._graft import discard_text_search_index
from .conftest import check_ocrmypdf
# pylint: disable... | 102 | 3,339 |
OCRmyPDF | tests/test_fpdf_renderer.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Tests for fpdf2-based PDF renderer."""
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
import pytest
from ocrmypdf.font import MultiFontManager
from ocrmypdf.fpdf_renderer import (
D... | 564 | 18,514 |
OCRmyPDF | tests/test_main.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import os
import shutil
import sys
from math import isclose
from pathlib import Path
from subprocess import run
from unittest.mock import patch
import pikepdf
import pytest
from PIL import Image
impo... | 1,001 | 27,955 |
OCRmyPDF | tests/test_helpers.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import multiprocessing
import os
from pathlib import Path
from unittest.mock import MagicMock
import pytest
from packaging.version import Version
from ocrmypdf import helpers
from ocrm... | 137 | 4,483 |
OCRmyPDF | tests/test_userunit.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
from math import isclose
import pytest
from ocrmypdf.pdfinfo import PdfInfo
from .conftest import check_ocrmypdf
# pylint: disable=redefined-outer-name
@pytest.fixture
def poster(resources):
... | 46 | 959 |
OCRmyPDF | tests/test_pdf_renderer.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Unit tests for Fpdf2PdfRenderer class."""
from __future__ import annotations
import re
from io import StringIO
from pathlib import Path
import pikepdf
import pytest
from pdfminer.converter import TextConverter
from pdfminer.layout ... | 915 | 31,932 |
OCRmyPDF | tests/conftest.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import logging
import platform
import sys
from pathlib import Path
from subprocess import CompletedProcess, run
import pytest
from ocrmypdf import api, pdfinfo
from ocrmypdf._exec import unpaper
from... | 193 | 5,607 |
OCRmyPDF | tests/plugins/tesseract_cache.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
"""Cache output of tesseract to speed up test suite.
The cache is keyed by by the input test file The input arguments are slugged
into a hideous filename that more or less represents them literally. Joined
together, this becomes the name of... | 225 | 7,869 |
OCRmyPDF | tests/plugins/gs_raster_soft_error.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess i... | 52 | 1,356 |
OCRmyPDF | tests/plugins/gs_render_failure.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
def raise_gs_fail(*args, **kwargs):
raise Cal... | 35 | 998 |
OCRmyPDF | tests/plugins/tesseract_simulate_oom_killer.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
"""Tesseract no-op plugin that simulates the OOM killer on page 4.
OCRmyPDF can use a lot of memory, even that it might trigger the
OOM killer on Linux or similar features on other platforms. We want to
ensure we fail with an error rather th... | 68 | 1,943 |
OCRmyPDF | tests/plugins/tesseract_debug_rotate.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
"""Tesseract no-op/fixed rotate plugin.
To quickly run tests where getting OCR output is not necessary and we want to test
the rotation pipeline.
In generate_hocr mode, create a .hocr file that specifies no text found.
In 'pdf' mode, conve... | 99 | 3,099 |
OCRmyPDF | tests/plugins/gs_feature_elision.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess import run_polling_stderr
ELISION_WARNING = """GPL Ghostscript 9.50... | 38 | 1,144 |
OCRmyPDF | tests/plugins/tesseract_badutf8.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
"""Tesseract bad utf8.
In some cases, some versions of Tesseract can output binary gibberish or data
that is not UTF-8 compatible, so we are forced to check that we can convert it
and present it to the user.
"""
from __future__ import anno... | 57 | 1,527 |
OCRmyPDF | tests/plugins/gs_render_soft_error.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess import run_polling_stderr
... | 44 | 1,181 |
OCRmyPDF | tests/plugins/tesseract_noop.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
"""Tesseract no-op plugin.
To quickly run tests where getting OCR output is not necessary.
In generate_hocr mode, create a .hocr file that specifies no text found.
In 'pdf' mode, convert the image to PDF using another program.
In orientat... | 97 | 2,939 |
OCRmyPDF | tests/plugins/gs_pdfa_failure.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess import run_polling_stderr
def run_rig_args(args, **kwargs):
# ... | 40 | 1,251 |
OCRmyPDF | tests/plugins/gs_raster_failure.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
def raise_gs_fail(*args,... | 51 | 1,268 |
OCRmyPDF | tests/plugins/stdout_polluter.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MIT
"""Test plugin that deliberately writes garbage to stdout.
Used to verify that OCRmyPDF's stdout protection diverts stray writes (from
plugins or libraries) to stderr, so that a PDF written to stdout is never
corrupted. Pollutes at three poi... | 43 | 1,144 |
OCRmyPDF | tests/plugins/tesseract_crash.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
import signal
from contextlib import contextmanager
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins.tesseract_ocr impor... | 56 | 1,563 |
OCRmyPDF | tests/plugins/tesseract_big_image_error.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MIT
from __future__ import annotations
from contextlib import contextmanager
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins.tesseract_ocr import TesseractOcr... | 54 | 1,516 |
OCRmyPDF | scripts/generate_glyphless_font.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Generate the Occulta glyphless font for OCRmyPDF.
Occulta (Latin for "hidden") is a glyphless font designed for invisible text layers
in searchable PDFs. It has proper Unicode cmap coverage using format 13 (man... | 232 | 6,631 |
OCRmyPDF | misc/pdf_text_diff.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Compare text in PDFs."""
from __future__ import annotations
from pathlib import Path
from subprocess import run
from tempfile import NamedTemporaryFile
from typing import Annotated
import cyclopts
app = cyclopts.App()
@app.defau... | 58 | 1,403 |
OCRmyPDF | misc/ocrmypdf_compare.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Run OCRmyPDF on the same PDF with different options."""
from __future__ import annotations
import os
import shlex
from io import BytesIO
from pathlib import Path
from subprocess import check_output, run
from tempfile import TemporaryDir... | 129 | 4,099 |
OCRmyPDF | misc/webservice.py | .py | #!/usr/bin/env python
# SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Run the OCRmyPDF web service."""
from __future__ import annotations
import os
import sys
try:
import streamlit # noqa: F401
except ImportError:
raise ImportError(
'You need to instal... | 32 | 658 |
OCRmyPDF | misc/batch.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2016 findingorder <https://github.com/findingorder>
# SPDX-FileCopyrightText: 2024 nilsro <https://github.com/nilsro>
# SPDX-License-Identifier: MIT
"""Example of using ocrmypdf as a library in a script.
This script will recursively search a directory for PDF files and... | 88 | 2,951 |
OCRmyPDF | misc/bisect_pdf.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MIT
"""Helper script for bisecting PDFs to find a page with an issue."""
from __future__ import annotations
import sys
import pikepdf
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <input.pdf>")
sys.exit(1... | 45 | 1,435 |
OCRmyPDF | misc/pdf_compare.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Compare two PDFs."""
from __future__ import annotations
from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
import pikepdf
import pymupdf
import streamlit as st
from lxml import etree
from streamlit_... | 83 | 2,524 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.