@@ -34,6 +34,32 @@ def test_guido_as_bdfl(self):
3434 # parser reports the start of the token
3535 self .assertEqual (cm .exception .offset , 3 )
3636
37+ def test_barry_as_bdfl_look_ma_with_no_compiler_flags (self ):
38+ # Check that the future import is handled by the parser
39+ # even if the compiler flags are not passed.
40+ code = "from __future__ import barry_as_FLUFL;2 {0} 3"
41+ compile (code .format ('<>' ), '<BDFL test>' , 'exec' )
42+ with self .assertRaises (SyntaxError ) as cm :
43+ compile (code .format ('!=' ), '<FLUFL test>' , 'exec' )
44+ self .assertRegex (str (cm .exception ), "with Barry as BDFL, use '<>' instead of '!='" )
45+ self .assertIn ('2 != 3' , cm .exception .text )
46+ self .assertEqual (cm .exception .filename , '<FLUFL test>' )
47+ self .assertEqual (cm .exception .lineno , 1 )
48+ self .assertEqual (cm .exception .offset , len (code ) - 4 )
49+
50+ def test_barry_as_bdfl_relative_import (self ):
51+ code = "from .__future__ import barry_as_FLUFL;2 {0} 3"
52+ compile (code .format ('!=' ), '<FLUFL test>' , 'exec' )
53+ with self .assertRaises (SyntaxError ) as cm :
54+ compile (code .format ('<>' ), '<BDFL test>' , 'exec' )
55+ self .assertRegex (str (cm .exception ), "<BDFL test>" )
56+ self .assertIn ('2 <> 3' , cm .exception .text )
57+ self .assertEqual (cm .exception .filename , '<BDFL test>' )
58+ self .assertEqual (cm .exception .lineno , 1 )
59+ self .assertEqual (cm .exception .offset , len (code ) - 4 )
60+
61+
62+
3763
3864if __name__ == '__main__' :
3965 unittest .main ()
0 commit comments