Skip to content

Commit 5e9f9bf

Browse files
committed
Upgrade Tika and stabilize remote parser tests
1 parent df5c917 commit 5e9f9bf

8 files changed

Lines changed: 44 additions & 13 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head><meta charset="utf-8"><title>Tika Python Remote HTML Fixture</title></head>
4+
<body><main><h1>Tika Python Remote HTML Fixture</h1><p>This deterministic file is hosted by the tika-python documentation site for parser remote URL tests.</p></main></body>
5+
</html>
518 Bytes
Loading
44 Bytes
Binary file not shown.
34.4 KB
Binary file not shown.

tests/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
from functools import partial
4+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
5+
import os
36
from pathlib import Path
7+
import threading
48

59
import pytest
610

11+
GITHUB_PAGES_REMOTE_FIXTURE_BASE_URL = (
12+
"https://chrismattmann.github.io/tika-python/_static/test-files"
13+
)
14+
715

816
@pytest.fixture
917
def test_file_path():
1018
return Path(__file__).parent / "files" / "rwservlet.pdf"
19+
20+
21+
@pytest.fixture(scope="session")
22+
def remote_fixture_base_url():
23+
configured_url = os.getenv("TIKA_REMOTE_TEST_BASE_URL")
24+
if configured_url:
25+
yield configured_url.rstrip("/")
26+
return
27+
28+
if not os.getenv("CI"):
29+
yield GITHUB_PAGES_REMOTE_FIXTURE_BASE_URL
30+
return
31+
32+
static_dir = Path(__file__).parents[1] / "docs" / "source" / "_static" / "test-files"
33+
handler = partial(SimpleHTTPRequestHandler, directory=static_dir)
34+
35+
with ThreadingHTTPServer(("127.0.0.1", 0), handler) as httpd:
36+
thread = threading.Thread(target=httpd.serve_forever, daemon=True)
37+
thread.start()
38+
yield f"http://127.0.0.1:{httpd.server_port}"
39+
httpd.shutdown()

tests/test_parser.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@
55
from tika import parser
66

77

8-
def test_remote_pdf():
8+
def test_remote_pdf(remote_fixture_base_url):
99
"""parse remote PDF"""
10-
assert parser.from_file(
11-
"https://upload.wikimedia.org/wikipedia/commons/4/42/Article_feedback_flow_B_-_Thank_editors.pdf")
10+
assert parser.from_file(f"{remote_fixture_base_url}/remote.pdf")
1211

1312

14-
def test_remote_html():
13+
def test_remote_html(remote_fixture_base_url):
1514
"""parse remote HTML"""
16-
assert parser.from_file("http://nossl.sh")
15+
assert parser.from_file(f"{remote_fixture_base_url}/remote.html")
1716

1817

19-
def test_remote_mp3():
18+
def test_remote_mp3(remote_fixture_base_url):
2019
"""parse remote mp3"""
21-
assert parser.from_file(
22-
"https://archive.org/download/Ainst-Spaceshipdemo.mp3/Ainst-Spaceshipdemo.mp3")
20+
assert parser.from_file(f"{remote_fixture_base_url}/remote.mp3")
2321

2422

25-
def test_remote_jpg():
23+
def test_remote_jpg(remote_fixture_base_url):
2624
"""parse remote jpg"""
27-
assert parser.from_file(
28-
"https://upload.wikimedia.org/wikipedia/commons/b/b7/X_logo.jpg")
25+
assert parser.from_file(f"{remote_fixture_base_url}/remote.jpg")
2926

3027

3128
def test_local_binary(test_file_path):

tika/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
__version__ = "3.1.0"
16+
__version__ = "3.3.2"
1717

1818
from pkgutil import extend_path
1919

tika/tika.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def make_content_disposition_header(fn):
152152
log.setLevel(logging.INFO)
153153

154154
Windows = True if platform.system() == "Windows" else False
155-
TikaVersion = os.getenv('TIKA_VERSION', '3.1.0')
155+
TikaVersion = os.getenv('TIKA_VERSION', '3.3.2')
156156
TikaJarPath = os.getenv('TIKA_PATH', tempfile.gettempdir())
157157
TikaFilesPath = tempfile.gettempdir()
158158
TikaServerLogFilePath = log_path

0 commit comments

Comments
 (0)