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

Created on 2012-02-15 08:15 by ncoghlan, last changed 2019-08-07 12:52 by nanjekyejoannah.

File name Uploaded Description Edit
mywork.patch francisco.freire, 2013-08-08 22:15 Formatter Unity Tests review
mywork2.patch francisco.freire, 2013-08-24 11:50 New Patch with changes review
Messages (16)
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.
Date User Action Args
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