Initial commit and release of doi2dataset
This commit is contained in:
commit
9be53fd2fc
23 changed files with 2482 additions and 0 deletions
50
tests/test_doi2dataset.py
Normal file
50
tests/test_doi2dataset.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from doi2dataset import NameProcessor, Phase, sanitize_filename, validate_email_address
|
||||
|
||||
|
||||
def test_phase_check_year():
|
||||
"""Test that check_year correctly determines if a year is within the phase boundaries."""
|
||||
phase = Phase("TestPhase", 2000, 2010)
|
||||
# Within boundaries
|
||||
assert phase.check_year(2005) is True
|
||||
# Outside boundaries
|
||||
assert phase.check_year(1999) is False
|
||||
assert phase.check_year(2011) is False
|
||||
# Boundary cases
|
||||
assert phase.check_year(2000) is True
|
||||
assert phase.check_year(2010) is True
|
||||
|
||||
def test_sanitize_filename():
|
||||
"""Test the sanitize_filename function to convert DOI to a valid filename."""
|
||||
doi = "10.1234/abc.def"
|
||||
expected = "10_1234_abc_def"
|
||||
result = sanitize_filename(doi)
|
||||
assert result == expected
|
||||
|
||||
def test_split_name_with_comma():
|
||||
"""Test splitting a full name that contains a comma."""
|
||||
full_name = "Doe, John"
|
||||
given, family = NameProcessor.split_name(full_name)
|
||||
assert given == "John"
|
||||
assert family == "Doe"
|
||||
|
||||
def test_split_name_without_comma():
|
||||
"""Test splitting a full name that does not contain a comma."""
|
||||
full_name = "John Doe"
|
||||
given, family = NameProcessor.split_name(full_name)
|
||||
assert given == "John"
|
||||
assert family == "Doe"
|
||||
|
||||
def test_validate_email_address_valid():
|
||||
"""Test that a valid email address is correctly recognized."""
|
||||
valid_email = "john.doe@iana.org"
|
||||
assert validate_email_address(valid_email) is True
|
||||
|
||||
def test_validate_email_address_invalid():
|
||||
"""Test that an invalid email address is correctly rejected."""
|
||||
invalid_email = "john.doe@invalid_domain"
|
||||
assert validate_email_address(invalid_email) is False
|
Loading…
Add table
Add a link
Reference in a new issue