Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion py_maplib/tests/test_custom_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import polars as pl
import pytest
from polars.testing import assert_frame_equal

from maplib import Model, RDFType, MaplibException, rdf

from maplib import Model, RDFType, MaplibException

def test_struuidv5_dns():
m = Model()
Expand Down Expand Up @@ -77,3 +80,70 @@ def test_struuidv5_valid():
""")
assert df.height == 3

def test_concat_lang_string_same_lang():
m = Model()
df = m.query("""
SELECT * WHERE {
VALUES ?name {"bar"@en}
BIND(concat("foo"@en, ?name) AS ?concatstr)
}
""")
expected_df = pl.from_repr(
"""
┌─────────────┬──────────┐
│ concatstr ┆ name │
│ --- ┆ --- │
│ str ┆ str │
╞═════════════╪══════════╡
│ "foobar"@en ┆ "bar"@en │
└─────────────┴──────────┘
"""
)
sm = m.query("""
SELECT * WHERE {
VALUES ?name {"bar"@en}
BIND(concat("foo"@en, ?name) AS ?concatstr)
}
""", solution_mappings=True)
assert_frame_equal(df, expected_df)
assert sm.rdf_types["concatstr"] == RDFType.Literal(rdf.langString)

def test_concat_lang_string_diff_lang():
m = Model()
df = m.query("""
SELECT * WHERE {
VALUES ?name {"bar"@en}
BIND(concat(?name, "noe"@no) AS ?concatstr)
}
""")
expected_df = pl.from_repr("""
┌─────────────┬──────────┐
│ concatstr ┆ name │
│ --- ┆ --- │
│ str ┆ str │
╞═════════════╪══════════╡
│ "barnoe"@en ┆ "bar"@en │
└─────────────┴──────────┘
"""
)
assert_frame_equal(df, expected_df)

def test_encoding_of_parenthesis():
m = Model()
df = m.query("""
SELECT * WHERE {
VALUES ?name {"Foo(bar)"}
BIND(ENCODE_FOR_URI(?name) AS ?encodedstr)
}
""")
expected_df = pl.from_repr("""
┌──────────────┬──────────┐
│ encodedstr ┆ name │
│ --- ┆ --- │
│ str ┆ str │
╞══════════════╪══════════╡
│ Foo%28bar%29 ┆ Foo(bar) │
└──────────────┴──────────┘
"""
)
assert_frame_equal(df, expected_df)
Loading