[Python-Dev] cpython: Cleanup test_builtin

Victor Stinner victor.stinner at gmail.com
Thu Aug 22 13:48:53 CEST 2013


> You forgot self.addCleanup(unlink, TESTFN) (here and in other places).

These functions call write_testfile() which creates the file but also
schedules its removal when the test is done (since my changeset):

    def write_testfile(self):
        # NB the first 4 lines are also used to test input, below
        fp = open(TESTFN, 'w')
        self.addCleanup(unlink, TESTFN)
        ...

Victor


2013/8/22 Serhiy Storchaka <storchaka at gmail.com>:
> 22.08.13 02:59, victor.stinner написав(ла):
>
>> http://hg.python.org/cpython/rev/0a1e1b929665
>> changeset:   85308:0a1e1b929665
>> user:        Victor Stinner <victor.stinner at gmail.com>
>> date:        Thu Aug 22 01:58:12 2013 +0200
>> summary:
>>    Cleanup test_builtin
>>
>> files:
>>    Lib/test/test_builtin.py |  16 ++++------------
>>    1 files changed, 4 insertions(+), 12 deletions(-)
>
> [...]
>
>>       def test_open(self):
>>           self.write_testfile()
>>           fp = open(TESTFN, 'r')
>> -        try:
>> +        with fp:
>>               self.assertEqual(fp.readline(4), '1+1\n')
>>               self.assertEqual(fp.readline(), 'The quick brown fox jumps
>> over the lazy dog.\n')
>>               self.assertEqual(fp.readline(4), 'Dear')
>>               self.assertEqual(fp.readline(100), ' John\n')
>>               self.assertEqual(fp.read(300), 'XXX'*100)
>>               self.assertEqual(fp.read(1000), 'YYY'*100)
>> -        finally:
>> -            fp.close()
>> -            unlink(TESTFN)
>
>
> You forgot self.addCleanup(unlink, TESTFN) (here and in other places).
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com


More information about the Python-Dev mailing list