File: test_long_int_args.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (61 lines) | stat: -rw-r--r-- 1,630 bytes parent folder | download | duplicates (8)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Ensure longs passed to int arguments are handled correctly

Made for Jython.
"""
import array
import cStringIO
import tempfile
from test import test_support
import unittest
import StringIO

class LongIntArgsTestCase(unittest.TestCase):

    def test_array(self):
        a = array.array('c', 'jython')
        assert a.pop(0L) == 'j'

    def test_file(self):
        test_file = tempfile.TemporaryFile()
        try:
            self._test_file(test_file)
        finally:
            test_file.close()

    def test_StringIO(self):
        self._test_file(StringIO.StringIO())

    def test_cStringIO(self):
        self._test_file(cStringIO.StringIO())

    def test_str(self):
        self._test_basestring(str)

    def test_unicode(self):
        self._test_basestring(unicode)

    def _test_basestring(self, class_):
        s = class_('hello from jython')
        l = long(len(s))
        assert s.count('o', 0L, l) == 3
        assert s.endswith('n', 0L, l) == True
        assert s.expandtabs(1L) == s
        assert s.find('h', 0L, l) == 0
        assert s.index('h', 0L, l) == 0
        assert s.rfind('h', 0L, l) == 14
        assert s.rindex('h', 0L, l) == 14
        assert s.split(' ', 1L) == ['hello', 'from jython']
        assert s.startswith('jython', 11L)

    def _test_file(self, test_file):
        test_file.write('jython')
        test_file.seek(0L)
        assert test_file.read(1L) == 'j'
        assert test_file.readline(2L) == 'yt'
        assert test_file.readlines(3L) == ['hon']

def test_main():
    test_support.run_unittest(LongIntArgsTestCase)

if __name__ == '__main__':
    test_main()