Skip to content

Instantly share code, notes, and snippets.

@ternus
Created October 24, 2013 20:52
Show Gist options
  • Save ternus/7144756 to your computer and use it in GitHub Desktop.
Save ternus/7144756 to your computer and use it in GitHub Desktop.
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