#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
kivy_class_ptn = re.compile(r"<\b[\w_.\@\+]+>:?")
def test_kivy_class(s):
"""
>>> s = "<MYBT@ToggleButton+Button>:"
>>> test_kivy_class(s)
"<MYBT@ToggleButton+Button>:"
>>> s = "<MYBT>"
>>> test_kivy_class(s)
"<MYBT>"
"""
ret = re.search(kivy_class_ptn, s)
if ret: return ret.group()
else: return ''
if __name__ == "__main__":
import doctest
doctest.testmod()
output:
**********************************************************************
File
"F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
line 19, in __main__.test_kivy_class
Failed example:
test_kivy_class(s)
Expected:
"<MYBT@ToggleButton+Button>:"
Got:
'<MYBT@ToggleButton+Button>:'
**********************************************************************
File
"F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
line 22, in __main__.test_kivy_class
Failed example:
test_kivy_class(s)
Expected:
"<MYBT>"
Got:
'<MYBT>'
**********************************************************************
1 items had failures:
2 of 8 in __main__.test_kivy_class
***Test Failed*** 2 failures.
It failed with an unknown reason that evaluate two expected equal value but got
an unexpected result! I'm struggling with this problem for a long time. Did I
did something wrong? And how do I to fix it?
any help is appreciated. :)
--
https://mail.python.org/mailman/listinfo/python-list