@@ -259,22 +259,44 @@ def raise_memoryerror(*args, **kwargs):
259259 def test_loader (self ):
260260 filename = 'scheme://path'
261261
262- for loader in (None , object (), NoSourceLoader ()):
262+ linecache .clearcache ()
263+ module_globals = {'__name__' : 'a.b.c' , '__loader__' : None }
264+ self .assertEqual (linecache .getlines (filename , module_globals ), [])
265+
266+ for loader in object (), NoSourceLoader ():
263267 linecache .clearcache ()
264268 module_globals = {'__name__' : 'a.b.c' , '__loader__' : loader }
265- self .assertEqual (linecache .getlines (filename , module_globals ), [])
269+ with self .assertWarns (DeprecationWarning ) as w :
270+ self .assertEqual (linecache .getlines (filename , module_globals ), [])
271+ self .assertEqual (str (w .warning ),
272+ 'Module globals is missing a __spec__.loader' )
266273
267274 linecache .clearcache ()
268275 module_globals = {'__name__' : 'a.b.c' , '__loader__' : FakeLoader ()}
269- self .assertEqual (linecache .getlines (filename , module_globals ),
270- ['source for a.b.c\n ' ])
276+ with self .assertWarns (DeprecationWarning ) as w :
277+ self .assertEqual (linecache .getlines (filename , module_globals ),
278+ ['source for a.b.c\n ' ])
279+ self .assertEqual (str (w .warning ),
280+ 'Module globals is missing a __spec__.loader' )
271281
272- for spec in ( None , object (), ModuleSpec ( '' , FakeLoader ()) ):
282+ for spec in None , object ():
273283 linecache .clearcache ()
274284 module_globals = {'__name__' : 'a.b.c' , '__loader__' : FakeLoader (),
275285 '__spec__' : spec }
286+ with self .assertWarns (DeprecationWarning ) as w :
287+ self .assertEqual (linecache .getlines (filename , module_globals ),
288+ ['source for a.b.c\n ' ])
289+ self .assertEqual (str (w .warning ),
290+ 'Module globals is missing a __spec__.loader' )
291+
292+ linecache .clearcache ()
293+ module_globals = {'__name__' : 'a.b.c' , '__loader__' : FakeLoader (),
294+ '__spec__' : ModuleSpec ('' , FakeLoader ())}
295+ with self .assertWarns (DeprecationWarning ) as w :
276296 self .assertEqual (linecache .getlines (filename , module_globals ),
277297 ['source for a.b.c\n ' ])
298+ self .assertEqual (str (w .warning ),
299+ 'Module globals; __loader__ != __spec__.loader' )
278300
279301 linecache .clearcache ()
280302 spec = ModuleSpec ('x.y.z' , FakeLoader ())
0 commit comments