gordian...@gmail.com於 2015年1月12日星期一 UTC+8下午12時20分46秒寫道: > #!/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. :)
Sorry for asking a dummy problem. I just solve it by changing the string quote from double to single. The problem is that doctest treat double quote string and single quote string as different value! >>> s = "<MYBT@ToggleButton+Button>:" >>> test_kivy_class(s) '<MYBT@ToggleButton+Button>:' < change from double quote to single >>> s = "<MYBT>" >>> test_kivy_class(s) '<MYBT>' < change from double quote to single -- https://mail.python.org/mailman/listinfo/python-list