Skip to content

Commit

Permalink
Avoid returning windows-style line returns (#1370)
Browse files Browse the repository at this point in the history
There are few examples of data that have windows-style line returns.
This isn't a full fix - the best way would be to update all of the
sources to work on this, but is an intermediate that makes sure that the
getter methods on the Resource class at least process them out.
cthoyt authored Jan 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2e7bcab commit d1d8c00
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/bioregistry/schema/struct.py
Original file line number Diff line number Diff line change
@@ -713,9 +713,10 @@ def _get_prefix_key_str(self, key: str, metaprefixes: Union[str, Sequence[str]])
rv = self.get_prefix_key(key, metaprefixes)
if rv is None:
return None
if isinstance(rv, str):
return rv
raise TypeError
if not isinstance(rv, str):
raise TypeError
rv = rv.replace("\r\n", "\n")
return rv

def _get_prefix_key_bool(
self, key: str, metaprefixes: Union[str, Sequence[str]]
14 changes: 14 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -73,6 +73,19 @@ def test_lint(self):
""",
)

def test_line_returns(self) -> None:
"""Test that there are no Windows-style line returns in curated data."""
for prefix, resource in self.registry.items():
with self.subTest(prefix=prefix):
resource_dict = resource.model_dump()
for key, value in resource_dict.items():
if isinstance(value, str):
self.assertNotIn(
"\\r",
value,
msg=f"Windows-style line return detected in {key} field of {prefix}",
)

def test_prefixes(self):
"""Check prefixes aren't malformed."""
for prefix, resource in self.registry.items():
@@ -159,6 +172,7 @@ def test_has_description(self):
with self.subTest(prefix=prefix, name=bioregistry.get_name(prefix)):
desc = bioregistry.get_description(prefix)
self.assertIsNotNone(desc)
self.assertNotIn("\r", desc)

def test_has_homepage(self):
"""Test that all non-deprecated entries have a homepage."""

0 comments on commit d1d8c00

Please sign in to comment.