/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1558.15.7 by Aaron Bentley
Add copyright statements
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1558.15.7 by Aaron Bentley
Add copyright statements
16
1558.15.1 by Aaron Bentley
Add text_file function
17
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
18
from ..errors import BinaryFile
19
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
20
    BytesIO,
21
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from . import TestCase, TestCaseInTempDir
23
from ..textfile import text_file, check_text_lines, check_text_path
1558.15.1 by Aaron Bentley
Add text_file function
24
25
26
class TextFile(TestCase):
1558.15.8 by Aaron Bentley
Whitespace fixes
27
1558.15.1 by Aaron Bentley
Add text_file function
28
    def test_text_file(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
29
        s = BytesIO(b'ab' * 2048)
1558.15.1 by Aaron Bentley
Add text_file function
30
        self.assertEqual(text_file(s).read(), s.getvalue())
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
31
        s = BytesIO(b'a' * 1023 + b'\x00')
1558.15.1 by Aaron Bentley
Add text_file function
32
        self.assertRaises(BinaryFile, text_file, s)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
33
        s = BytesIO(b'a' * 1024 + b'\x00')
1558.15.1 by Aaron Bentley
Add text_file function
34
        self.assertEqual(text_file(s).read(), s.getvalue())
35
1558.15.6 by Aaron Bentley
Added more tests
36
    def test_check_text_lines(self):
6973.7.5 by Jelmer Vernooij
s/file/open.
37
        lines = [b'ab' * 2048]
1558.15.6 by Aaron Bentley
Added more tests
38
        check_text_lines(lines)
6973.7.5 by Jelmer Vernooij
s/file/open.
39
        lines = [b'a' * 1023 + b'\x00']
1558.15.6 by Aaron Bentley
Added more tests
40
        self.assertRaises(BinaryFile, check_text_lines, lines)
41
1558.15.8 by Aaron Bentley
Whitespace fixes
42
1558.15.6 by Aaron Bentley
Added more tests
43
class TextPath(TestCaseInTempDir):
1558.15.8 by Aaron Bentley
Whitespace fixes
44
1558.15.6 by Aaron Bentley
Added more tests
45
    def test_text_file(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
46
        with open('boo', 'wb') as f:
47
            f.write(b'ab' * 2048)
1558.15.6 by Aaron Bentley
Added more tests
48
        check_text_path('boo')
7143.15.2 by Jelmer Vernooij
Run autopep8.
49
        with open('boo', 'wb') as f:
50
            f.write(b'a' * 1023 + b'\x00')
1558.15.6 by Aaron Bentley
Added more tests
51
        self.assertRaises(BinaryFile, check_text_path, 'boo')