Created
October 24, 2013 20:52
-
-
Save ternus/7144756 to your computer and use it in GitHub Desktop.
Data for working on http://stackoverflow.com/questions/19576122/python-differences-when-splitting-with-regex-script-vs-tests?noredirect=1#19576122
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
cternus@astarael ~/foo> cat errorregex.py 2 | |
import re | |
class ErrorRegex(): | |
def __init__(self): | |
self.regex = re.compile(r"[^\\]\{}".format("|")) | |
def split(self,line): | |
line = line.replace("\n","") | |
print line | |
splitted = self.regex.split(line) | |
print splitted | |
return splitted | |
if __name__ == "__main__": | |
text = r"aa|bb|d\|d" | |
er = ErrorRegex() | |
er.split(text) | |
cternus@astarael ~/foo> cat foo_test.py | |
import unittest | |
import errorregex | |
class TestErrorRegex(unittest.TestCase): | |
def test_default_arguments(self): | |
expected = ["aa","bb","d\|d"] | |
input_ = r"aa|bb|d\|d" | |
er = errorregex.ErrorRegex() | |
actual = er.split(input_) | |
self.assertEqual(expected, actual) | |
if __name__ == '__main__': | |
unittest.main() | |
cternus@astarael ~/foo> python --version | |
Python 2.7.5 | |
cternus@astarael ~/foo> python foo_test.py | |
aa|bb|d\|d | |
['a', 'b', 'd\\|d'] | |
F | |
====================================================================== | |
FAIL: test_default_arguments (__main__.TestErrorRegex) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "foo_test.py", line 11, in test_default_arguments | |
self.assertEqual(expected, actual) | |
AssertionError: Lists differ: ['aa', 'bb', 'd\\|d'] != ['a', 'b', 'd\\|d'] | |
First differing element 0: | |
aa | |
a | |
- ['aa', 'bb', 'd\\|d'] | |
? - - | |
+ ['a', 'b', 'd\\|d'] | |
---------------------------------------------------------------------- | |
Ran 1 test in 0.001s | |
FAILED (failures=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment