Commits

Anonymous committed 0c315cf

addressed issue of leading u'' for doctest comparison in looped collection; see http://bitbucket.org/fiji/django-3k/issue/50/leading-u-problem-with-repr-of-looped-collections-in for issue details

  • Participants
  • Parent commits 2a3c0b7

Comments (0)

Files changed (1)

django/test/_doctest.py

         
             if sys.version_info >= (3,):
                  # only set alternate displayhook if Python 3.x or after
+                lines = []
                 def py3_displayhook(value):
                     if not value:
                         # None should not be considered at all
                     s = s.replace("'", '"')
                     expected = expected.replace("'", '"')
                     
+                    # In case of multi-line expected result
+                    lines.append(s)
+                    
                     # let them match
                     if s == expected: # be wary of false positives here
                         # they should be the same, print expected value
                         print >> sys.stdout, example.want.strip()
+                        
+                    # multi-line expected output, doctest uses loop 
+                    elif len(expected.split("\n")) == len(lines):
+                        if "\n".join(lines) == expected:
+                            print >> sys.stdout, example.want.strip()
+                        else:
+                            print >> sys.stdout, repr(value)
+                    elif len(expected.split("\n")) != len(lines):
+                        # we are not done looping yet, do not print anything!
+                        pass
+                          
                     else:
                         print >> sys.stdout, repr(value)