Files
wehub-resource-sync 461bf6fd40
CI / lint (3.11) (push) Has been cancelled
CI / lint (3.12) (push) Has been cancelled
CI / lint (3.13) (push) Has been cancelled
CI / shellcheck (push) Has been cancelled
CI / shfmt (push) Has been cancelled
CI / setup (3.11) (push) Has been cancelled
CI / setup (3.12) (push) Has been cancelled
CI / setup (3.13) (push) Has been cancelled
CI / check-licenses (3.12) (push) Has been cancelled
CI / test_unit (3.11) (push) Has been cancelled
CI / test_unit (3.12) (push) Has been cancelled
CI / test_unit (3.13) (push) Has been cancelled
CI / test_unit_no_extras (3.11) (push) Has been cancelled
CI / test_unit_no_extras (3.12) (push) Has been cancelled
CI / test_json_to_html (3.12) (push) Has been cancelled
CI / test_unit_no_extras (3.13) (push) Has been cancelled
CI / test_unit_dependency_extras (csv, 3.12, --extra csv) (push) Has been cancelled
CI / test_unit_dependency_extras (xlsx, 3.11, --extra xlsx) (push) Has been cancelled
CI / test_unit_dependency_extras (xlsx, 3.12, --extra xlsx) (push) Has been cancelled
CI / test_unit_dependency_extras (csv, 3.11, --extra csv) (push) Has been cancelled
CI / test_unit_dependency_extras (csv, 3.13, --extra csv) (push) Has been cancelled
CI / test_unit_dependency_extras (docx, 3.11, --extra docx) (push) Has been cancelled
CI / test_unit_dependency_extras (docx, 3.12, --extra docx) (push) Has been cancelled
CI / test_unit_dependency_extras (docx, 3.13, --extra docx) (push) Has been cancelled
CI / test_unit_dependency_extras (markdown, 3.11, --extra md) (push) Has been cancelled
CI / test_unit_dependency_extras (markdown, 3.12, --extra md) (push) Has been cancelled
CI / test_unit_dependency_extras (markdown, 3.13, --extra md) (push) Has been cancelled
CI / test_unit_dependency_extras (odt, 3.11, --extra odt) (push) Has been cancelled
CI / test_unit_dependency_extras (odt, 3.12, --extra odt) (push) Has been cancelled
CI / test_unit_dependency_extras (odt, 3.13, --extra odt) (push) Has been cancelled
CI / test_unit_dependency_extras (pdf-image, 3.11, --extra pdf --extra image --extra paddleocr) (push) Has been cancelled
CI / test_unit_dependency_extras (pdf-image, 3.12, --extra pdf --extra image --extra paddleocr) (push) Has been cancelled
CI / test_unit_dependency_extras (pdf-image, 3.13, --extra pdf --extra image --extra paddleocr) (push) Has been cancelled
CI / test_unit_dependency_extras (pptx, 3.11, --extra pptx) (push) Has been cancelled
CI / test_unit_dependency_extras (pptx, 3.12, --extra pptx) (push) Has been cancelled
CI / test_unit_dependency_extras (pptx, 3.13, --extra pptx) (push) Has been cancelled
CI / test_unit_dependency_extras (pypandoc, 3.11, --extra epub --extra org --extra rtf --extra rst) (push) Has been cancelled
CI / test_unit_dependency_extras (pypandoc, 3.12, --extra epub --extra org --extra rtf --extra rst) (push) Has been cancelled
CI / test_unit_dependency_extras (pypandoc, 3.13, --extra epub --extra org --extra rtf --extra rst) (push) Has been cancelled
Build And Push Docker Image / set-short-sha (push) Has been cancelled
Partition Benchmark / setup (push) Has been cancelled
Partition Benchmark / Measure and compare partition() runtime (push) Has been cancelled
CI / test_unit_dependency_extras (xlsx, 3.13, --extra xlsx) (push) Has been cancelled
CI / test_ingest_src (3.12) (push) Has been cancelled
CI / test_json_to_markdown (3.12) (push) Has been cancelled
CI / changelog (push) Has been cancelled
CI / test_dockerfile (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Build And Push Docker Image / build-images (linux/amd64, opensource-linux-8core) (push) Has been cancelled
Build And Push Docker Image / build-images (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Build And Push Docker Image / publish-images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:33:56 +08:00

157 lines
4.6 KiB
Python

import datetime
import pytest
from unstructured.cleaners import extract
EMAIL_META_DATA_INPUT = """from ABC.DEF.local ([ba23::58b5:2236:45g2:88h2]) by
\n ABC.DEF.local ([68.183.71.12]) with mapi id\
n 32.88.5467.123; Fri, 26 Mar 2021 11:04:09 +1200"""
def test_get_indexed_match_raises_with_bad_index():
with pytest.raises(ValueError):
extract._get_indexed_match("BLAH BLAH BLAH", "BLAH", -1)
def test_get_indexed_match_raises_with_index_too_high():
with pytest.raises(ValueError):
extract._get_indexed_match("BLAH BLAH BLAH", "BLAH", 4)
def test_extract_text_before():
text = "Teacher: BLAH BLAH BLAH; Student: BLAH BLAH BLAH!"
assert extract.extract_text_before(text, "BLAH", 1) == "Teacher: BLAH"
def test_extract_text_after():
text = "Teacher: BLAH BLAH BLAH; Student: BLAH BLAH BLAH!"
assert extract.extract_text_after(text, "BLAH;", 0) == "Student: BLAH BLAH BLAH!"
def test_extract_email_address():
text = "Im Rabn <Im.Rabn@npf.gov.nr>"
assert extract.extract_email_address(text) == ["im.rabn@npf.gov.nr"]
def test_extract_ip_address():
assert extract.extract_ip_address(EMAIL_META_DATA_INPUT) == [
"ba23::58b5:2236:45g2:88h2",
"68.183.71.12",
]
def test_extract_ip_address_name():
assert extract.extract_ip_address_name(EMAIL_META_DATA_INPUT) == [
"ABC.DEF.local",
"ABC.DEF.local",
]
def test_extract_mapi_id():
assert extract.extract_mapi_id(EMAIL_META_DATA_INPUT) == ["32.88.5467.123"]
def test_extract_datetimetz():
assert extract.extract_datetimetz(EMAIL_META_DATA_INPUT) == datetime.datetime(
2021,
3,
26,
11,
4,
9,
tzinfo=datetime.timezone(datetime.timedelta(seconds=43200)),
)
def test_extract_datetimetz_works_with_no_date():
assert extract.extract_datetimetz("NO DATE HERE") is None
@pytest.mark.parametrize(
("text", "expected"),
[
("215-867-5309", "215-867-5309"),
("Phone Number: +1 215.867.5309", "+1 215.867.5309"),
("Phone Number: Just Kidding", ""),
],
)
def test_extract_us_phone_number(text, expected):
phone_number = extract.extract_us_phone_number(text)
assert phone_number == expected
@pytest.mark.parametrize(
("text", "expected"),
[
("1. Introduction:", ("1", None, None)),
("a. Introduction:", ("a", None, None)),
("20.3 Morse code ●●●", ("20", "3", None)),
("5.3.1 Convolutional Networks ", ("5", "3", "1")),
("D.b.C Recurrent Neural Networks", ("D", "b", "C")),
("2.b.1 Recurrent Neural Networks", ("2", "b", "1")),
("eins. Neural Networks", (None, None, None)),
("bb.c Feed Forward Neural Networks", ("bb", "c", None)),
("aaa.ccc Metrics", (None, None, None)),
(" version = 3.8", (None, None, None)),
("1 2. 3 4", (None, None, None)),
("1) 2. 3 4", (None, None, None)),
("2,3. Morse code 3. ●●●", (None, None, None)),
("1..2.3 four", (None, None, None)),
("Fig. 2: The relationship", (None, None, None)),
("23 is everywhere", (None, None, None)),
],
)
def test_extract_ordered_bullets(text, expected):
assert extract.extract_ordered_bullets(text=text) == expected
@pytest.mark.parametrize(
("text", "expected"),
[
(
"https://my-image.jpg",
(["https://my-image.jpg"]),
),
(
"https://my-image.png with some text",
(["https://my-image.png"]),
),
(
"https://my-image/with/some/path.png",
(["https://my-image/with/some/path.png"]),
),
(
"some text https://my-image.jpg with another http://my-image.bmp",
(["https://my-image.jpg", "http://my-image.bmp"]),
),
(
"http://not-an-image.com",
([]),
),
(
"some text",
([]),
),
(
"some text https://my-image.JPG with another http://my-image.BMP",
(["https://my-image.JPG", "http://my-image.BMP"]),
),
(
"http://my-path-with-CAPS/my-image.JPG",
(["http://my-path-with-CAPS/my-image.JPG"]),
),
(
"http://my-path/my%20image.JPG",
(["http://my-path/my%20image.JPG"]),
),
# url with reference #
(
"https://my-image.jpg#ref",
(["https://my-image.jpg"]),
),
],
)
def test_extract_image_urls_from_html(text, expected):
assert extract.extract_image_urls_from_html(text=text) == expected