Skip to content

Commit a4cce0a

Browse files
Address code review feedback: enforce uppercase X in ISSN, clean up data fields
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
1 parent f12de5a commit a4cce0a

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

packtools/sps/validation/journal_meta.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def validate_publisher_id_presence(self, error_level="CRITICAL"):
483483
expected='<journal-id journal-id-type="publisher-id"> with non-empty value',
484484
obtained=publisher_id if is_valid else None,
485485
advice='Add <journal-id journal-id-type="publisher-id">ACRONYM</journal-id> inside <journal-meta>',
486-
data={'publisher_id': publisher_id},
486+
data={'publisher_id': publisher_id} if is_valid else None,
487487
error_level=error_level,
488488
)
489489

@@ -512,7 +512,7 @@ def validate_journal_title_presence(self, error_level="CRITICAL"):
512512
expected='<journal-title> with non-empty value',
513513
obtained=journal_title if is_valid else None,
514514
advice='Add <journal-title>Title</journal-title> inside <journal-title-group>',
515-
data={'journal_title': journal_title},
515+
data={'journal_title': journal_title} if is_valid else None,
516516
error_level=error_level,
517517
)
518518

@@ -541,7 +541,7 @@ def validate_abbrev_journal_title_presence(self, error_level="CRITICAL"):
541541
expected='<abbrev-journal-title abbrev-type="publisher"> with non-empty value',
542542
obtained=abbrev_title if is_valid else None,
543543
advice='Add <abbrev-journal-title abbrev-type="publisher">Abbrev. Title</abbrev-journal-title> inside <journal-title-group>',
544-
data={'abbrev_title': abbrev_title},
544+
data={'abbrev_title': abbrev_title} if is_valid else None,
545545
error_level=error_level,
546546
)
547547

@@ -601,7 +601,7 @@ def validate_publisher_name_presence(self, error_level="CRITICAL"):
601601
expected='<publisher-name> with non-empty value',
602602
obtained=publisher_name if is_valid else None,
603603
advice='Add <publisher><publisher-name>Publisher Name</publisher-name></publisher> inside <journal-meta>',
604-
data={'publisher_name': publisher_name},
604+
data={'publisher_name': publisher_name} if is_valid else None,
605605
error_level=error_level,
606606
)
607607

@@ -619,14 +619,15 @@ def validate_issn_format(self, error_level="ERROR"):
619619
"""
620620
Rule 8: Validates ISSN format (XXXX-XXXX pattern).
621621
ISSN must be 4 digits, hyphen, 4 digits (last digit can be X).
622+
According to ISO 3297, the check digit X must be uppercase.
622623
623624
Returns
624625
-------
625626
generator of dict
626627
Validation results for each ISSN format.
627628
"""
628-
# Regex pattern for ISSN: 4 digits, hyphen, 3 digits + (digit or X)
629-
issn_pattern = re.compile(r'^\d{4}-\d{3}[\dXx]$')
629+
# Regex pattern for ISSN: 4 digits, hyphen, 3 digits + (digit or uppercase X)
630+
issn_pattern = re.compile(r'^\d{4}-\d{3}[\dX]$')
630631

631632
for issn_data in self.journal_issns.data:
632633
issn_value = issn_data.get('value', '')

tests/sps/validation/test_journal_meta.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,28 @@ def test_validate_issn_format_invalid_wrong_length(self):
10411041
self.assertEqual(len(results), 1)
10421042
self.assertEqual(results[0]['response'], 'ERROR')
10431043

1044+
def test_validate_issn_format_invalid_lowercase_x(self):
1045+
"""Test ISSN format validation rejects lowercase x (must be uppercase X)"""
1046+
xmltree = etree.fromstring(
1047+
"""
1048+
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en">
1049+
<front>
1050+
<journal-meta>
1051+
<issn pub-type="epub">1234-567x</issn>
1052+
</journal-meta>
1053+
</front>
1054+
</article>
1055+
"""
1056+
)
1057+
from packtools.sps.validation.journal_meta import ISSNFormatValidation
1058+
validation = ISSNFormatValidation(xmltree)
1059+
results = list(validation.validate_issn_format())
1060+
1061+
self.assertEqual(len(results), 1)
1062+
self.assertEqual(results[0]['response'], 'ERROR')
1063+
1064+
1065+
10441066

10451067
class JournalMetaAttributeTest(TestCase):
10461068
"""Tests for JournalMetaAttributeValidation class"""
@@ -1171,3 +1193,6 @@ def test_validate_issn_type_uniqueness_failure(self):
11711193
self.assertEqual(len(results), 1)
11721194
self.assertEqual(results[0]['response'], 'WARNING')
11731195
self.assertIn('epub', results[0]['data']['duplicates'])
1196+
1197+
def test_validate_issn_format_invalid_lowercase_x(self):
1198+
"""Test ISSN format validation rejects lowercase x (must be uppercase X)"""

0 commit comments

Comments
 (0)