Ticket #3598 (closed defect: fixed )

Opened 6 months ago

Last modified 6 months ago

TestCase.flushWarnings shouldn't use source files to implement its "offendingFunctions" feature

Reported by: exarkun Assigned to: exarkun
Type: defect Priority: high
Milestone: Component: trial
Keywords: Cc:
Branch: branches/findlinestarts-3598 Author: exarkun
Launchpad Bug:

Description

Using source files to determine which function a warning was emitted from is unreliable. It fails if:

  1. The source file is missing
  2. The source file is out of date with the bytecode file
  3. It's kind of slow

dis.findlinestarts can provide the necessary information and is now public.

Attachments

Change History

  2009-01-04 00:39:23+00:00 changed by exarkun

  • branch set to branches/findlinestarts-3598
  • branch_author set to exarkun

(In [25781]) Branching to 'findlinestarts-3598'

  2009-01-04 00:41:05+00:00 changed by exarkun

(In [25782]) use dis.findlinestarts instead of inspect.getsourcelines

refs #3598

  2009-01-05 17:58:53+00:00 changed by exarkun

  • keywords set to review
  • owner deleted

Think this is in good shape now.

  2009-01-06 23:45:22+00:00 changed by radix

  • keywords deleted
  • owner set to exarkun

[1] Need to mention copyright of that code copied from Python

[2] in test_renamedSource:

  • a: you should not call the *original* filename "renamedsourcefile", since that is confusing.
  • b: I don't think this comment is correct:

+ # Drop it from memory so we can import it again later

You don't actually need to drop it so you can import it again, since it's going to be imported with the different name, right? Of course, you do need to clean it up, but you can do that at the end.

[3] Please change that function to not use single-letter variables that are used across more than one line.

[4] I don't know whether the following expression has off-by-one errors:

+ if not (first <= w.lineno <= last):

Can you please add tests for all of the edge cases, thank you.

  2009-01-07 15:04:05+00:00 changed by exarkun

(In [25846]) test edge cases for line number stuff

refs #3598

  2009-01-07 15:06:34+00:00 changed by exarkun

(In [25847]) rename single letter variable "w" to something more descriptive

refs #3598

  2009-01-07 15:13:33+00:00 changed by exarkun

(In [25848]) add/adjust comments in new test method to be more descriptive/accurate

refs #3598

  2009-01-07 15:29:51+00:00 changed by exarkun

(In [25849]) document copyright holder and license of _findlinestarts

refs #3598

  2009-01-07 15:39:55+00:00 changed by exarkun

  • keywords set to review
  • owner deleted

  2009-01-07 23:33:24+00:00 changed by exarkun

This is a small part of #3554.

  2009-01-15 09:42:13+00:00 changed by mwh

  • keywords deleted
  • owner set to exarkun

I think it looks fine. I have two small comments.

1. Saying "inspect.getabsfile(aFunction) returns bad results sometimes." is a bit useless. What are bad results? When does it generate them?

2. I know you apologise for it, but 'renamedsourcefile.py' is never actually renamed. I think something plain 'module.py' would be clearer.

These are minor enough that I don't want to review this again :) Please fix and land.

  2009-01-16 13:29:34+00:00 changed by exarkun

(In [26041]) explain the getabsfile problem in more detail; change the name of the module used in the renamed-source-file-test to be more clear

refs #3598

  2009-01-16 14:05:55+00:00 changed by exarkun

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

(In [26043]) Merge findlinestarts-3598

Author: exarkun Reviewer: radix, mwhudson Fixes: #3598

Change the implementation of twisted.trial.unittest.TestCase.flushWarnings so that it works properly when a warning is emitted from a module which is defined by a source file which has been renamed since it was compiled. Previously, the rename would cause file names to disagree in certain places and prevent warnings emitted from code in a renamed file from being flushed.

Note: See TracTickets for help on using tickets.