Skip to content

Fix handling of warnings in the test runner #19247

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

Merged
merged 4 commits into from
May 4, 2020

Conversation

oscarbenjamin
Copy link
Collaborator

@oscarbenjamin oscarbenjamin commented May 3, 2020

References to other Issues or PRs

See #19193 and #19242
Finishes unfinished work from #19006 which implements part of #18066.

Brief description of what is fixed or changed

The PR #19006 deprecates the string fallback in sympify which parses functions via str. Because the test runner did not always fail when warnings were raised some tests were still using the deprecated code path. This PR fixes the test runner so that deprecation warnings will always fail the bulid on Travis in both normal tests and doctests by setting/resetting the warning filter before/after each individual test.

Fixing the test runner lead to other failures for example a doctest that does

>>> sqrt(x).has(sqrt)

Here the sympify function (used in has) converts the sqrt function a string and tries to parse it leading to the deprecation warning. I've changed has to use _sympify instead of sympify.

Changing Basic.has lead to failures in solveset which turned out to be due to a line erroneously calling expr.as_independent([x, y]) rather than expr.as_independent(x, y). I've fixed that.

There was also a doctest in printing that depended on automatic parsing of strings which I've changed to use Symbol explicitly.

Other comments

This is a PR against master so it can be reviewed. If this is merged in to master I will reopen it for the 1.6 branch (it is needed before updating the version in that branch). I will add the release note there:

* core
    * BREAKING CHANGE: Basic.has no longer accepts strings as input. For example in SymPy 1.5 you could do `Symbol('x').has('x')` and the string `'x'` passed to `has` would be sympified to a symbol so that the result would be `True`. In SymPy 1.6 this will raise an error because the string `'x'` can not be sympified using strict sympification.

Release Notes

NO ENTRY

When running tests/doctests with sympy's own test runners a warning
filter is used to turn DeprecationWarning/SymPyDeprecationWarning into
an error. The filter was only set one at the start of running the tests.
This means that if the filter is modified by one test then it will still
be modified when subsequent tests run.

This commit adds a raise_on_deprecated context manager in runtests.py
and uses it to set the warning filter in the test runners. The filter is
set immediately around running the test and is reset before each
individual test. This has picked up on a couple of failures that will
need to be fixed in subsequent commits.
The Basic.has method is changed from using sympify to _sympify so that
string input is no longer accepted and so that functions are no longer
parsed as strings.

A line in solveset needed to be fixed because it was erroneously calling
expr.as_independent([x, y]) rather than expr.as_independent(x, y).

BREAKING CHANGE

Basic.has no longer accepts strings so e.g. Symbol('x').has('x') will
raise an exception.
The tableform doctest relied on implicit sympification of strings into
symbols. This commit calls Symbol explicitly to remove the warning from
sympify.
@sympy-bot
Copy link

sympy-bot commented May 3, 2020

Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

  • No release notes entry will be added for this pull request.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs

See #19193 and #19242 
Finishes unfinished work from #19006 which implements part of #18066.

#### Brief description of what is fixed or changed

The PR #19006 deprecates the string fallback in sympify which parses functions via str. Because the test runner did not always fail when warnings were raised some tests were still using the deprecated code path. This PR fixes the test runner so that deprecation warnings will always fail the bulid on Travis in both normal tests and doctests by setting/resetting the warning filter before/after each individual test.

Fixing the test runner lead to other failures for example a doctest that does
```
>>> sqrt(x).has(sqrt)
```
Here the sympify function (used in `has`) converts the sqrt function a string and tries to parse it leading to the deprecation warning. I've changed has to use `_sympify` instead of `sympify`.

Changing `Basic.has` lead to failures in `solveset` which turned out to be due to a line erroneously calling `expr.as_independent([x, y])` rather than `expr.as_independent(x, y)`. I've fixed that.

There was also a doctest in printing that depended on automatic parsing of strings which I've changed to use Symbol explicitly.

#### Other comments

This is a PR against master so it can be reviewed. If this is merged in to master I will reopen it for the 1.6 branch (it is needed before updating the version in that branch). I will add the release note there:
```
* core
    * BREAKING CHANGE: Basic.has no longer accepts strings as input. For example in SymPy 1.5 you could do `Symbol('x').has('x')` and the string `'x'` passed to `has` would be sympified to a symbol so that the result would be `True`. In SymPy 1.6 this will raise an error because the string `'x'` can not be sympified using strict sympification.
```

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->

The Dict doctest relied on auto-sympification of strings in calling
D.has('one'). This commit uses Symbol explicitly because has no longer
accepts string input after 9c57fd0

BREAKING CHANGE: Using D.has('x') where D is a SymPy Dict will raise an
exception. Use D.has(Symbol('x')) instead.
@codecov
Copy link

codecov bot commented May 3, 2020

Codecov Report

Merging #19247 into master will decrease coverage by 0.008%.
The diff coverage is 47.826%.

@@              Coverage Diff              @@
##            master    #19247       +/-   ##
=============================================
- Coverage   75.674%   75.665%   -0.009%     
=============================================
  Files          651       651               
  Lines       169486    169487        +1     
  Branches     40021     40021               
=============================================
- Hits        128257    128244       -13     
- Misses       35625     35626        +1     
- Partials      5604      5617       +13     

@oscarbenjamin
Copy link
Collaborator Author

It would be great to have a speedy review on this. I can't bump the version on the 1.6 release branch without it but the fix here involves a breaking change that Basic.has no longer accept string inputs because it uses _sympify rather than sympify.

@jksuom
Copy link
Member

jksuom commented May 4, 2020

This looks good to me. I'm not sure that I quite understand what the nested context manager does but it seems to work.

@oscarbenjamin
Copy link
Collaborator Author

Thanks @jksuom.

@oscarbenjamin oscarbenjamin merged commit e0ef1da into sympy:master May 4, 2020
@oscarbenjamin oscarbenjamin deleted the pr_warnings_tests branch May 4, 2020 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy