Skip to content

Commit 194d1df

Browse files
committed
2 parents 578612c + 44974c5 commit 194d1df

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
import markitdown._uri_utils
4+
5+
6+
class TestUriUtils:
7+
8+
def test_file_uri_to_path(self):
9+
assert markitdown._uri_utils.file_uri_to_path("file://markitdown/tests/test_files/test.docx") == ("markitdown", "/tests/test_files/test.docx")
10+
11+
def test_file_uri_to_path_raises_error(self):
12+
with pytest.raises(ValueError):
13+
markitdown._uri_utils.file_uri_to_path("https://google.com/")
14+
15+
@pytest.mark.parametrize("uri, expected", [("data:,Hello%2C%20World%21", (None, {}, b"Hello, World!")),
16+
("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==", ("text/plain", {}, b"Hello, World!")),
17+
("data:text/plain;first=Hello;second=World,attributes%20with%20%3D", ("text/plain", {"first":"Hello", "second":"World"}, b"attributes with =")),
18+
("data:text/plain;test_attribute,empty%20attribute", ("text/plain", {'test_attribute': ''}, b"empty attribute")),
19+
])
20+
def test_parse_data_uri(self, uri, expected):
21+
assert markitdown._uri_utils.parse_data_uri(uri) == expected
22+
23+
def test_parse_data_uri_raises_error_not_data_uri(self):
24+
with pytest.raises(ValueError):
25+
markitdown._uri_utils.parse_data_uri("https://google.com/")
26+
27+
def test_parse_data_uri_raises_error_malformed_uri(self):
28+
with pytest.raises(ValueError):
29+
markitdown._uri_utils.parse_data_uri("data:Hello%2C%20World%21")

0 commit comments

Comments
 (0)