@@ -1101,7 +1101,6 @@ def test_private_completions(self):
11011101 ModuleInfo (None , "_private" , True ),
11021102 ],
11031103 )
1104- @patch .dict (sys .modules , {"foo" : object ()}) # don't propose to import it
11051104 def test_sub_module_private_completions (self ):
11061105 cases = (
11071106 # Return public methods by default
@@ -1380,20 +1379,20 @@ def test_attribute_completion_error_on_import(self):
13801379 self .assertEqual (output , expected )
13811380 self .assertNotIn ("boom" , sys .modules )
13821381
1383-
1382+ @ patch . dict ( sys . modules )
13841383 def test_attribute_completion_error_on_attributes_access (self ):
1385- class BrokenModule :
1386- def __dir__ ( self ):
1387- raise ValueError ( "boom" )
1388-
1389- with ( patch . dict ( sys . modules , { "boom" : BrokenModule ()}),
1390- patch ( "_pyrepl._module_completer.ModuleCompleter.iter_submodules" ,
1391- lambda * _ : [ ModuleInfo ( None , "submodule" , False )])):
1392- events = code_to_events ( "from boom import \t \n " )
1393- reader = self . prepare_reader ( events , namespace = {} )
1394- output = reader . readline ( )
1395- # ignore attributes, just propose submodule
1396- self .assertEqual (output , "from boom import submodule" )
1384+ with tempfile . TemporaryDirectory () as _dir :
1385+ dir = pathlib . Path ( _dir )
1386+ ( dir / "boom" ). mkdir ( )
1387+ ( dir / "boom" / "__init__.py" ). write_text ( "def __dir__(): raise ValueError()" )
1388+ ( dir / "boom" / "submodule.py" ). touch ()
1389+ with patch . object ( sys , "path" , [ _dir , * sys . path ]):
1390+ events = code_to_events ( "from boom import \t \t \n " ) # trigger import
1391+ reader = self . prepare_reader ( events , namespace = {} )
1392+ output = reader . readline ( )
1393+ self . assertIn ( "boom" , sys . modules )
1394+ # ignore attributes, just propose submodule
1395+ self .assertEqual (output , "from boom import submodule" )
13971396
13981397 @patch .dict (sys .modules )
13991398 def test_attribute_completion_private_and_invalid_names (self ):
0 commit comments