Skip to content
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

gh-69714: Make calendar module fully tested #93655

Merged
merged 29 commits into from
Jul 22, 2023

Conversation

bxsx
Copy link
Contributor

@bxsx bxsx commented Jun 9, 2022

Summary

Resolves #69714 by increasing test coverage of calendar module to 100%[1].

Coverage reports

Before

main branch test coverage report for calendar module:

$ ./python.exe coveragepy report --show-missing
Name              Stmts   Miss  Cover   Missing
-----------------------------------------------
Lib/calendar.py     399     60    85%   559, 564-570, 582, 602, 664-764, 768
-----------------------------------------------
TOTAL               399     60    85%

After

The PR branch test coverage report for calendar module:

$ ./python.exe coveragepy report --show-missing
Name              Stmts   Miss  Cover   Missing
-----------------------------------------------
Lib/calendar.py     397      3    99%   722, 742, 766
-----------------------------------------------
TOTAL               397      3    99%

Footnotes

[1] The remaining three lines are:

$ cat -n Lib/calendar.py | sed -n '722p;742p;766p'
   722	        sys.exit(1)
   742	            sys.exit(1)
   766	    main()
$

and they are, in fact, already covered by tests (only not reported by coveragepy).

rohitmediratta and others added 11 commits June 6, 2022 02:29
….Locale{Text|HTML}Calendar`

There are 3 paths to use `locale` argument in
`calendar.Locale{Text|HTML}Calendar.__init__(..., locale=None)`:
(1) `locale=None` -- denotes the "default locale"[1]
(2) `locale=""` -- denotes the native environment
(3) `locale=other_valid_locale` -- denotes a custom locale

So far case (2) is covered and case (1) is in 78935da (same branch).
This commit adds a remaining case (3).

[1] In the current implementation, this translates into the following
approach:

GET current locale
IF current locale == "C" THEN
  SET current locale TO ""
  GET current locale
ENDIF
This condition cannot be true. `_locale.setlocale()` from the C module
raises `locale.Error` instead of returning `None` for
`different_locale.__enter__` (where `self.oldlocale` is set).
This patch has already been applied to `main` branch (via pythongh-93468), but
with wrong copyright. After merging this commit to `main`, git `Author`
metadata will be updated to the original author.
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Jun 9, 2022

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Also cc: @hugovk (who I know has different opinions on testing to me!)

A

Lib/calendar.py Show resolved Hide resolved
Lib/calendar.py Show resolved Hide resolved
Lib/test/test_calendar.py Outdated Show resolved Hide resolved
Lib/test/test_calendar.py Outdated Show resolved Hide resolved
@AA-Turner AA-Turner added stdlib Python modules in the Lib dir type-feature A feature request or enhancement tests Tests in the Lib/test dir labels Jun 9, 2022
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@AA-Turner
Copy link
Member

You will need a NEWS entry, along the lines of Added tests to :mod:`calendar` to achieve full test coverage.

A

@bxsx
Copy link
Contributor Author

bxsx commented Jun 9, 2022

@AA-Turner
You will need a NEWS entry, along the lines of Added tests to :mod:`calendar` to achieve full test coverage.

Thanks! I just added it.

Another problem is the lack of CLA signatures from @jesstess and @rohitmediratta. The applied patches were quite old, so I'm not sure the email addresses are up to date (I don't know if the bot is sending emails about the CLA). Anyway, it looks like GitHub has assigned these commits to the correct usernames, so I'm tagging Jessica and Rohit in this comment to help notify :)

@AA-Turner
Copy link
Member

You'll need to fix the Ubuntu failures in test_locale_calendar_formatmonthname too:

Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_calendar.py", line 650, in test_locale_calendar_formatmonthname
    self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=False), "June")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/calendar.py", line 588, in formatmonthname
    with different_locale(self.locale):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/calendar.py", line 555, in __enter__
    _locale.setlocale(_locale.LC_TIME, self.locale)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/locale.py", line 626, in setlocale
    return _setlocale(category, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
locale.Error: unsupported locale setting

This may be another test-skipping scenario, I don't know what the values it is trying to set are though so I can't guess much further.

A

@AA-Turner
Copy link
Member

I'm tagging Jessica and Rohit in this comment to help notify

You might also want to consider emailing the two of them if you don't hear back, neither seem to have much recent publicly shown activity on GH.

A

@bxsx
Copy link
Contributor Author

bxsx commented Jun 9, 2022

@AA-Turner
You'll need to fix the Ubuntu failures in test_locale_calendar_formatmonthname too:

This may be another test-skipping scenario, I don't know what the values it is trying to set are though so I can't guess much further.

Or maybe (based on the traceback) it's related to one of the corner cases from #93655 (comment)?
I don't have access to Ubuntu at the moment but I can revert that change and see what happens before further investigation.
This is a newly added test BTW.

@AA-Turner
Copy link
Member

I can revert that change and see what happens before further investigation.

Sadly it doesn't seem to have worked :(

A

bxsx added 2 commits June 10, 2022 01:01
…()`.

This method temporarily changes the current locale to the given locale,
so `_locale.setlocale()` may raise `local.Error`.
… test coverage)""

This reverts commit 40e0da3.
So it brings back commit a96786c.
@bxsx
Copy link
Contributor Author

bxsx commented Jun 10, 2022

Sadly it doesn't seem to have worked :(

Yes, I misread the traceback in a rush before disconnecting, but I wanted to kick off builds to get results when I get back. Time saving ;)

For now, I have restored a96786c.

However, it is true that the cause of the problem is related to #31214 and as you correctly predicted, this is another test-skipping scenario. Fixed in 2b6f1f9.

@bxsx
Copy link
Contributor Author

bxsx commented Jun 10, 2022

test_illegal_arguments and test_too_many_arguments fail in Azure Pipelines PR.
I will try to investigate it, but for now I'm marking this PR as a draft.

@bxsx bxsx marked this pull request as draft June 10, 2022 02:05
Lib/test/test_calendar.py Show resolved Hide resolved
Lib/test/test_calendar.py Show resolved Hide resolved
Lib/test/test_calendar.py Show resolved Hide resolved
@bxsx
Copy link
Contributor Author

bxsx commented Jun 11, 2022

test_illegal_arguments and test_too_many_arguments fail in Azure Pipelines PR.
I will try to investigate it, but for now I'm marking this PR as a draft.

Fixed in 8b7bc06.

@bxsx
Copy link
Contributor Author

bxsx commented Jun 11, 2022

Ok, all comments are now addressed and resolved. All tests pass successfully. ✔️
Still missing CLA signatures from @jesstess and @rohitmediratta. I will email them directly. 🤞

I think the PR is ready for another round of reviews ;-)

@bxsx bxsx marked this pull request as ready for review June 11, 2022 19:06
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

The updated tests look good, I'll wait for Hugo's thoughts.

A

Lib/calendar.py Show resolved Hide resolved
Lib/calendar.py Show resolved Hide resolved
@bxsx bxsx requested review from hugovk and AA-Turner June 12, 2022 17:01
@bxsx
Copy link
Contributor Author

bxsx commented Jun 17, 2022

Good news for the weekend.

Rohit signed the CLA. Thanks again @rohitmediratta!

I also looked at @jesstess GH profile and I believe the missing CLA has already been signed by Jessica as she is a former director of the Python Software Foundation and a member of @python.

I've emailed contributions@python.org to sort this out.

@terryjreedy
Copy link
Member

Here is the holdup situation:
For https://bugs.python.org/issue13330, Attempt full test coverage of LocaleTextCalendar.formatweekday
Sean Fleming, no CLA recorded, uploaded a patch 2011-11-03 02:14.
bpo user jesstess Jessica McKellar, https://bugs.python.org/user11041, signed the CLA "on: 2013-04-12.20:00:00".
She more or less rejected Sean's patch and uploaded a much different patch,
https://bugs.python.org/file35060/issue13330.patch on 2014-04-27 16:43.
Serhiy Storchaka mentioned a couple of problems.

When moved to gh, issue became #57539. Irit Katriel requested gh PR and mentioned this issue.
Last June, hugovk converted Jessica's patch to a PR, with the correction requested by Serhiy.
The commit message mistakenly said "Co-authored-by: Sean Fleming". This apparently did not trigger the CLA bot of the time to request a signature from Sean. ambv merged and backported on June 7, 2022.

On June 9, bxsx added ab069a4, which added Jessica's original code, without the Serhiy correction. It somehow credited Jessica as author. Fortunately, the deletion of the correction is somehow not in the merged patch. Unfortunately, it fooled the CLA bot into thinking that she was an author of this PR.

@ambv This PR, which has had a lot of work by multiple people, is blocked by the false 'need' for an unobtainable signature from @jesstess Jessica McKeller, who did not contribute to this PR. Should reverting ab069a4 fix the mistake or is something else needed. If so, can you override the bot? (Though a final review may be needed.)

@ambv ambv merged commit 2aba047 into python:main Jul 22, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attempt to further increase test coverage of calendar module
10 participants