Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and simplify org name regex #60

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iatirulesets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_rule(context_xpath, element, rule, case):

def test_ruleset_verbose(ruleset, tree):
for context_xpath, rules in ruleset.items():
for element in tree.findall(context_xpath):
for element in tree.xpath(context_xpath):
for rule in rules:
cases = rules[rule]['cases']
for case in cases:
Expand Down
4 changes: 4 additions & 0 deletions meta_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ test regex_matches regex_bad False
test regex_no_matches regex_bad True
test regex_no_matches regex_good False

test regex_org_name org_name_good True
test regex_org_name org_name_bad False
test regex_org_name org_name_not_relevant True

test starts_with identifiers True
test starts_with identifiers_bad False

Expand Down
8 changes: 8 additions & 0 deletions meta_tests/org_name_bad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<iati-activities><iati-activity>
<transaction>
<provider-org>
<narrative>
</narrative>
</provider-org>
</transaction>
</iati-activity></iati-activities>
9 changes: 9 additions & 0 deletions meta_tests/org_name_good.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<iati-activities><iati-activity>
<transaction>
<provider-org>
<narrative>
provider org
</narrative>
</provider-org>
</transaction>
</iati-activity></iati-activities>
6 changes: 6 additions & 0 deletions meta_tests/org_name_not_relevant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<iati-activities><iati-activity>
<transaction>
<provider-org ref="abcd">
</provider-org>
</transaction>
</iati-activity></iati-activities>
10 changes: 10 additions & 0 deletions meta_tests/regex_org_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"//transaction/provider-org | //transaction/receiver-org": {
"regex_matches": {
"cases": [
{ "regex": "\\S",
"paths": [ "narrative" ], "condition": "count(@ref)=0" }
]
}
}
}
4 changes: 2 additions & 2 deletions rulesets/standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"//planned-disbursement/provider-org | //planned-disbursement/receiver-org | //transaction/provider-org | //transaction/receiver-org | //recipient-org-budget/recipient-org": {
"regex_matches": {
"cases": [
{ "regex": "^(?!\s*$).+",
"paths": [ "narrative" ], "condition": "count(@ref)==1" }
{ "regex": "\\S",
"paths": [ "narrative" ], "condition": "count(@ref)=0" }
]
}
},
Expand Down