Skip to content

Commit

Permalink
Merge pull request #4 from slacAWallace/update-regex
Browse files Browse the repository at this point in the history
Updated to v13 of regex tool. Fixed unit tests.
  • Loading branch information
klauer authored Jan 7, 2019
2 parents 101e76e + dc289ed commit ae6e341
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 6 additions & 8 deletions czar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
r"^(?P<functionalTaxon>(?P<functionalClass>\w{2})"
r"(?P<functionalIncrement>\d{1,})"
r"(?P<beamPath>\w{1,}\d{0,}\w{0,})):"
r"(?P<fungibleTaxon>.{3,})?(?(fungibleTaxon):|)"
r"(?P<component>\w{3}):(?P<componentIncrement>\d{2,3}|[X,Y,Z]):"
r"(?P<elementTaxon>[\w|\d]+$)")
r"(?P<fungibleTaxon>.{3,}?):"
r"(?P<component>.{3,}?)"
r"($|:(?P<auxiliaryPV>.{3,})$)")


def describe(Name):
Expand Down Expand Up @@ -37,11 +37,9 @@ def name(NameDict):
Dictionary must include all elements of a name, omitted increments
will be set to 01. <todo>
'''
theName = '{functionalClass}{functionalIncrement}{beamPath}:\
{fungibleTaxon}:{component}:{componentIncrement}:\
{elementTaxon}'.format(
**NameDict
)
theName = '{functionalClass}{functionalIncrement}{beamPath}:' \
'{fungibleTaxon}:{component}:{auxiliaryPV}'.format(
**NameDict)

if re.search(pattern, theName) is None:
raise ValueError
Expand Down
15 changes: 7 additions & 8 deletions tests/test_czar.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import czar
import pytest
expectedKeys = ['functionalTaxon', 'functionalClass', 'functionalIncrement',
'beamPath', 'fungibleTaxon', 'component', 'componentIncrement',
'elementTaxon']
'beamPath', 'fungibleTaxon', 'component',
'auxiliaryPV']

testName = 'EM1K2:GEM:VGC:02:OPN_REQ'
badName = 'XLEM1K2G:GEM:VGC:02:OPN_REQ'
testName = 'EM1K2:GEM:VGC2:OPN_REQ'
badName = 'XLEM1K2G:GEM:VGC2:OPN_REQ'


# Add a name to this list to make sure it stays valid for all time
@pytest.mark.parametrize("Name", [
'EM1K2:GEM:VGC:02:OPN_REQ'
'EM1K2:GEM:VGC2:OPN_REQ'
])
def test_describe_valid_name(Name):
assert czar.describe(Name), Name + " is invalid."
Expand All @@ -31,9 +31,8 @@ def test_one_works_with_the_other():
("functionalIncrement", "1"),
("beamPath", "K2"),
("fungibleTaxon", "GEM"),
("component", "VGC"),
("componentIncrement", "02"),
("elementTaxon", "OPN_REQ")
("component", "VGC2"),
("auxiliaryPV", "OPN_REQ")
])
def test_describe_parse_functionalTaxon(key, thing):
assert czar.describe(testName)[key] == thing

0 comments on commit ae6e341

Please sign in to comment.