Show
Ignore:
Timestamp:
09/24/08 16:16:22 (18 months ago)
Author:
JensDiemer
Message:

another bugfix in verbose error messages...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/tests/utils/unittest_addons.py

    r1771 r1773  
    4747    def __str__(self): 
    4848        try: 
    49             msg = self.args[0] 
     49            raw_msg = self.args[0] 
    5050             
    5151            """ 
    5252            Get the right split_string is not easy. There are three kinds: 
    53             u"foo" != "bar" 
    54             u'foo' != "bar" 
    55             u"foo" != 'bar' 
    56             u'foo' != 'bar' 
     53            "foo" != "bar" 
     54            'foo' != "bar" 
     55            "foo" != 'bar' 
     56            'foo' != 'bar' 
     57            With and without a 'u' ;) 
    5758            """ 
    58             msg = msg.lstrip("u") # u"foobar" -> "foobar" 
     59            msg = raw_msg.lstrip("u") 
     60             
    5961            first_quote = msg[0] 
    60             last_quote = msg[-1] 
    61             split_string = "%s != %s" % (first_quote, last_quote) 
    62             msg = msg.strip(first_quote + last_quote) 
     62            second_quote  = msg[-1] 
     63             
     64            msg = msg.strip("'\"") 
     65             
     66            split_string = "%s != %s" % (first_quote, second_quote) 
    6367 
    64 #            # strip ' out 
    65 #            if msg.startswith("u'"): 
    66 #                msg = msg[2:-1] 
    67 #            else: 
    68 #                msg = msg[1:-1] 
    69 # 
    70 #            if "' != '" in msg: 
    71 #                split_string = "' != '" 
    72 #            elif '" != "' in msg: 
    73 #                split_string = '" != "' 
    74 #            else: 
    75 #                msg = self._format_output(msg) 
    76 #                return "Unknwon error output: %r" % msg 
     68            if split_string not in msg: 
     69                # Second part is unicode? 
     70                split_string = "%s != u%s" % (first_quote, second_quote) 
    7771                 
     72            if split_string not in msg: 
     73                msg = ( 
     74                    "Split error output failed!" 
     75                    " - split string >%r< not in message: %r" 
     76                ) % (split_string, raw_msg) 
     77                raise AssertionError(msg) 
     78                
    7879            try: 
    7980                block1, block2 = msg.split(split_string) 
     
    9394 
    9495            return ( 
    95                 "\n\n---[Output:]---\n%s\n" 
     96                "%r\n\n---[Output:]---\n%s\n" 
    9697                "---[not equal to:]---\n%s" 
    9798                "\n---[diff:]---\n%s" 
    98             ) % (block1, block2, diff) 
     99            ) % (raw_msg, block1, block2, diff) 
    99100        except: 
    100101            etype, value, tb = sys.exc_info()