-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
296 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,85 @@ | ||
import logging | ||
import os | ||
from pathlib import Path | ||
from typing import Final | ||
from typing import Generator | ||
|
||
import pytest | ||
|
||
from tika_client.client import TikaClient | ||
|
||
TIKA_URL: Final[str] = os.getenv("TIKA_URL", "http://localhost:9998") | ||
|
||
SAMPLE_DIR: Final[Path] = Path(__file__).parent.resolve() / "samples" | ||
@pytest.fixture(scope="session") | ||
def tika_host() -> str: | ||
return os.getenv("TIKA_URL", "http://localhost:9998") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def samples_dir() -> Path: | ||
return Path(__file__).parent.resolve() / "samples" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_libre_office_writer_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample-libre-office.odt" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_google_docs_to_libre_office_writer_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.odt" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_google_docs_to_docx_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.docx" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_docx_file(samples_dir: Path) -> Path: | ||
return samples_dir / "microsoft-sample.docx" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_doc_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.doc" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def c(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.html" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_office_doc_with_images_file(samples_dir: Path) -> Path: | ||
return samples_dir / "test-document-images.odt" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_jpeg_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.jpg" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_png_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample.png" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_ods_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample-spreadsheet.ods" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sample_xlsx_file(samples_dir: Path) -> Path: | ||
return samples_dir / "sample-spreadsheet.xlsx" | ||
|
||
|
||
@pytest.fixture | ||
def tika_client() -> TikaClient: | ||
with TikaClient(tika_url=TIKA_URL, log_level=logging.INFO) as client: | ||
def tika_client(tika_host: str) -> Generator[TikaClient, None, None]: | ||
with TikaClient(tika_url=tika_host, log_level=logging.INFO) as client: | ||
yield client | ||
|
||
|
||
@pytest.fixture | ||
def tika_client_compressed() -> TikaClient: | ||
with TikaClient(tika_url=TIKA_URL, log_level=logging.INFO, compress=True) as client: | ||
def tika_client_compressed(tika_host: str) -> Generator[TikaClient, None, None]: | ||
with TikaClient(tika_url=tika_host, log_level=logging.INFO, compress=True) as client: | ||
yield client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
from pathlib import Path | ||
|
||
import magic | ||
|
||
from tests.conftest import SAMPLE_DIR | ||
from tika_client.client import TikaClient | ||
|
||
|
||
class TestParseImageMetadata: | ||
def test_image_jpeg(self, tika_client: TikaClient): | ||
def test_image_jpeg(self, tika_client: TikaClient, sample_jpeg_file: Path): | ||
""" | ||
Test the handling of a JPEG file metadata retrieval | ||
""" | ||
test_file = SAMPLE_DIR / "sample.jpg" | ||
resp = tika_client.metadata.from_file(test_file, magic.from_file(str(test_file), mime=True)) | ||
resp = tika_client.metadata.from_file(sample_jpeg_file, magic.from_file(str(sample_jpeg_file), mime=True)) | ||
|
||
assert resp.type == "image/jpeg" | ||
|
||
def test_image_png(self, tika_client: TikaClient): | ||
def test_image_png(self, tika_client: TikaClient, sample_png_file: Path): | ||
""" | ||
Test the handling of a PNG file metadata retrieval | ||
""" | ||
test_file = SAMPLE_DIR / "sample.png" | ||
resp = tika_client.metadata.from_file(test_file, magic.from_file(str(test_file), mime=True)) | ||
resp = tika_client.metadata.from_file(sample_png_file, magic.from_file(str(sample_png_file), mime=True)) | ||
|
||
assert resp.type == "image/png" |
Oops, something went wrong.