add 'transcode_file' helper method
This commit is contained in:
parent
ce6fed5947
commit
15c06bab11
@ -114,6 +114,17 @@ class TC_example(TestCase):
|
|||||||
with self.cmd("true") as c:
|
with self.cmd("true") as c:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_09_encoding(self):
|
||||||
|
self.create_file("abc.txt", [
|
||||||
|
'detta är abc.txt',
|
||||||
|
'räksmörgås',
|
||||||
|
' aaa',
|
||||||
|
' bbb',
|
||||||
|
' ccc',
|
||||||
|
' ddd',
|
||||||
|
], encoding='utf-16')
|
||||||
|
self.transcode_file('abc.txt', 'xxx.txt', src_encoding='utf-16', tgt_encoding='utf-32')
|
||||||
|
|
||||||
def xxx_test_bool(self):
|
def xxx_test_bool(self):
|
||||||
with self.cmd("true") as c:
|
with self.cmd("true") as c:
|
||||||
c.exit_status(0)
|
c.exit_status(0)
|
||||||
|
@ -357,6 +357,17 @@ class TestCase:
|
|||||||
else:
|
else:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
def transcode_file(self, src_file, tgt_file=None, src_encoding='utf-8', tgt_encoding='utf-8'):
|
||||||
|
if tgt_file:
|
||||||
|
mkdir_for(tgt_file)
|
||||||
|
else:
|
||||||
|
tgt_file = src_file
|
||||||
|
|
||||||
|
with open(src_file, "r", encoding=src_encoding) as f:
|
||||||
|
data = f.read()
|
||||||
|
with open(tgt_file, "w", encoding=tgt_encoding) as f:
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
def cmd(self, cmdline):
|
def cmd(self, cmdline):
|
||||||
tmpdir = self.__tmpdir
|
tmpdir = self.__tmpdir
|
||||||
before = tmpdir.snapshot()
|
before = tmpdir.snapshot()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user