1. fiji
  2. django-3k
  3. Issues
Issue #57 resolved

Problem with leading u' in conjunction with new sorted dict in modeltests.aggregation

Johan Harjono
created an issue

{{{

!python

File "/home/johan/workspace/fiji/build/tests/modeltests/aggregation/models.py", line ?, in modeltests.aggregation.models.test.API_TESTS Failed example: sorted([(p.name, p.bookpricesum) for p in publishers]) Expected: [(u'Apress', Decimal("59.69")), (u"Jonno's House of Books", None), (u'Morgan Kaufmann', Decimal("75.00")), (u'Prentice Hall', Decimal("112.49")), (u'Sams', Decimal("23.09"))] Got: [('Apress', Decimal('59.69')), ("Jonno's House of Books", None), ('Morgan Kaufmann', Decimal('75.00')), ('Prentice Hall', Decimal('112.49')), ('Sams', Decimal('23.09'))] }}}

Comments (3)

  1. Johan Harjono reporter
    def py3_displayhook(value):
        if not value:
            # None should not be considered at all
            return original_displayhook(value)
        
        # Collect the repr output in one variable
        s = repr(value)
        # Strip b"" and u"" prefixes from the repr and expected output
        # TODO: better way of stripping the prefixes?
        expected = example.want
        expected = expected.strip() # be wary of newlines
        s = s.replace("u", "")
        s = s.replace("b", "")
        expected = expected.replace("u", "")
        expected = expected.replace("b", "")
        
        #############################################
        # Note what is SINGLE QUOTE and what is DOUBLE QUOTE
        #
        # s == str: [('Apress', Decimal('59.69')), ("Jonno's Hose of Books", None), ('Morgan Kafmann', Decimal('75.00')), ('Prentice Hall', Decimal('112.49')), ('Sams', Decimal('23.09'))]
        #
        # expected == str: [('Apress', Decimal("59.69")), ("Jonno's Hose of Books", None), ('Morgan Kafmann', Decimal("75.00")), ('Prentice Hall', Decimal("112.49")), ('Sams', Decimal("23.09"))]
        #############################################
        
        
        # let them match
        if s == expected: # be wary of false positives here
            # they should be the same, print expected value
            print(example.want.strip(), file=sys.stdout)
        else:
            print(repr(value), file=sys.stdout)
            
    

    Notice why it failed? the string that we got as a result use SINGLE QUOTES in its repr, whereas the doctest expects the same thing except with DOUBLE QUOTES, rather bizarre

  2. Log in to comment