annoying doctest problem

gordianknot1981 at gmail.com gordianknot1981 at gmail.com
Sun Jan 11 23:30:44 EST 2015


gordian... at 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 at ToggleButton+Button>:"
>     >>> test_kivy_class(s)
>     "<MYBT at 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 at ToggleButton+Button>:"
> Got:
>     '<MYBT at 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 at ToggleButton+Button>:"
    >>> test_kivy_class(s)
    '<MYBT at ToggleButton+Button>:'   < change from double quote to single
    >>> s = "<MYBT>"             
    >>> test_kivy_class(s)
    '<MYBT>'                        < change from double quote to single







More information about the Python-list mailing list