FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle removing resources without parents by Mirochill · Pull Request #108 · aboutcode-org/commoncode · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions src/commoncode/resource.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,9 @@ def remove_resource(self, resource):
parent = resource.parent(self)
if TRACE:
logger_debug(" parent", parent)
parent.children_names.remove(resource.name)
parent.save(self)
if parent:
parent.children_names.remove(resource.name)
parent.save(self)

# remove resource proper
self._remove_resource(resource)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_resource.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ def test_walk_skip_root_basic(self):
]
assert [(r.name, r.is_file) for r in results] == expected

def test_remove_resource_without_parent(self):
test_codebase = self.get_test_loc("resource/codebase")
codebase = Codebase(test_codebase)
resource = codebase.get_resource("codebase/dir/that")
parent = resource.parent(codebase)

codebase.resources_by_path.pop(parent.path)

removed_paths = codebase.remove_resource(resource)

assert removed_paths == {resource.location}
assert resource.path not in codebase.resources_by_path

def test_walk_filtered_with_filtered_root(self):
test_codebase = self.get_test_loc("resource/codebase")
codebase = Codebase(test_codebase)
Expand Down

Back | FazBrowse Home | New Git URL