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
12 changes: 12 additions & 0 deletions packtools/sps/sps.sch
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<active pattern="article_categories"/>
</phase>

<phase id="phase.fpage_or_elocation-id">
<active pattern="fpage_or_elocation_id"/>
</phase>


<!--
Patterns - sets of rules.
Expand Down Expand Up @@ -92,4 +96,12 @@
</assert>
</rule>
</pattern>

<pattern id="fpage_or_elocation_id">
<rule context="article/front/article-meta">
<assert test="fpage or elocation-id">
Element 'article-meta': Missing elements fpage or elocation-id.
</assert>
</rule>
</pattern>
</schema>
80 changes: 80 additions & 0 deletions tests/test_schematron.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,83 @@ def test_article_categories_is_absent(self):

self.assertFalse(self._run_validation(sample))


class fpage_OR_elocationTests(unittest.TestCase):
"""Tests for article/front/article-meta/fpage or elocation-id elements.
"""
def _run_validation(self, sample):
schematron = isoschematron.Schematron(SCH, phase='phase.fpage_or_elocation-id')
return schematron.validate(etree.parse(sample))

def test_case1(self):
"""
fpage is True
elocation-id is True
fpage v elocation-id is True
"""
sample = """<article>
<front>
<article-meta>
<fpage>01</fpage>
<elocation-id>E27</elocation-id>
</article-meta>
</front>
</article>
"""
sample = StringIO(sample)

self.assertTrue(self._run_validation(sample))

def test_case2(self):
"""
fpage is True
elocation-id is False
fpage v elocation-id is True
"""
sample = """<article>
<front>
<article-meta>
<fpage>01</fpage>
</article-meta>
</front>
</article>
"""
sample = StringIO(sample)

self.assertTrue(self._run_validation(sample))

def test_case3(self):
"""
fpage is False
elocation-id is True
fpage v elocation-id is True
"""
sample = """<article>
<front>
<article-meta>
<elocation-id>E27</elocation-id>
</article-meta>
</front>
</article>
"""
sample = StringIO(sample)

self.assertTrue(self._run_validation(sample))

def test_case4(self):
"""
fpage is False
elocation-id is False
fpage v elocation-id is False
"""
sample = """<article>
<front>
<article-meta>
</article-meta>
</front>
</article>
"""
sample = StringIO(sample)

self.assertFalse(self._run_validation(sample))