Cria deprecated_sps_pkg_name para manter acessível a versão anterior do nome do pacote#1065
Conversation
- Add deprecated_sps_pkg_name_fpage: formats fpage without underscore before seq - Add deprecated_sps_pkg_name_suppl: returns raw suppl value (not prefixed with 's') - Add deprecated_sps_pkg_name: builds package name using deprecated format
There was a problem hiding this comment.
Pull request overview
This pull request adds deprecated properties (deprecated_sps_pkg_name, deprecated_sps_pkg_name_suppl, deprecated_sps_pkg_name_fpage) to maintain backward compatibility with the previous SPS package naming format. The changes were made because sps_pkg_name was modified with new formatting rules: supplements changed from "1" to "s1", and fpage now includes a v2 suffix when fpage equals lpage.
Changes:
- Added
deprecated_sps_pkg_name_fpage,deprecated_sps_pkg_name_suppl, anddeprecated_sps_pkg_nameproperties to XMLWithPre class - Exposed
deprecated_sps_pkg_namein PidProviderXMLAdapter - Created comprehensive test suite for both new and deprecated naming conventions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| tests/sps/pid_provider/test_xml_sps_lib.py | New test file with comprehensive tests for SPS package name properties, including deprecated versions |
| packtools/sps/pid_provider/xml_sps_lib.py | Added deprecated property implementations for backward-compatible package naming |
| packtools/sps/pid_provider/xml_sps_adapter.py | Exposed deprecated_sps_pkg_name property through the adapter interface |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def sps_pkg_name(self): | ||
| return self.xml_with_pre.sps_pkg_name | ||
|
|
||
| @property |
There was a problem hiding this comment.
The deprecated_sps_pkg_name property should be decorated with @cached_property instead of @property to match the caching behavior of sps_pkg_name (line 18-20) and the underlying implementation in xml_sps_lib.py where it is also a cached property. This inconsistency will cause the deprecated package name to be recomputed on every access, potentially impacting performance.
| @property | |
| @cached_property |
| from unittest.mock import MagicMock, PropertyMock, patch | ||
| from lxml import etree |
There was a problem hiding this comment.
Unused imports detected. The imports MagicMock, PropertyMock, and patch from unittest.mock, as well as etree from lxml, are not used anywhere in this test file. Consider removing them to keep the imports clean.
| from unittest.mock import MagicMock, PropertyMock, patch | |
| from lxml import etree |
| self.volume, | ||
| self.number and self.number.zfill(2), | ||
| self.deprecated_sps_pkg_name_suppl, | ||
| self.sps_pkg_name_suffix or self.alternative_sps_pkg_name_suffix, |
There was a problem hiding this comment.
The deprecated_sps_pkg_name function is using self.sps_pkg_name_suffix which internally calls the NEW sps_pkg_name_fpage logic. This defeats the purpose of providing backward compatibility. A new property deprecated_sps_pkg_name_suffix should be created that uses deprecated_sps_pkg_name_fpage instead of sps_pkg_name_fpage, and it should be used here. Otherwise, when fpage equals lpage and v2 exists, the deprecated version will incorrectly include the v2 suffix.
| def test_deprecated_sps_pkg_name_fpage_none(self): | ||
| xml_with_pre = self._make_xml(vol="10", num="2", elocation="e123") | ||
| self.assertIsNone(xml_with_pre.deprecated_sps_pkg_name_fpage) | ||
|
|
||
| def test_deprecated_sps_pkg_name_fpage_zero(self): | ||
| xml_with_pre = self._make_xml(vol="10", num="2", fpage="0", lpage="0") | ||
| self.assertIsNone(xml_with_pre.deprecated_sps_pkg_name_fpage) | ||
|
|
||
| def test_deprecated_sps_pkg_name_fpage_simple(self): | ||
| xml_with_pre = self._make_xml(vol="10", num="2", fpage="123", lpage="130") | ||
| self.assertEqual(xml_with_pre.deprecated_sps_pkg_name_fpage, "123") | ||
|
|
||
| def test_deprecated_sps_pkg_name_fpage_with_seq(self): | ||
| xml_with_pre = self._make_xml(vol="10", num="2", fpage="123", fpage_seq="a", lpage="130") | ||
| self.assertEqual(xml_with_pre.deprecated_sps_pkg_name_fpage, "123a") |
There was a problem hiding this comment.
Missing test case for deprecated_sps_pkg_name_fpage when fpage equals lpage and v2 is present. According to the PR description, this is a key difference: the deprecated version should return just the fpage (e.g., "123") while the new version returns fpage with v2 suffix (e.g., "123_00123"). Add a test case similar to test_sps_pkg_name_fpage_same_fpage_lpage_with_v2 but for the deprecated version to verify it returns just "123" without the v2 suffix.
| def test_deprecated_sps_pkg_name_with_suppl(self): | ||
| xml_with_pre = self._make_xml( | ||
| issn_epub="1234-5678", | ||
| acron="abc", | ||
| vol="10", | ||
| num="2", | ||
| suppl="1", | ||
| fpage="100", | ||
| lpage="110", | ||
| ) | ||
| self.assertEqual(xml_with_pre.deprecated_sps_pkg_name, "1234-5678-abc-10-02-1-100") | ||
|
|
||
| def test_deprecated_sps_pkg_name_suppl_zero(self): | ||
| xml_with_pre = self._make_xml( | ||
| issn_epub="1234-5678", | ||
| acron="abc", | ||
| vol="10", | ||
| num="2", | ||
| suppl="0", | ||
| fpage="100", | ||
| lpage="110", | ||
| ) | ||
| self.assertEqual(xml_with_pre.deprecated_sps_pkg_name, "1234-5678-abc-10-02-suppl-100") |
There was a problem hiding this comment.
Missing test case for the complete deprecated_sps_pkg_name with fpage==lpage and v2 scenario. This would ensure the entire deprecated package name is correctly generated without the v2 suffix, verifying the fix for the bug in the implementation where sps_pkg_name_suffix is incorrectly used instead of a deprecated version.
| import unittest | ||
| unittest.main() No newline at end of file |
There was a problem hiding this comment.
Module 'unittest' is imported with both 'import' and 'import from'.
| import unittest | |
| unittest.main() | |
| from unittest import main | |
| main() |
| try: | ||
| if int(fpage) == 0: | ||
| return None | ||
| except (TypeError, ValueError): |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| try: | ||
| if int(suppl) == 0: | ||
| return "suppl" | ||
| except (TypeError, ValueError): |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
Adiciona
deprecated_sps_pkg_namepara manter compatibilidade com versão anterior do nome do pacoteDescrição
Cria a propriedade
deprecated_sps_pkg_namee propriedades auxiliares (deprecated_sps_pkg_name_suppl,deprecated_sps_pkg_name_fpage) para preservar o acesso à lógica anterior de geração do nome do pacote SPS.Motivação
A propriedade
sps_pkg_namefoi modificada com novas regras de formatação:"1"para"s1"fpage == lpagee existev2, adiciona sufixo dos últimos 5 caracteres do v2Essas mudanças podem impactar sistemas que dependem do formato anterior do nome do pacote. Para garantir compatibilidade retroativa e permitir migração gradual, foram criadas as versões
deprecated_*.Mudanças
Testes
Adicionados testes unitários cobrindo:
sps_pkg_name_suppledeprecated_sps_pkg_name_supplsps_pkg_name_fpageedeprecated_sps_pkg_name_fpagesps_pkg_nameedeprecated_sps_pkg_name