-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mimetype handling on windows (#259)
This PR fixes handling of mimetypes on windows machines: Needed due to issue: https://bugs.python.org/issue43975 Resolves issue: #245 Chose not to use mimetypes.init since that's using a singleton pattern and worried that users will be likely to run into issues since the server may be parsing files which may also end up using mimetype guessing based on file extension
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
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
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,24 @@ | ||
import pytest | ||
|
||
from langserve.playground import _get_mimetype | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file_extension, expected_mimetype", | ||
[ | ||
("js", "application/javascript"), | ||
("css", "text/css"), | ||
("htm", "text/html"), | ||
("html", "text/html"), | ||
("txt", "text/plain"), # An example of an unknown extension using guess_type | ||
], | ||
) | ||
def test_get_mimetype(file_extension: str, expected_mimetype: str) -> None: | ||
# Create a filename with the given extension | ||
filename = f"test_file.{file_extension}" | ||
|
||
# Call the _get_mimetype function with the test filename | ||
mimetype = _get_mimetype(filename) | ||
|
||
# Check if the returned mimetype matches the expected one | ||
assert mimetype == expected_mimetype |