Skip to content

gh-75117: IDLE - add script for running coverage on tests #22694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

taleinat
Copy link
Contributor

@taleinat taleinat commented Oct 14, 2020

This adds a cross-platform script for generating coverage info for any single IDLE module or for all of IDLE.

The script uses a dedicated venv in Lib/idlelib/test_idle/coverage_venv/, creating it if not found. The coverage package is installed into this venv.

The script also writes a temporary .coveragerc file to ignore irrelevant code. If an existing .coveragerc exists, it is temporarily overwritten.

This is heavily based on @terryjreedy's instructions in Lib/idlelib/test_idle/README, adapted to be cross-platform and hopefully robust in terms of where it is run from and where it leaves files lying around.

This has currently only been tested on Ubuntu 20.04, and should be tested on macOS and Windows.

@E-Paine
Copy link
Contributor

E-Paine commented Oct 14, 2020

I haven't looked properly at it yet, but:

  1. You have trailing whitespace in the run_coverage file
  2. Is it worth modifying test_idle/README.txt for the new script?

@taleinat
Copy link
Contributor Author

  1. You have whitespace in the run_coverage file

Where? Could you leave a specific comment on the relevant lines?

  1. Is it worth modifying test_idle/README.txt for the new script?

Yes, if we agree that this is the way to go, and on some details such as the file name and location.

@taleinat
Copy link
Contributor Author

@E-Paine, many thanks for the review and great comments! 🙏

@taleinat
Copy link
Contributor Author

@terryjreedy, this is now definitely ready for your review :)

@terryjreedy
Copy link
Member

I was looking for something to add to, not replace, a revised version of what I already wrote. So I probably will want this patch to leave README alone so I can deal with it in a followup PR. But I will defer that until we finish the sidebar patch.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 17, 2020
@erlend-aasland
Copy link
Contributor

Looks good after first read-through. Should mention that this only works with in-tree builds.

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jul 30, 2022
@erlend-aasland
Copy link
Contributor

erlend-aasland commented Aug 3, 2022

This has currently only been tested on Ubuntu 20.04, and should be tested on macOS and Windows.

Tested on1:

  • macOS 12.2.12: ✔️
  • Windows 103: ✔️

Footnotes

  1. Rebased onto main

  2. All but the implicit open-in-browser work swell

  3. open-in-browser needs absolute path; else ok

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Aug 3, 2022

(Updating branch to trigger the new CLA check)

@taleinat
Copy link
Contributor Author

taleinat commented Aug 3, 2022

Thanks for the review @erlend-aasland!

Feel free to remove the parts that open the report in a browser, and instead just print the path to the HTML file.

We should likely get @terryjreedy's blessing before merging this, though.

(Something is very wrong with the CLA bot if it doesn't know that I've signed the CLA...)

@erlend-aasland
Copy link
Contributor

Feel free to remove the parts that open the report in a browser, and instead just print the path to the HTML file.

Since webbrowser seems to be broken, or at least problematic, on macOS, the most consistent thing to do is just to remove that functionality. I can update the PR.

(Something is very wrong with the CLA bot if it doesn't know that I've signed the CLA...)

@ambv ☝🏻

@ambv
Copy link
Contributor

ambv commented Aug 3, 2022

@taleinat sorry for the mishap. You used to use taleinat+python@gmail.com, now you started using simply taleinat@gmail.com. The CLA bot is dumb at the moment about + and .. There's an open issue about it, I'll address this today and use your case as a test.

@erlend-aasland
Copy link
Contributor

Thanks, Łukasz!

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think coveragerc should be extracted to a file first. I can do it easier since I can just copy my current file.

(There were several before modules were renamed, now only one is left.)
To get a coverage report for a specific module's tests, run:

python Lib/idlelib/idle_test/run_coverage.py <module_name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd ..
cover tooltip

shows me the htmlcov/index.html in about a second, faster than I can type the above. How long does the above run with tooltip?

Comment on lines +194 to +195
To get a coverage report for IDLE's entire test suite, run the
above command with "all" instead of a module name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which of two possible meanings of 'all' is used?

  1. Run each test_x separately and report the coverage for each module the same as if only that test file were run.
  2. Run all tests together and report the coverage for each module that result from running all tests (as well as the collective coverage).
    I believe using coverage option -L gives me the second.

To get a coverage report for IDLE's entire test suite, run the
above command with "all" instead of a module name.

Note: this does not work with out-of-tree builds yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean installed python or something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds testing for the IDLE test suite in the source directory. I'm one of those folks who like to keep my git clone clean, so I use a build directory outside of the repo directory (AKA an out-of-tree build).

$ cd cpython.git
$ git clean -fdx
$ mkdir ../build
$ cd ../build
$ ../cpython.git/configure && make
$ ./python.exe ../cpython.git/Lib/idlelib/idle_test/run_coverage.py  # <= will not work
$ cd cpython.git
$ git clean -fdx
$ ./configure && make
$ ./python.exe Lib/idlelib/idle_test/run_coverage.py  # <= ok

I guess you could use an installed Python to check the coverage of the IDLE test suite in your development environment. I'm not sure why you would want to do so, though.

Comment on lines +121 to +122

.*# htest #
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme is behind the file I actually use.

Suggested change
.*# htest #
.*# pragma: no cover
.*# pragma: no branch
.*# htest #
if not (_htest or _utest):

The pragmas are generic to coverage; 'no cover' is currently used in idlelib.

The suggested coveragerc should be a separate file in idle_test/. If I knew how to put a symlink in /dev, where I use it, I would to avoid the 2 copies issues.

---
The second parameter was added for tests of module x not named test_x.
(There were several before modules were renamed, now only one is left.)
To get a coverage report for a specific module's tests, run:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify what I meant 2 years ago, DO NOT REMOVE the instructions for what I have done since 3.6 and plan to continue to use. What I deferred then was revising my text. I am working on it now.

Suggested change
To get a coverage report for a specific module's tests, run:
To get a coverage report for a specific module's tests, do one of the following:
A. run

I can then edit my part to starts B. ....

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@terryjreedy terryjreedy changed the title bpo-30934: add script for running coverage on IDLE modules' tests gh-75117: add script for running coverage on IDLE modules' tests Aug 3, 2022
@ambv ambv closed this Aug 4, 2022
@ambv ambv reopened this Aug 4, 2022
@ambv
Copy link
Contributor

ambv commented Aug 4, 2022

@taleinat, all's good now.

@terryjreedy terryjreedy changed the title gh-75117: add script for running coverage on IDLE modules' tests gh-75117: IDLE - add script for running coverage on tests Nov 2, 2022
@python python deleted a comment Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants