This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Unify tests for str.format and string.Formatter
Type: enhancement Stage: patch review
Components: Tests Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, eric.smith, ezio.melotti, francisco.freire, francismb, moijes12, nanjekyejoannah, ncoghlan, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2012-02-15 08:15 by ncoghlan, last changed 2022-04-11 14:57 by admin.

Messages (19)
msg153392 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-15 08:15
A couple of issues have arisen where features were added to str.format without similarly being added to string.Formatter.

This is only possible because the test cases for the two are currently almost entirely separate.

A common set of tests defined as (fmt, args, kwargs, output) tuples would help ensure that the implementations remained consistent in the future.
msg153729 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-02-19 22:39
(ISTM that such test improvements would be beneficial to all branches, and we would also eschew merge issues if we change all branches.  Other core devs sometimes object to test improvements or additions in stable branches though.)
msg154000 - (view) Author: Francis MB (francismb) * Date: 2012-02-22 22:11
I have some questions about this:

1) In Lib/test/ it says:
“Common tests shared by test_str, test_unicode, test_userstring and


   a) I cannot find test_str

   b) string is imported and only some constants ascii_letters
   and digits are used

   c) In test_join there is a comment “see the test in
   test.test_string.StringTest.test_join” Is that obsolete?
   (I cannot find StringTest in the test_string test)

2) Is there more tests for the build in format (in
test_buildin.BuiltinTest.test_format only the basic machinery is tested.
I would expect something like in somewhere

3) it is true that all tests for the build in 'format' should also pass 
in 'string.Formatter().format'

Thanks in advance!

msg154002 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-22 22:18
At least the first couple of those look like obsolete comments left over from the 2.x branch (we didn't do a mass renaming in the test suite, so many tests still live in their old locations).
msg194709 - (view) Author: Francisco Freire (francisco.freire) * Date: 2013-08-08 22:15
I increased the coverage of formatter module to 40%. I added a new file "" including some unit tests.
msg195061 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-08-13 09:50
I left a review on rietveld.

FWIW I think string_tests and related files should undergo a (major?) refactoring.  I worked with them a few times and it's a bit of a mess with all those base classes and mixins.  I also found some tests that weren't running because they were accidentally overridden by one of the subclasses, or other tests that were duplicated.  This is especially true on Python 3, where bytes and str share a smaller subset of features.
msg196074 - (view) Author: Francisco Freire (francisco.freire) * Date: 2013-08-24 11:50
Thanks for the review. I corrected some issues in my code. Here is the new patch.
msg217757 - (view) Author: Francis MB (francismb) * Date: 2014-05-02 16:42
The formatter module was deprecated in Python 3.4 and is scheduled
for removal in Python 3.6. See [1] and [2].

msg217904 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-05-05 03:54
Note that this issue wasn't about the formatter module - it relates to the str.format() method and the string.Formatter *class*.

The formatter module is completely unrelated.
msg217927 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2014-05-05 15:10
The issue is about tests for str.format and string.Formatter, but in and the associated patch there are tests for the formatter module to increase its coverage.

I suggested on the mentorship list that we break this into two issues.
msg218159 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-09 12:35
Francisco, can you sign the contributor agreement?
msg218163 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-09 13:49
I added some review comments.
msg218976 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-23 15:43
Set to "pending" while I wait to hear back from Francisco on the review comments.
msg219011 - (view) Author: Francisco Freire (francisco.freire) * Date: 2014-05-23 23:11
Hi, I signed the contributor agreement. Thank you for your review comments. I did these tests about one year ago and right now I don't have much time to look at it again. I hope to do so in the next months.
msg219508 - (view) Author: moijes12 (moijes12) Date: 2014-06-01 16:14
> Note that this issue wasn't about the formatter module - it relates to the str.format() method and the string.Formatter *class*.

I would tend to agree with Nick and Eric. From what I see in the patch, the tests are for formatter module and not the string.Formatter class.
msg348636 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-29 11:47
This issue is no newcomer friendly, I remove the "easy" keyword.
msg380590 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-09 14:51
@Irit Katriel: Please avoid changing the versions field of old inactive issues. It changes artificially the last activity date of an issue and it sends an email to all people in the nosy list. There is no need to update the Version field of the +7500 open bugs.
msg380625 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-11-10 00:23
Victor: Irit is reviewing old issues to decide whether to close or not.  She has to touch it somehow to mark it as reviewed.

Irit: if you only change the version, others may think that you blindly updated the version.  Better to say something that moves the issue forward.  Also, only marking for the next version, now 3.10, would delay the possible future obsolescence of the version marking.  In any case, any coredev who merges would decide about backports.

This particular issue needs major surgery as it is two interleaved but unrelated discussions.  Francisco should have moved his unrelated patch to a new issue as Eric Smith asked.  I opened new issue 42299 and moved the revised patch there, with credit to Francisco and Ezio as reviewer.  I unlinked both from here.

To make the discussion of Nick's issue more readable, the unrelated messages about the unrelated patch should be unlinked.  I believe each message unlink would generate a separate email, as did the file unlinks.
msg380665 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-10 13:53
Since nobody implemented this idea in 8 years, maybe it's time to give up and close this issue as out of date. It seeems like Nick was busy with other stuff, and nobody took this task in the meanwhile.
Date User Action Args
2022-04-11 14:57:26adminsetgithub: 58227
2020-11-10 13:53:04vstinnersetmessages: + msg380665
2020-11-10 00:23:10terry.reedysetmessages: + msg380625
versions: - Python 3.8, Python 3.9
2020-11-10 00:13:58terry.reedysetfiles: - mywork2.patch
2020-11-09 23:42:36terry.reedysetfiles: - mywork.patch
2020-11-09 14:51:43vstinnersetmessages: + msg380590
2020-11-06 23:00:06iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.6, Python 3.3, Python 3.4
2020-01-29 03:22:02josephgordonsetnosy: - josephgordon
2020-01-29 00:57:17brett.cannonsetnosy: - brett.cannon
2019-08-07 12:52:57nanjekyejoannahsetnosy: + nanjekyejoannah
2019-07-29 11:47:28vstinnersetkeywords: - easy
nosy: + vstinner
messages: + msg348636

2015-12-14 02:25:23josephgordonsetnosy: + josephgordon
2015-04-24 15:56:59brett.cannonsetassignee: brett.cannon ->
2014-06-01 16:14:16moijes12setnosy: + moijes12
messages: + msg219508
2014-05-23 23:11:30francisco.freiresetstatus: pending -> open

messages: + msg219011
2014-05-23 15:43:55brett.cannonsetstatus: open -> pending

messages: + msg218976
2014-05-09 13:49:40brett.cannonsetmessages: + msg218163
2014-05-09 12:35:12brett.cannonsetmessages: + msg218159
2014-05-05 15:10:16eric.smithsetmessages: + msg217927
2014-05-05 03:54:23ncoghlansetmessages: + msg217904
2014-05-03 13:43:14brett.cannonsetassignee: brett.cannon

nosy: + brett.cannon
2014-05-02 16:42:24francismbsetmessages: + msg217757
2013-08-24 11:50:30francisco.freiresetfiles: + mywork2.patch

messages: + msg196074
2013-08-13 09:50:43ezio.melottisetversions: + Python 3.4, - Python 3.2
nosy: + ezio.melotti

messages: + msg195061

type: enhancement
stage: patch review
2013-08-08 22:15:21francisco.freiresetfiles: + mywork.patch

nosy: + francisco.freire
messages: + msg194709

keywords: + patch
2012-02-22 22:18:49ncoghlansetmessages: + msg154002
2012-02-22 22:11:08francismbsetmessages: + msg154000
2012-02-19 22:39:03eric.araujosetversions: + Python 2.6, Python 3.2
nosy: + eric.araujo

messages: + msg153729

keywords: + easy
2012-02-15 20:46:31terry.reedysetnosy: + terry.reedy
2012-02-15 17:38:12francismbsetnosy: + francismb
2012-02-15 11:24:41eric.smithsetnosy: + eric.smith
2012-02-15 08:15:04ncoghlancreate