Skip to content

Commit

Permalink
update prune and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kena-SL committed Jan 29, 2024
1 parent c7f48f4 commit 6a65dfd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
14 changes: 11 additions & 3 deletions digital_land/phase/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ def process(self, stream):
entry_number = block["entry-number"]

if self.issues:
self.issues.log_issue(
"entity", "unknown entity", curie, line_number=line_number
)
if not reference:
self.issues.log_issue(
"entity",
"unknown entity - missing reference",
curie,
line_number=line_number,
)
else:
self.issues.log_issue(
"entity", "unknown entity", curie, line_number=line_number
)

logging.info(
f"{resource} row {entry_number}: missing entity for {curie}"
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/phase/test_prune.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from digital_land.phase.prune import EntityPrunePhase
from digital_land.log import IssueLog
from digital_land.log import DatasetResourceLog


class TestEntityPrunePhase:
def test_process_returns_missing_reference(self):
input_stream = [
{
"row": {
"prefix": "ancient-woodland",
"reference": "",
"entity": "",
},
"entry-number": 1,
"resource": "123",
"line-number": 2,
}
]
issues = IssueLog()
resource_log = DatasetResourceLog()
phase = EntityPrunePhase(issues, resource_log)

list(phase.process(input_stream))
assert issues.rows[0]["issue-type"] == "unknown entity - missing reference"

def test_process_returns_unknown_entity(self):
input_stream = [
{
"row": {
"prefix": "dataset",
"reference": "REF01",
"entity": "",
},
"entry-number": 1,
"resource": "123",
"line-number": 2,
}
]
issues = IssueLog()
resource_log = DatasetResourceLog()
phase = EntityPrunePhase(issues, resource_log)

list(phase.process(input_stream))
assert issues.rows[0]["issue-type"] == "unknown entity"

0 comments on commit 6a65dfd

Please sign in to comment.