@@ -929,7 +929,7 @@ def prepare_reader(self, events, namespace):
929929 reader = ReadlineAlikeReader (console = console , config = config )
930930 return reader
931931
932- def test_import_completions (self ):
932+ def _only_stdlib_imports (self ):
933933 import importlib
934934 # Make iter_modules() search only the standard library.
935935 # This makes the test more reliable in case there are
@@ -938,22 +938,21 @@ def test_import_completions(self):
938938 lib_path = os .path .dirname (importlib .__path__ [0 ])
939939 sys .path = [lib_path ]
940940
941+ def test_import_completions (self ):
942+ self ._only_stdlib_imports ()
941943 cases = (
942944 ("import path\t \n " , "import pathlib" ),
943945 ("import importlib.\t \t res\t \n " , "import importlib.resources" ),
944946 ("import importlib.resources.\t \t a\t \n " , "import importlib.resources.abc" ),
945947 ("import foo, impo\t \n " , "import foo, importlib" ),
946948 ("import foo as bar, impo\t \n " , "import foo as bar, importlib" ),
947- ("import pri\t \n " , "import pri" ), # do not complete with "print("
948949 ("from impo\t \n " , "from importlib" ),
949- ("from pri\t \n " , "from pri" ),
950950 ("from importlib.res\t \n " , "from importlib.resources" ),
951951 ("from importlib.\t \t res\t \n " , "from importlib.resources" ),
952952 ("from importlib.resources.ab\t \n " , "from importlib.resources.abc" ),
953953 ("from importlib import mac\t \n " , "from importlib import machinery" ),
954954 ("from importlib import res\t \n " , "from importlib import resources" ),
955955 ("from importlib.res\t import a\t \n " , "from importlib.resources import abc" ),
956- ("from typing import Na\t \n " , "from typing import Na" ), # do not complete with "NameError("
957956 )
958957 for code , expected in cases :
959958 with self .subTest (code = code ):
@@ -991,6 +990,20 @@ def test_invalid_identifiers(self):
991990 output = reader .readline ()
992991 self .assertEqual (output , expected )
993992
993+ def test_no_fallback_on_regular_completion (self ):
994+ self ._only_stdlib_imports ()
995+ cases = (
996+ ("import pri\t \n " , "import pri" ),
997+ ("from pri\t \n " , "from pri" ),
998+ ("from typing import Na\t \n " , "from typing import Na" ),
999+ )
1000+ for code , expected in cases :
1001+ with self .subTest (code = code ):
1002+ events = code_to_events (code )
1003+ reader = self .prepare_reader (events , namespace = {})
1004+ output = reader .readline ()
1005+ self .assertEqual (output , expected )
1006+
9941007 def test_get_path_and_prefix (self ):
9951008 cases = (
9961009 ('' , ('' , '' )),
0 commit comments