3 from translate
.misc
import autoencode
7 type2test
= autoencode
.autoencode
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'
17 def test_uniqueness(self
):
18 """tests constructor creates unique objects"""
19 s1
= unicode(u
'unicode string')
20 s2
= unicode(u
'unicode string')
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')
28 # even though all the attributes are the same, this is a mutable type
29 # so the objects created must be different
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')