Skip to content

Commit

Permalink
Merge pull request #346 from rafaelpezzuto/fix-validation-xml-lang
Browse files Browse the repository at this point in the history
Corrige situação de validador de xml:lang sem atributo
  • Loading branch information
rafaelpezzuto authored Nov 9, 2022
2 parents cc1280b + 477b7b4 commit e057718
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packtools/sps/validation/article_and_subarticles.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ def validate_language(xml):
line=i.get('line_number'),
))

if not tag_is_valid(_lang):
elif not tag_is_valid(_lang):
_message = f'XML {_article_type} has an invalid language: {_lang}'
errors.append(exceptions.ValidationArticleAndSubArticlesHasInvalidLanguage(
message=_message,
2 changes: 1 addition & 1 deletion packtools/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Single source to the version across setup.py and the whole project.
"""
from __future__ import unicode_literals
__version__ = '2.16'
__version__ = '2.16.1'
50 changes: 49 additions & 1 deletion tests/sps/validation/test_article_and_subarticles.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,31 @@
from packtools.sps.validation.article_and_subarticles import validate_language


class ArticleTest(TestCase):
class ArticleAndSubarticlesTest(TestCase):
def test_article_has_no_language_attribute(self):
xml_str = """
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article">
<front>
<article-meta>
<article-id pub-id-type="publisher-id" specific-use="scielo-v3">zTn4sYXBrfSTMNVPF5Dm7jr</article-id>
<article-id pub-id-type="publisher-id" specific-use="scielo-v2">S0103-50532014001202258</article-id>
<article-id pub-id-type="doi">10.5935/0103-5053.20140192</article-id>
</article-meta>
</front>
</article>
"""
xml_tree = get_xml_tree(xml_str)

result, errors = validate_language(xml_tree)

self.assertFalse(result)

self.assertListEqual(
['XML research-article has no language.'],
[e.message for e in errors]
)


def test_article_has_valid_language(self):
xml_str = """
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en">
@@ -102,6 +126,30 @@ def test_article_and_subarticles_with_two_valid_languages_and_one_invalid(self):
[e.line for e in errors]
)

def test_article_and_subarticles_with_one_valid_language_one_empty_and_one_invalid(self):
xml_str = """
<article article-type="research-article" dtd-version="1.1" specific-use="sps-1.9" xml:lang="en" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">
<sub-article article-type="translation" id="s1">
</sub-article>
<sub-article article-type="translation" id="s2" xml:lang="">
</sub-article>
</article>
"""
xml_tree = get_xml_tree(xml_str)
result, errors = validate_language(xml_tree)

self.assertFalse(result)

self.assertListEqual(
['XML translation has no language.', 'XML translation has an invalid language: '],
[e.message for e in errors]
)

self.assertListEqual(
[3, 5],
[e.line for e in errors]
)


def test_article_and_subarticles_with_two_invalid_languages(self):
xml_str = """

0 comments on commit e057718

Please sign in to comment.