@@ -823,6 +823,27 @@ def test_index_falls_back_to_static_page_without_flasgger(self):
823823 self .assertEqual (result .returncode , 0 , result .stderr )
824824 self .assertIn ("OK" , result .stdout )
825825
826+ def test_sources_have_no_invalid_escape_sequences (self ):
827+ """Every module in the httpbin package compiles without escape-sequence
828+ warnings. Invalid escapes are a SyntaxWarning on 3.12+ (DeprecationWarning
829+ earlier) and will become a SyntaxError in a future Python."""
830+ import glob
831+ import warnings
832+
833+ pkg_dir = os .path .dirname (httpbin .__file__ )
834+ py_files = glob .glob (os .path .join (pkg_dir , "**" , "*.py" ), recursive = True )
835+ self .assertTrue (py_files , "no source files found" )
836+ with warnings .catch_warnings ():
837+ warnings .simplefilter ("error" , SyntaxWarning )
838+ warnings .simplefilter ("error" , DeprecationWarning )
839+ for path in py_files :
840+ with open (path , encoding = "utf-8" ) as f :
841+ src = f .read ()
842+ try :
843+ compile (src , path , "exec" )
844+ except (SyntaxWarning , DeprecationWarning ) as exc :
845+ self .fail ("{}: {}" .format (path , exc ))
846+
826847 def test_parse_multi_value_header (self ):
827848 self .assertEqual (parse_multi_value_header ('xyzzy' ), [ "xyzzy" ])
828849 self .assertEqual (parse_multi_value_header ('"xyzzy"' ), [ "xyzzy" ])
0 commit comments