@@ -1009,7 +1009,6 @@ def test_private_completions(self):
10091009 ModuleInfo (None , "_private" , True ),
10101010 ],
10111011 )
1012- @patch .dict (sys .modules , {"foo" : object ()}) # don't propose to import it
10131012 def test_sub_module_private_completions (self ):
10141013 cases = (
10151014 # Return public methods by default
@@ -1288,19 +1287,20 @@ def test_attribute_completion_error_on_import(self):
12881287 self .assertEqual (output , expected )
12891288 self .assertNotIn ("boom" , sys .modules )
12901289
1290+ @patch .dict (sys .modules )
12911291 def test_attribute_completion_error_on_attributes_access (self ):
1292- class BrokenModule :
1293- def __dir__ ( self ):
1294- raise ValueError ( "boom" )
1295-
1296- with ( patch . dict ( sys . modules , { "boom" : BrokenModule ()}),
1297- patch ( "_pyrepl._module_completer.ModuleCompleter.iter_submodules" ,
1298- lambda * _ : [ ModuleInfo ( None , "submodule" , False )])):
1299- events = code_to_events ( "from boom import \t \n " )
1300- reader = self . prepare_reader ( events , namespace = {} )
1301- output = reader . readline ( )
1302- # ignore attributes, just propose submodule
1303- self .assertEqual (output , "from boom import submodule" )
1292+ with tempfile . TemporaryDirectory () as _dir :
1293+ dir = pathlib . Path ( _dir )
1294+ ( dir / "boom" ). mkdir ( )
1295+ ( dir / "boom" / "__init__.py" ). write_text ( "def __dir__(): raise ValueError()" )
1296+ ( dir / "boom" / "submodule.py" ). touch ()
1297+ with patch . object ( sys , "path" , [ _dir , * sys . path ]):
1298+ events = code_to_events ( "from boom import \t \t \n " ) # trigger import
1299+ reader = self . prepare_reader ( events , namespace = {} )
1300+ output = reader . readline ( )
1301+ self . assertIn ( "boom" , sys . modules )
1302+ # ignore attributes, just propose submodule
1303+ self .assertEqual (output , "from boom import submodule" )
13041304
13051305 @patch .dict (sys .modules )
13061306 def test_attribute_completion_private_and_invalid_names (self ):
0 commit comments