This repository has been archived by the owner on Feb 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
} | ||
|
||
from lazy_attachment_doc import * | ||
from dates import * | ||
from dates import * | ||
from xpath import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.test import TestCase | ||
from ..xpath import dot_interpolate | ||
|
||
|
||
class DotInterpolateTest(TestCase): | ||
|
||
def testRegex(self): | ||
replacement = "@case_id stuff" | ||
cases = [ | ||
('./lmp < 570.5', '%s/lmp < 570.5'), | ||
('stuff ./lmp < 570.', 'stuff %s/lmp < 570.'), | ||
('.53 < hello.', '.53 < hello%s'), | ||
] | ||
for case in cases: | ||
self.assertEqual( | ||
dot_interpolate(replacement, case[0]), | ||
case[1] % replacement | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import re | ||
|
||
|
||
def dot_interpolate(xpath, context): | ||
""" | ||
Replaces non-decimal dots in `context` with `xpath` | ||
""" | ||
pattern = r'(\D|^)\.(\D|$)' | ||
repl = '\g<1>%s\g<2>' % xpath | ||
return re.sub(pattern, repl, context) |