File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed
tests/unit/adaptors/graph Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 22Changelog
33=========
44
5+ Unreleased
6+ ----------
7+
8+ * Fixed handling of within-descendant-imports when squashing modules (see `Issue 195 <https://github.com/seddonym/grimp/issues/195 >`_).
9+
5103.7 (2025-03-07)
611----------------
712
Original file line number Diff line number Diff line change @@ -178,11 +178,6 @@ impl Graph {
178178 } )
179179 . collect ( ) ;
180180
181- // Remove any descendants.
182- for descendant in descendants {
183- self . remove_module ( descendant) ;
184- }
185-
186181 // Add descendants and imports to parent module.
187182 for imported in modules_imported_by_descendants {
188183 self . add_import ( module, imported) ;
@@ -192,6 +187,11 @@ impl Graph {
192187 self . add_import ( importer, module) ;
193188 }
194189
190+ // Remove any descendants.
191+ for descendant in descendants {
192+ self . remove_module ( descendant) ;
193+ }
194+
195195 self . mark_module_squashed ( module) ;
196196 }
197197}
Original file line number Diff line number Diff line change @@ -447,3 +447,22 @@ def test_raises_module_not_present_if_no_module(self):
447447
448448 with pytest .raises (ModuleNotPresent ):
449449 graph .squash_module ("foo" )
450+
451+ def test_correctly_handles_imports_within_descendants (self ):
452+ graph = ImportGraph ()
453+
454+ graph .add_module ("animals" )
455+ graph .add_module ("food" )
456+ graph .add_import (importer = "animals.dog" , imported = "food.chicken" )
457+ graph .add_import (importer = "app.cli" , imported = "animals.dog" )
458+ # We want to check that this import within the descendants of `animals` does
459+ # not cause problems. If this import is not properly removed then the imports map can
460+ # become corrupted, since it will contain an import to modules that no longer exist.
461+ # See https://github.com/seddonym/grimp/issues/195 for more details.
462+ graph .add_import (importer = "animals.dog" , imported = "animals.base" )
463+
464+ graph .squash_module ("animals" )
465+
466+ # If the `animals` module was squashed correctly then the following calls should not panic.
467+ assert graph .find_modules_directly_imported_by ("animals" ) == {"food.chicken" }
468+ assert graph .find_modules_that_directly_import ("animals" ) == {"app.cli" }
You can’t perform that action at this time.
0 commit comments