Opened 2 years ago

Closed 21 months ago

#5811 enhancement closed wontfix (wontfix)

replace usage of file with FilePath in twisted.test

Reported by: thijs Owned by: thijs
Priority: low Milestone: Python-3.x
Component: core Keywords:
Cc: thijs Branch:
Author: Launchpad Bug:

Description (last modified by thijs)

The usage of file should be replaced with FilePath in twisted.test and it's tests for Python 3 compatibility.

twisted/test/test_sob.py:116:        f = file(filename, 'w')
twisted/test/test_sob.py:134:        f = file(filename, 'w')
twisted/test/test_sob.py:152:        f = file(filename, 'w')
twisted/test/test_ftp.py:632:            fObj = file(os.path.join(self.directory, '%d.txt' % (size,)), 'wb')
twisted/test/test_fdesc.py:218:        fObj = file(self.mktemp(), 'w')
twisted/test/test_fdesc.py:230:        fObj = file(self.mktemp(), 'w')
twisted/test/test_threads.py:376:        progfile = file(progname, 'w')
twisted/test/test_process.py:2382:            f = file(name, "w")
twisted/test/test_pb.py:829:        self.pager = util.FilePager(collector, file(self.filename),
twisted/test/test_pb.py:845:        fd = file(self.filename, 'w')
twisted/test/test_pb.py:890:        fd = file(filenameEmpty, 'w')
twisted/test/test_twistd.py:358:        f = file(self.tapfile, 'wb')
twisted/test/test_twistd.py:682:        fObj = file(pidfile)
twisted/test/test_twistd.py:696:        fObj = file(pidfile)
twisted/test/test_twistd.py:793:        file(pidfile, "w").close()
twisted/test/test_twistd.py:920:        data = file(config["profile"]).read()
twisted/test/test_twistd.py:1024:        data = file(config["profile"]).read()
twisted/test/test_twistd.py:1109:        data = file(config["profile"]).read()
twisted/test/test_iutils.py:34:        scriptFile = file(script, 'wt')
twisted/test/test_rebuild.py:48:        file(os.path.join(self.fakelibPath, '__init__.py'), 'w').close()
twisted/test/test_stdio.py:140:            for line in file(errorLogFile):
twisted/test/test_stdio.py:264:        junkFile = file(junkPath, 'w')
twisted/test/test_stdio.py:312:            self.assertEqual(p.data[1], file(junkPath).read())
twisted/test/test_strcred.py:531:        file(self.filename, 'w').write('admin:asdf\nalice:foo\n')
twisted/test/test_ssl.py:219:        fObj = file(fName, 'w')
twisted/test/test_logfile.py:205:        f = file(self.path, "w")

Attachments (2)

test-open-5811.patch (12.5 KB) - added by thijs 2 years ago.
test-open-5811-2.patch (30.4 KB) - added by thijs 2 years ago.

Download all attachments as: .zip

Change History (11)

Changed 2 years ago by thijs

comment:1 Changed 2 years ago by thijs

  • Keywords review added

comment:2 follow-up: Changed 2 years ago by antoine

  • Keywords review removed
  • Owner set to thijs

Patch looks fine to me. You might also want to replace xrange(1024) with range(1024), and 0707 with 0o707 (Python 3-compatible octal notation).

comment:3 in reply to: ↑ 2 Changed 2 years ago by thijs

Replying to antoine:

Patch looks fine to me. You might also want to replace xrange(1024) with range(1024), and 0707 with 0o707 (Python 3-compatible octal notation).

Feel free to open a separate ticket(s) for that type of change, thanks.

comment:4 Changed 2 years ago by thijs

  • Status changed from new to assigned

comment:5 Changed 2 years ago by thijs

  • Summary changed from replace usage of file with open in twisted.test to replace usage of file with FilePath in twisted.test

comment:6 Changed 2 years ago by thijs

  • Description modified (diff)

Changed 2 years ago by thijs

comment:7 Changed 2 years ago by thijs

  • Keywords review added
  • Owner thijs deleted
  • Status changed from assigned to new

Attached patch uses FilePath instead; meaning this should never happen again. ;)

comment:8 Changed 2 years ago by cyli

  • Keywords review removed
  • Owner set to thijs

Hi thijs! Thanks for working on this.

  1. test_fdesc has change so that it no longer uses file - instead it uses open, so the patch is probably out of date by now
  2. There seem to be several other usages of file that were missed?
stdio_test_consumer.py
26:        d = basic.FileSender().beginFileTransfer(file(self.junkPath), self.transport)

stdio_test_halfclose.py
61:    log.startLogging(file(sys.argv[2], 'w'))

stdio_test_loseconn.py
43:    log.startLogging(file(sys.argv[2], 'w'))

test_newcred.py
184:        f = file(dbfile, 'w')
196:        f = file(dbfile, 'w')
207:        f = file(dbfile, 'w')
220:        f = file(dbfile, 'w')
246:        f = file(dbfile, 'w')
408:            fObj = file(fn, 'w')
415:            fObj = file(fn, 'w')
422:            fObj = file(fn, 'w')

test_ssl.py
288:        cert = ssl.PrivateCertificate.loadPEM(file(certPath).read())

comment:9 Changed 21 months ago by therve

  • Resolution set to wontfix
  • Status changed from new to closed

Following Plan/Python3 I'm closing this ticket. Sorry for the inconvenience.

Note: See TracTickets for help on using tickets.