File: test_file_jy.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 (52 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (3)
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
"""Misc file tests.

Made for Jython.
"""
from __future__ import with_statement
import os
import unittest
from test import test_support

class FileTestCase(unittest.TestCase):

    def tearDown(self):
        if os.path.exists(test_support.TESTFN):
            os.remove(test_support.TESTFN)

    def test_append(self):
        # http://bugs.jython.org/issue1466
        mode = 'ab'
        fp1 = open(test_support.TESTFN, mode)
        fp1.write('test1\n')
        fp2 = open(test_support.TESTFN, mode)
        fp2.write('test2\n')
        fp1.close()
        fp2.close()
        with open(test_support.TESTFN) as fp:
            self.assertEqual('test1\ntest2\n', fp.read())

    def test_appendplus(self):
        # regression with the test_append fix:
        # http://bugs.jython.org/issue1576
        with open(test_support.TESTFN, 'ab+') as fp:
            fp.write('test1\n')
            fp.seek(0)
            self.assertEqual(fp.read(), 'test1\n')

    def test_issue1825(self):
        testfnu = unicode(test_support.TESTFN)
        try:
            open(testfnu)
        except IOError, e:
            self.assertTrue(isinstance(e.filename, unicode))
            self.assertEqual(e.filename, testfnu)
        else:
            self.assertTrue(False)


def test_main():
    test_support.run_unittest(FileTestCase)


if __name__ == '__main__':
    test_main()