def test_mutter_never_fails(self):
# Even if the decode/encode stage fails, mutter should not
# raise an exception
# This test checks that mutter doesn't fail; the current behaviour
# is that it doesn't fail *and writes non-utf8*. mutter(u'Writing a greek mu (\xb5) works in a unicode string')
mutter('But fails in an ascii string \xb5')
mutter('and in an ascii argument: %s', '\xb5')
log = self.get_log() self.assertContainsRe(log, 'Writing a greek mu') self.assertContainsRe(log, "But fails in an ascii string")
# However, the log content object does unicode replacement on reading
# to let it get unicode back where good data has been written. So we
# have to do a replaceent here as well. self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8', 'replace'))
So, this test is passing in the way the comment describes: mutter
doesn't actually fail, but we're no longer writing what we expected
to.
Looking at what got written, it's consistent with the currently
documented behaviour: lines sent as unicode get written as utf8 and
lines sent as byte strings are sent through as such (therefore the
file's then not valid utf8.) I think this is still reasonable
behaviour.
(Pdb) p log
'0.232 Writing a greek mu (\xc2\xb5) works in a unicode string\n0.232
But fails in an ascii string \xb5\n0.232 and in an ascii argument:
\xb5\n'
The main change we'd need then, is that when looking at the result, we
should just search for a non-utf8 string.
def test_mutter_ never_fails( self):
mutter( u'Writing a greek mu (\xb5) works in a unicode string')
self.assertCon tainsRe( log, 'Writing a greek mu')
self.assertCon tainsRe( log, "But fails in an ascii string")
self.assertCon tainsRe( log, "ascii argument: \xb5".decode( 'utf8',
'replace' ))
# Even if the decode/encode stage fails, mutter should not
# raise an exception
# This test checks that mutter doesn't fail; the current behaviour
# is that it doesn't fail *and writes non-utf8*.
mutter('But fails in an ascii string \xb5')
mutter('and in an ascii argument: %s', '\xb5')
log = self.get_log()
# However, the log content object does unicode replacement on reading
# to let it get unicode back where good data has been written. So we
# have to do a replaceent here as well.
So, this test is passing in the way the comment describes: mutter
doesn't actually fail, but we're no longer writing what we expected
to.
Looking at what got written, it's consistent with the currently
documented behaviour: lines sent as unicode get written as utf8 and
lines sent as byte strings are sent through as such (therefore the
file's then not valid utf8.) I think this is still reasonable
behaviour.
(Pdb) p log
'0.232 Writing a greek mu (\xc2\xb5) works in a unicode string\n0.232
But fails in an ascii string \xb5\n0.232 and in an ascii argument:
\xb5\n'
The main change we'd need then, is that when looking at the result, we
should just search for a non-utf8 string.