-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move unstructured tests to be an integration test (#8244)
GitOrigin-RevId: 212d083180f24db95a61ba4aa2ba87525b55d3a5
- Loading branch information
1 parent
4a88c9e
commit aa94353
Showing
3 changed files
with
54 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
import pathway as pw | ||
from pathway.tests.utils import assert_table_equality | ||
from pathway.xpacks.llm.parsers import UnstructuredParser | ||
|
||
|
||
@pytest.mark.environment_changes | ||
def test_parse_unstructured(monkeypatch): | ||
parser = UnstructuredParser() | ||
txt = "Pójdź, kińże tę chmurność w głąb flaszy 🍾." | ||
input_df = pd.DataFrame([dict(raw=txt.encode("utf8"))]) | ||
|
||
class schema(pw.Schema): | ||
raw: bytes | ||
|
||
input_table = pw.debug.table_from_pandas(input_df, schema=schema) | ||
result = input_table.select(ret=parser(pw.this.raw)[0][0]) | ||
|
||
assert_table_equality( | ||
result, pw.debug.table_from_pandas(pd.DataFrame([dict(ret=txt)])) | ||
) | ||
|
||
|
||
@pytest.mark.environment_changes | ||
@pytest.mark.asyncio | ||
def test_parse_unstructured_unk_exception(monkeypatch): | ||
parser = UnstructuredParser() | ||
|
||
binary_data = b"NONEXISTING_FMT" + os.urandom(2048) | ||
|
||
input_df = pd.DataFrame([dict(raw=binary_data)]) | ||
|
||
class schema(pw.Schema): | ||
raw: bytes | ||
|
||
input_table = pw.debug.table_from_pandas(input_df, schema=schema) | ||
|
||
with pytest.raises(Exception) as excinfo: | ||
result = input_table.select(ret=parser(pw.this.raw)[0][0]) | ||
pw.debug.compute_and_print(result) | ||
|
||
exception_msg = str(excinfo.value) | ||
|
||
assert ( | ||
"This error may indicate libmagic (magic) dependency is missing." | ||
in exception_msg | ||
) | ||
assert "FileType.UNK" in exception_msg |
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