Ticket #5830 task closed fixed

Opened 10 months ago

Last modified 9 months ago

Make twisted/test/test_text pass under Python 3

Reported by: vperic Owned by: vperic
Priority: normal Milestone: Python-3.x
Component: core Keywords: py3k
Cc: thijs Branch: branches/test_text-5830
Author: vperic Launchpad Bug:

Description

As before, to actually make this actually run you need to import unittest from the library, not from trial, and then "python3.2 -m unittest twisted.test.test_text" will run the tests.

The changes:

Replace calls to functions from the string module in favor of string methods (Refs: #4999); don't use the types module in favor of the "isinstance" function - types was changed in Python 3 to not include some base types, like dicts, lists and tuples.

This also required the addition of some tests.

Attachments

test_text.patch Download (5.0 KB) - added by vperic 10 months ago.
First version
test_text.2.patch Download (5.0 KB) - added by vperic 10 months ago.
Second version

Change History

Changed 10 months ago by vperic

First version

1

  Changed 10 months ago by vperic

  • type changed from enhancement to task

2

  Changed 10 months ago by antoine

Changing exact type tests to isinstance() will change semantics: what happens e.g. to a tuple subclass?

3

follow-up: ↓ 4   Changed 10 months ago by vperic

As in, a tuple subclass would be caught now but not before? I guess you are right, but I could argue that the new behaviour is more correct. Right now, subclasses of those types are handled just right any other element, so printed just as a string, which is not what they're supposed to do per the doctest of stringyString; with the new code, they'll also be printed "one element per line".

The function itself isn't used anywhere, so I'm not sure what the original author intended.

Still, if I was to keep the old semantics, how should I fix this? The types module is changed in Python 3.

4

in reply to: ↑ 3   Changed 10 months ago by antoine

Replying to vperic:

Still, if I was to keep the old semantics, how should I fix this?

type(foo) is tuple

5

  Changed 10 months ago by vperic

  • keywords review removed
  • owner set to vperic

D'oh, you're right. Thanks! I'll update the patch to do just that; dropping the review tag for now.

6

  Changed 10 months ago by vperic

  • keywords review added
  • owner vperic deleted

Right, fixed that, thanks antoine! Putting back up for review.

Changed 10 months ago by vperic

Second version

7

  Changed 10 months ago by thijs

  • cc thijs added

Could you create a branch for the patch so we can run it on buildbot. This should rule out any test failures. Maybe once #4999 landed?

8

  Changed 10 months ago by vperic

  • owner set to vperic

Yes, definitely, I'll update this once #4999 is in to contain just the py3k changes (which are minimal, really).

9

  Changed 9 months ago by itamar

  • keywords review removed

#4999 was merged, so this can now be updated.

10

  Changed 9 months ago by vperic

  • branch set to branches/test_text-5830
  • branch_author set to vperic

(In [35184]) Create branch test_text-5830

11

  Changed 9 months ago by vperic

I've ordered a test run on just twisted.test.test_text (as it's the only touched module). After removing the added tests, this is actually a very, very simple patch.  Build results.

12

  Changed 9 months ago by vperic

  • keywords review added
  • owner vperic deleted

Ok, it just occurred to me that no one actually gave this a "+1" so I'll put it up for review formally.

13

  Changed 9 months ago by thijs

  • keywords review removed
  • owner set to vperic

Please merge, thanks.

14

  Changed 9 months ago by vperic

  • status changed from new to closed
  • resolution set to fixed

(In [35186]) Merge test_text-5830: Make t.test.test_text pass under Python 3

Author: vperic Reviewers: antoine, thijs Fixes: #5830

Don't use the types module in favor of the "type(object) is sometype" syntagm - types was changed in Python 3 to not include some base types, like dicts, lists and tuples.

Note: See TracTickets for help on using tickets.