Skip to content

Commit

Permalink
refactor: rename is_uri function for accuracy
Browse files Browse the repository at this point in the history
Rename the `is_uri` function to `is_url` for accuracy, as the function
specifically checks for URLs, not URIs.
  • Loading branch information
clnsmth authored Sep 30, 2024
1 parent 8c2f8dc commit ded2748
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/spinneret/shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from urllib.parse import urljoin
from lxml import etree
from spinneret.utilities import is_uri
from spinneret.utilities import is_url


def convert_userid_to_url(eml: etree.ElementTree) -> etree.ElementTree:
Expand All @@ -20,11 +20,11 @@ def convert_userid_to_url(eml: etree.ElementTree) -> etree.ElementTree:

# If the directory isn't a URL, then there it is not possible to
# convert the value to a URL so skip this element
if not is_uri(directory):
if not is_url(directory):
continue

# If the value is not a URL, then convert it to a URL
if not is_uri(value):
if not is_url(value):
new_value = urljoin(directory, value)
element.text = new_value

Expand Down
6 changes: 3 additions & 3 deletions src/spinneret/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def delete_empty_tags(xml: etree._ElementTree) -> etree._ElementTree:
return xml


def is_uri(text: str) -> bool:
def is_url(text: str) -> bool:
"""
:param text: The string to be checked.
:returns: True if the string is likely a URI, False otherwise.
:note: A string is considered a URI if it has scheme and network
:returns: True if the string is likely a URL, False otherwise.
:note: A string is considered a URL if it has scheme and network
location values.
"""
res = urlparse(text)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from lxml import etree
from spinneret import datasets
from spinneret.utilities import delete_empty_tags, is_uri
from spinneret.utilities import delete_empty_tags, is_url


def test_delete_empty_tags():
Expand All @@ -26,6 +26,6 @@ def test_delete_empty_tags():


def test_is_uri():
"""Test that a string is a URI or not"""
assert is_uri("http://purl.dataone.org/odo/ECSO_00001203") is True
assert is_uri("A free text description.") is False
"""Test that a string is a URL or not"""
assert is_url("http://purl.dataone.org/odo/ECSO_00001203") is True
assert is_url("A free text description.") is False

0 comments on commit ded2748

Please sign in to comment.