Package translate :: Package misc :: Module test_autoencode
[hide private]
[frames] | no frames]

Source Code for Module translate.misc.test_autoencode

 1  #!/usr/bin/env python 
 2   
 3  from translate.misc import autoencode 
 4  from py import test 
 5   
6 -class TestAutoencode:
7 type2test = autoencode.autoencode 8
9 - def test_default_encoding(self):
10 """tests that conversion to string uses the encoding attribute""" 11 s = self.type2test(u'unicode string', 'utf-8') 12 assert s.encoding == 'utf-8' 13 assert str(s) == 'unicode string' 14 s = self.type2test(u'\u20ac') 15 assert str(self.type2test(u'\u20ac', 'utf-8')) == '\xe2\x82\xac'
16
17 - def test_uniqueness(self):
18 """tests constructor creates unique objects""" 19 s1 = unicode(u'unicode string') 20 s2 = unicode(u'unicode string') 21 assert s1 == s2 22 assert s1 is s2 23 s1 = self.type2test(u'unicode string', 'utf-8') 24 s2 = self.type2test(u'unicode string', 'ascii') 25 s3 = self.type2test(u'unicode string', 'utf-8') 26 assert s1 == s2 == s3 27 assert s1 is not s2 28 # even though all the attributes are the same, this is a mutable type 29 # so the objects created must be different 30 assert s1 is not s3
31
32 - def test_bad_encoding(self):
33 """tests that we throw an exception if we don't know the encoding""" 34 assert test.raises(ValueError, self.type2test, 'text', 'some-encoding')
35