Skip to content

Commit

Permalink
add functionality to check_term
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-troy committed Oct 31, 2024
1 parent 1cda17a commit 844510b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions liiatools/common/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,21 @@ def check_term(filename):
:return: A tern within the string
:raises ValueError: If no term is found
"""
match = re.search(
match_short = re.search(
f"{Term.OCT.name}|{Term.JAN.name}|{Term.MAY.name}",
filename,
re.IGNORECASE,
)
if match:
return Term[match.group(0).upper()].value
if match_short:
return Term[match_short.group(0).upper()].value

match_long = re.search(
f"{Term.OCT.value}|{Term.JAN.value}|{Term.MAY.value}",
filename,
re.IGNORECASE,
)

if match_long:
return match_long.group(0).title()

raise ValueError
3 changes: 2 additions & 1 deletion liiatools/common/reference/_authorities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ data_codes:
Waltham Forest: 'WAL'
Wandsworth: 'WAN'
Westminster: 'WES'
Gloucester City Council: "GCC"
Gloucester City Council: "GCC"
Cheshire West and Chester: "CWC"
4 changes: 4 additions & 0 deletions tests/common/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def test_check_term():
assert check_term(r"jan_16/2015_16/addresses.csv") == Term.JAN.value
assert check_term(r"MAY_16/2015_16/addresses.csv") == Term.MAY.value

assert check_term(r"autumn_15/2015_16/addresses.csv") == Term.OCT.value
assert check_term(r"Spring_16/2015_16/addresses.csv") == Term.JAN.value
assert check_term(r"SUMMER_16/2015_16/addresses.csv") == Term.MAY.value


class TestCheckTerm(unittest.TestCase):
def test_check_term(self):
Expand Down

0 comments on commit 844510b

Please sign in to comment.