File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,37 +105,40 @@ def _yatiml_sweeten(self, node: yatiml.Node) -> None:
105105
106106 @classmethod
107107 def _parse_string_representation (cls , text : str ) -> Tuple [str , str , str ]:
108- help_text = 'Import statements should look like "from a.b.c import d"'
108+ help_text = 'Import statements should look like "from a.b.c import <kind> d"'
109109
110110 parts = text .split ()
111111
112112 if len (parts ) > 0 and parts [0 ] != 'from' :
113113 raise RuntimeError (
114- 'Import statement "{text}" does not start with "from".\n ' +
114+ f 'Import statement "{ text } " does not start with "from".\n ' +
115115 help_text )
116116
117117 if len (parts ) > 1 :
118118 module = parts [1 ]
119119
120120 if len (parts ) > 2 and parts [2 ] != 'import' :
121121 raise RuntimeError (
122- 'Import statement "{text}" does not have "import" part.\n ' +
122+ f 'Import statement "{ text } " does not have "import" part.\n ' +
123123 help_text )
124124
125125 if len (parts ) > 3 :
126- try :
127- kind = parts [3 ]
128- except KeyError :
129- raise RuntimeError (
130- f'Tried to import an invalid kind of object "{ parts [3 ]} " in' +
131- f' import statement "{ text } ".\n ' + help_text )
126+ kind = parts [3 ]
127+ else :
128+ raise RuntimeError (
129+ f'Import statement "{ text } " does not specify which kind of thing'
130+ ' to import.\n ' + help_text )
132131
133132 if len (parts ) > 4 :
134133 name = parts [4 ]
134+ else :
135+ raise RuntimeError (
136+ f'Import statement "{ text } " does not specify the name of the thing'
137+ ' to import.\n ' + help_text )
135138
136139 if len (parts ) > 5 :
137140 raise RuntimeError (
138- 'Extra text found at end of import statement "{text}".\n ' +
141+ f 'Extra text found at end of import statement "{ text } ".\n ' +
139142 help_text )
140143
141144 return module , kind , name
Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ def test_load_invalid_import6(load_import: LoadImport) -> None:
7171 load_import ('from nlesc.examples[1] import implementation example' )
7272
7373
74+ def test_load_invalid_import7 (load_import : LoadImport ) -> None :
75+ with pytest .raises (RuntimeError ):
76+ load_import ('from a.b import example' )
77+
78+
79+ def test_load_invalid_import8 (load_import : LoadImport ) -> None :
80+ with pytest .raises (RuntimeError ):
81+ load_import ('from a.b import implementation' )
82+
83+
7484def test_module_path () -> None :
7585 imp = ImportStatement ('nlesc.examples' , 'implementation' , 'test' )
7686 assert imp .module_path () == Path ('nlesc/examples.ymmsl' )
You can’t perform that action at this time.
0 commit comments