Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/data/dangling-component.st.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
movie: Real Movie (2000)
========================

:: Title
Real Movie

:: Date
2000-01-01

:: Description
A real movie that exists as a story.


Collection: Test Collection
===========================

:: Title
Test Collection

:: Date
2000

:: Description
A collection that lists one real story and one missing story.

:: Component Stories
movie: Real Movie (2000)
movie: Missing Movie (1999)
13 changes: 13 additions & 0 deletions tests/test_totolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@ def test_multiple_entries(self):
warnings = list(ontology._impl.validate_entries())
assert any("Multiple TOStory with name" in x for x in warnings)

def test_component_warning(self):
ontology = totolo.files("tests/data/dangling-component.st.txt")
warnings = list(ontology._impl.validate_components())
# The missing component story is flagged...
assert any(
"Undefined 'component story'" in x and "movie: Missing Movie (1999)" in x
for x in warnings
)
# ...while the component story that exists is not.
assert not any("movie: Real Movie (2000)" in x for x in warnings)
# And it surfaces through the top-level validate().
assert any("Undefined 'component story'" in x for x in ontology.validate())


class TestOperations:
def test_equality(self):
Expand Down
2 changes: 1 addition & 1 deletion totolo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


remote = TORemote()
__version__ = "2.1.3"
__version__ = "2.1.4"
__ALL__ = [
empty,
files,
Expand Down
9 changes: 9 additions & 0 deletions totolo/impl/to_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def organize_collections(self):
def validate(self):
yield from self._impl.validate_entries()
yield from self._impl.validate_storythemes()
yield from self._impl.validate_components()
yield from self._impl.validate_cycles()

def write(self, prefix=None, cleaned=False, verbose=False):
Expand Down Expand Up @@ -299,6 +300,14 @@ def validate_storythemes(self):
yield (f"{story.name}: Undefined '{weight} theme' with "
f"name '{kwfield.keyword}'")

def validate_components(self):
"""Detect component stories of collections that reference undefined stories."""
for story in self.o.stories():
for component_name in story.get("Component Stories"):
if component_name not in self.o.story:
yield (f"{story.name}: Undefined 'component story' with "
f"name '{component_name}'")

def validate_cycles(self):
"""Detect cycles (stops after first cycle encountered)."""
parents = {}
Expand Down
Loading