|
| 1 | +import sys |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 |
|
3 | 5 | from pydantic_ai.messages import AudioUrl, BinaryContent, DocumentUrl, ImageUrl, VideoUrl
|
@@ -135,29 +137,33 @@ def test_image_url_invalid():
|
135 | 137 | ImageUrl('foobar.potato').format
|
136 | 138 |
|
137 | 139 |
|
138 |
| -@pytest.mark.parametrize( |
139 |
| - 'document_url,media_type,format', |
140 |
| - [ |
141 |
| - pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'), |
142 |
| - pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'), |
143 |
| - pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'), |
144 |
| - pytest.param( |
145 |
| - DocumentUrl('foobar.docx'), |
146 |
| - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
147 |
| - 'docx', |
148 |
| - id='docx', |
149 |
| - ), |
150 |
| - pytest.param( |
151 |
| - DocumentUrl('foobar.xlsx'), |
152 |
| - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
153 |
| - 'xlsx', |
154 |
| - id='xlsx', |
155 |
| - ), |
156 |
| - pytest.param(DocumentUrl('foobar.html'), 'text/html', 'html', id='html'), |
157 |
| - pytest.param(DocumentUrl('foobar.md'), 'text/markdown', 'md', id='md'), |
158 |
| - pytest.param(DocumentUrl('foobar.xls'), 'application/vnd.ms-excel', 'xls', id='xls'), |
159 |
| - ], |
160 |
| -) |
| 140 | +_url_formats = [ |
| 141 | + pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'), |
| 142 | + pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'), |
| 143 | + pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'), |
| 144 | + pytest.param( |
| 145 | + DocumentUrl('foobar.docx'), |
| 146 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
| 147 | + 'docx', |
| 148 | + id='docx', |
| 149 | + ), |
| 150 | + pytest.param( |
| 151 | + DocumentUrl('foobar.xlsx'), |
| 152 | + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 153 | + 'xlsx', |
| 154 | + id='xlsx', |
| 155 | + ), |
| 156 | + pytest.param(DocumentUrl('foobar.html'), 'text/html', 'html', id='html'), |
| 157 | + pytest.param(DocumentUrl('foobar.xls'), 'application/vnd.ms-excel', 'xls', id='xls'), |
| 158 | +] |
| 159 | +if sys.version_info > (3, 11): # pragma: no branch |
| 160 | + # This solves an issue with MIMEType on MacOS + python < 3.12. mimetypes.py added the text/markdown in 3.12, but on |
| 161 | + # versions of linux the knownfiles include text/markdown so it isn't an issue. The .md test is only consistent |
| 162 | + # independent of OS on > 3.11. |
| 163 | + _url_formats.append(pytest.param(DocumentUrl('foobar.md'), 'text/markdown', 'md', id='md')) |
| 164 | + |
| 165 | + |
| 166 | +@pytest.mark.parametrize('document_url,media_type,format', _url_formats) |
161 | 167 | def test_document_url_formats(document_url: DocumentUrl, media_type: str, format: str):
|
162 | 168 | assert document_url.media_type == media_type
|
163 | 169 | assert document_url.format == format
|
@@ -232,6 +238,7 @@ def test_binary_content_is_methods():
|
232 | 238 | assert document_content.format == 'pdf'
|
233 | 239 |
|
234 | 240 |
|
| 241 | +@pytest.mark.xdist_group(name='url_formats') |
235 | 242 | @pytest.mark.parametrize(
|
236 | 243 | 'video_url,media_type,format',
|
237 | 244 | [
|
|
0 commit comments