blob: 1e6d1e5d0d452671ca9c5fb3b6eed8ab65e00b0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# TODO: deprecated, remove in 0.9.0
import pytest
from snakeoil import stringio
class readonly_mixin:
encoding = None
kls = None
def convert_data(self, data):
if self.encoding is None:
return data
return data.encode(self.encoding)
def unconvert_data(self, data):
if self.encoding is None:
return data
return data.decode(self.encoding)
def test_nonwritable(self):
convert = self.convert_data
obj = self.kls(convert("adsf"))
with pytest.raises(TypeError):
obj.write(convert("bow ties"))
with pytest.raises(TypeError):
obj.writelines(convert("are cool"), convert(" so says the doctor"))
with pytest.raises(TypeError):
obj.truncate()
class Test_text_readonly(readonly_mixin):
kls = stringio.text_readonly
class Test_bytes_readonly(readonly_mixin):
kls = stringio.bytes_readonly
encoding = "utf8"
|