11import pytest # type: ignore
22
33from grimp .adaptors .graph import ImportGraph
4- from grimp .exceptions import InvalidModuleExpression
4+ import re
5+ from grimp .exceptions import InvalidImportExpression
56
67
78def test_find_modules_directly_imported_by ():
@@ -318,9 +319,7 @@ def test_finds_matching_direct_imports(self, import_line_number, import_line_con
318319 line_contents = import_line_contents ,
319320 )
320321
321- assert graph .find_matching_direct_imports (
322- importer_expression = "pkg.animals.*" , imported_expression = "pkg.food.*"
323- ) == [
322+ assert graph .find_matching_direct_imports ("pkg.animals.* -> pkg.food.*" ) == [
324323 {"importer" : "pkg.animals.cat" , "imported" : "pkg.food.fish" },
325324 {"importer" : "pkg.animals.dog" , "imported" : "pkg.food.chicken" },
326325 ]
@@ -340,26 +339,22 @@ def test_deduplicates_imports(self):
340339 line_contents = "...2" ,
341340 )
342341
343- assert graph .find_matching_direct_imports (
344- importer_expression = "pkg.animals.*" , imported_expression = "pkg.colors.*"
345- ) == [
342+ assert graph .find_matching_direct_imports ("pkg.animals.* -> pkg.colors.*" ) == [
346343 {"importer" : "pkg.animals.dog" , "imported" : "pkg.colors.golden" },
347344 ]
348345
349- def test_raises_error_if_importer_expression_is_invalid (self ):
350- graph = ImportGraph ()
351- with pytest .raises (
352- InvalidModuleExpression , match = "foo.. is not a valid module expression."
353- ):
354- graph .find_matching_direct_imports (
355- importer_expression = "foo.." , imported_expression = "bar"
356- )
357-
358- def test_raises_error_if_imported_expression_is_invalid (self ):
346+ @pytest .mark .parametrize (
347+ "expression" ,
348+ [
349+ "foo.. -> bar" ,
350+ "foo -> bar.." ,
351+ "foo > bar" ,
352+ ],
353+ )
354+ def test_raises_error_if_expression_is_invalid (self , expression ):
359355 graph = ImportGraph ()
360356 with pytest .raises (
361- InvalidModuleExpression , match = "bar.. is not a valid module expression."
357+ InvalidImportExpression ,
358+ match = re .escape (f"{ expression } is not a valid import expression." ),
362359 ):
363- graph .find_matching_direct_imports (
364- importer_expression = "foo" , imported_expression = "bar.."
365- )
360+ graph .find_matching_direct_imports (expression )
0 commit comments