File: test_file_jy.py

package info (click to toggle)
jython 2.5.2-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 72,424 kB
  • sloc: python: 375,154; java: 216,094; xml: 1,413; sh: 330; ansic: 126; perl: 122; makefile: 98
file content (42 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download
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
"""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_main():
    test_support.run_unittest(FileTestCase)


if __name__ == '__main__':
    test_main()