File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -720,14 +720,15 @@ def create_page() -> Tuple[Page, EmbeddedRstParser]:
720720
721721 # Attempt to read the literally included file
722722 try :
723- with open (filepath ) as file :
724- text = file .read ()
725-
723+ text = filepath .read_text (encoding = "utf-8" )
726724 except OSError as err :
727725 self .diagnostics .append (
728726 CannotOpenFile (argument_text , err .strerror , line )
729727 )
730728 return doc
729+ except UnicodeDecodeError as err :
730+ self .diagnostics .append (CannotOpenFile (argument_text , str (err ), line ))
731+ return doc
731732
732733 lines = text .split ("\n " )
733734
Original file line number Diff line number Diff line change @@ -703,6 +703,20 @@ def test_literalinclude() -> None:
703703 assert len (diagnostics ) == 1
704704 assert isinstance (diagnostics [0 ], DocUtilsParseError )
705705
706+ # Test non-textual
707+ page , diagnostics = parse_rst (
708+ parser ,
709+ path ,
710+ """
711+ .. literalinclude:: /compass-explain-plan-with-index-raw-json.png
712+ """ ,
713+ )
714+ page .finish (diagnostics )
715+ assert len (diagnostics ) == 1
716+ assert [(type (d ), "utf-8" in d .message ) for d in diagnostics ] == [
717+ (CannotOpenFile , True )
718+ ]
719+
706720
707721def test_include () -> None :
708722 path = ROOT_PATH .joinpath (Path ("test.rst" ))
You can’t perform that action at this time.
0 commit comments