@@ -154,10 +154,10 @@ def test_it_identifies_NDJSON_for_file_like_object_with_no_name_but_NDJSON_conte
154154 assert detect_filetype (file = file , content_type = FileType .NDJSON .mime_type ) == FileType .NDJSON
155155
156156
157- # TODO: ideally this test should pass, currently fails
158- # def test_it_identifies_NDJSON_for_file_with_ndjson_extension_but_JSON_content_type():
159- # file_path = example_doc_path("simple.ndjson")
160- # assert detect_filetype(file_path, content_type=FileType.JSON.mime_type) == FileType.NDJSON
157+ def test_it_identifies_NDJSON_for_file_with_ndjson_extension_but_JSON_content_type ():
158+ file_path = example_doc_path ( "simple.ndjson" )
159+ assert detect_filetype ( file_path , content_type = FileType . JSON . mime_type ) == FileType . NDJSON
160+
161161
162162# ================================================================================================
163163# STRATEGY #3 - GUESS MIME-TYPE WITH LIBMAGIC/FILETYPE LIBRARY
@@ -396,6 +396,27 @@ def test_it_detects_HTML_from_guessed_mime_type_ending_with_xml_and_html_extensi
396396 assert file_type is FileType .HTML
397397
398398
399+ @pytest .mark .parametrize (
400+ ("expected_value" , "file_name" ),
401+ [(FileType .NDJSON , "simple.ndjson" ), (FileType .JSON , "spring-weather.html.json" )],
402+ )
403+ def test_it_detects_correct_json_type_without_extension (expected_value : FileType , file_name : str ):
404+ with open (example_doc_path (file_name ), "rb" ) as f :
405+ file = io .BytesIO (f .read ())
406+
407+ filetype = detect_filetype (file = file )
408+ assert filetype == expected_value
409+
410+
411+ @pytest .mark .parametrize (
412+ ("expected_value" , "file_name" ),
413+ [(FileType .NDJSON , "simple.ndjson" ), (FileType .JSON , "spring-weather.html.json" )],
414+ )
415+ def test_it_detects_correct_json_type_with_extension (expected_value : FileType , file_name : str ):
416+ filetype = detect_filetype (file_path = example_doc_path (file_name ))
417+ assert filetype == expected_value
418+
419+
399420@pytest .mark .parametrize (
400421 ("mime_type" , "file_name" ),
401422 [
0 commit comments