Issue 10273: Clean-up Unittest API (original) (raw)

Created on 2010-11-01 00:13 by rhettinger, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (29)

msg120100 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-01 00:13

msg120101 - (view)

Author: Antoine Pitrou (pitrou) * (Python committer)

Date: 2010-11-01 00:18

I would prefer assertRegex to assertRegexp.

msg120106 - (view)

Author: Michael Foord (michael.foord) * (Python committer)

Date: 2010-11-01 03:32

In general none of this should be done until there is clear consensus on Python-dev and it isn't clear that this is the case.

msg120127 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-01 14:01

msg120188 - (view)

Author: Antoine Pitrou (pitrou) * (Python committer)

Date: 2010-11-01 23:34

Just my 2 cents:

msg120194 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-02 00:28

[Antoine]

I would prefer assertRegex to assertRegexp

That makes sense. It is the name used in other unittest implementations, it matches what the re module used to be called in Python, and it avoids issues with camel casing (i.e. Regexp vs RegExp).

msg120201 - (view)

Author: Brett Cannon (brett.cannon) * (Python committer)

Date: 2010-11-02 02:39

Just sent an email to python-dev, but since this issue sparked it, I might as well comment here: unittest shouldn't be made back into a single module.

Ignoring the fact that the file structure has nothing to do with the public API and so is orthogonal to the main thrust of this issue, changing it back will break imports in code from Python 2.7 that uses the more modular structure that now underlies unittest. Considering how much whining we get about code breakage any time Michael tries to fix anything in the module I think this is the last thing anyone wants to have happen.

msg120220 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-02 13:11

FWIW in addition to assertRegexpMatches and assertNotRegexpMatches there are 2 more methods that use "Regexp": assertRaisesRegexp and the newly introduced assertWarnsRegexp.

msg120221 - (view)

Author: Michael Foord (michael.foord) * (Python committer)

Date: 2010-11-02 13:14

@Ezio

Good catch. Even though several of us (including myself) prefer assertRegex over assertRegexp it is probably better to have consistent APIs otherwise people will never remember which methods have the 'p' and which don't.

msg120294 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-03 00:33

After discussion on python-dev, it seems that API lock-in precludes any change to the package structure. So, the main proposals left are the addition of new better aliases for some of the functions and changing to the docs so that the new name is clear:

assertLE(self, other) old name: AssertLessEqual . . .

Also, I we should still dedocument assertEqual and its brethren and leave assertEqual as the primary interface.

At some point, we could add an option to assertEqual to allow user control of how failing results are displayed. This would let us separate content from presentation (i.e. a==b vs how a diff would get presented).

msg120298 - (view)

Author: R. David Murray (r.david.murray) * (Python committer)

Date: 2010-11-03 01:31

I don't think assertLE is enough of an improvement over assertLessEqual to be worth adding yet more deprecated names to unittest. So I'm -0 on this change in general. (I'd be -1 except that it would be kind of nice to have the names be shorter :)

If the change is made, then assertEqual should become assertEQ, and assertNotEqual should become assertNE.

Another option is to go the other way, and change assertLess to assertLessThan. That is, make the spelling consistently be the spelled out version of the abbreviation used in the special methods and elsewhere in the docs. This would involve far fewer name changes.

msg120301 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-03 02:29

Besides being shorter, the advantages of assertLE are consistent with the rich comparison method names, no worries about Than, no camel casing ambiguities, no pluralization or other nmemonic issues (LessThanEqual or LessThanEquals or LessThanOrEqual or LessThanOrEqualTo). The goal is to make sure you don't have to look up the spelling every time you use them.

That being said, assertEqual can't change. It has been around forever and is clear about what it does.

What I am sure about is that assertLess and assertLessEqual are very non-standard spellings and that infrequent users of comparison assertions won't remember them.

msg120323 - (view)

Author: R. David Murray (r.david.murray) * (Python committer)

Date: 2010-11-03 13:01

assertEquals existed forever, too, but we deprecated that :) (with no intent to remove it, as I understand it).

There is no more ambiguity in "assertLessThan" than there is in assertLT, one just has more letters. True, you have to look it up the first time, but you have to do that anyway, so I don't see that as a big deal. Once you've looked it up the first time you know the naming rule and you can figure out all the other names. (Which is not true now, since instead of 'LessThan' we have "Less", which does not correspond to to the special method name by a simple rule).

msg120357 - (view)

Author: Michael Foord (michael.foord) * (Python committer)

Date: 2010-11-03 23:52

Renaming and aliasing methods has a cost. It confuses users of the old names (including future users - the current API is now baked into django 1.3 unless I can get an update done in time for them to change the version they're using). People who use autocomplete or introspection (dir) to explore the APIs will also still come across the old names. Given that unittest has just changed a lot a further radical change is 'unfortunate'.

However, for both the regexp methods and the Items method the names are actually misleading.

For assertItemsEqual Raymond suggests assertElementCountsEqual. See issue 10242.

For the regexp methods we should use assertRegexp - this is shorter, not misleading and consistent with assertRaisesRegexp.

We should leave the gt / le / lt methods as they are. There is less consensus that these methods should be changed anyway.

The documentation can be improved by moving all the deprecated methods (new and old) out of the main documentation and into a separate section at the end of the documentation.

The type specific asserts we should also move into their own section and out of the main documentation. This means users who discover don't have to go to the source (there are online references) but they are out of the main documentation.

Hopefully everyone is only equally unhappy with this resolution.

msg120360 - (view)

Author: Antoine Pitrou (pitrou) * (Python committer)

Date: 2010-11-04 00:04

For assertItemsEqual Raymond suggests assertElementCountsEqual. See issue 10242.

Why replace a long awkward name with an even longer and more awkward name?

msg120363 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-04 00:27

An alternative would be adding check_order and check_duplicates to assertSameElements and de-deprecate it.

Python 2.7 could be left unchanged because it's too late to add/rename/deprecate methods (it has assertItemsEqual but not assertSameElements). Py3.2 would also be unchanged (assertItemsEqual and the deprecation of assertSameElements are both new in 3.2, assertSameElements has been introduced in 3.1). They would end up with two different methods though.

The assertSameElements name seems quite good, and providing extra args will make it more flexible (it will cover all the 4 cases listed in ) and the behavior would be clear without clumsy method names.

msg120369 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-04 01:25

For the regexp methods we should use assertRegexp

assertRegex is better. it matches the name used in other unittest implementations, there is not confusion with camel casing RegExp vs Regexp, and it matches the former name of Python's own regex module.

We should leave the gt / le / lt methods as they are.

The assertLessEqual name is non-standard, it will never be spelled right by someone who hasn't used it recently.

The documentation can be improved by moving all the deprecated methods (new and old) out of the main documentation and into a separate section at the end of the documentation

See issue 10242 for a suggestion on how to handle renaming (document the new and old name in the same entry, noting that one name is old).

For assertItemsEqual Raymond suggests assertElementCountsEqual. Why replace a long awkward name with an even longer and more awkward name?

If length is an issue, assertCountsEqual will also do fine. The important virtue is clarity. The problem with ItemsEqual is that it doesn't tell you anything about what it does (unordered comparison where duplicates matter). Also, the term "items" in Python usually means key/value pairs. That is why we use the term "elements" in sets, itertools, etc. In contrast, assertCountsEqual tells you what it does, compares the element counts. It is the same as Counter(a)==Counter(b) for hashable elements and an equivalent for unhashable elements.

msg120370 - (view)

Author: R. David Murray (r.david.murray) * (Python committer)

Date: 2010-11-04 01:54

assertCountsEqual is IMO much clearer than assertItemsCountsEqual (or however you spell it). I was unclear on what the latter did, but the former is fairly clear. Ezio's suggestion is also clearer.

Raymond, since you said 'never' your statement about assertLessEqual is clearly false :). I don't have any problem remembering it (it's just le spelled out using the standard unittest camelcase). assertLess, on the other hand, I often get wrong, since it is not lt spelled out.

msg120372 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-04 02:23

assertLess, on the other hand, I often get wrong, since it is not lt spelled out.

Right. Even Michael gets that one wrong.

Meditate on why Guido created the special method lt instead of less_than.

Regardless of why Guido made that choice, we do already have a standard way to spell less-than in Python, and it would be good to stick with it.

msg120393 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-04 11:52

It should be noted that, if we re-use assertSameElements, the default behavior should be preserved for compatibility with 3.1, and that is different (and possibly less useful) than the one of assertItemsEqual. Ambiguities could be solved easily specifying the args explicitly every time though.

Regarding assertLT I'm still -1. The current names are imho the best compromise between being short and descriptive. They also match nicely assertEqual (assertLT <-> assertEQ; assertLessThan <-> assertEqualTo; but assertLess <-> assertEqual). Also it might not be immediately obvious what assertGE does, if one is not familiar with the special methods or if taken out of context (it's easy to recognize it if it's together with assertLT/LE/GT, but alone might just look a specialized method with a bad name). Moreover people who are used to the current spelling will have to notice the change, note that one name is now deprecated, update their code, remember if the correct name is assertLess or assertLT, wonder if assertEqual has been deprecated in favor of assertEQ too, remember the version where the name changed (e.g. if they try assertLT on 3.1 it won't work) and so on.

msg120597 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-06 08:18

people who are used to the current spelling will have to notice the change, note that one name is now deprecated

I haven't proposed any deprecations. Just add the new names as aliases. Change the docs list the new names as primary and mention the old name for reference.

We don't have to sticking with crummy naming.

msg122413 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-25 22:16

After discussion with Michael and Guido, am limiting this to:

msg122416 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-25 22:56

I already fixed this on py3k, adding a section where the type-specific methods are described0 and added a reference in the assertEqual description1. I also clarified that usually there's no need to call them directly even thought I don't see why they shouldn't do it if they want to use a specific test.

And assertNotRegexpMatches -> assertNotRegex, assertRaisesRegexp -> assertRaisesRegex, assertWarnsRegexp -> assertWarnRegex? Will the *Regexp forms be deprecated too?

msg122425 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-26 01:12

Yes, all the variants of RegexpMatches --> Regex No, on deprecations. Just add a new alias and note in the docs that the oldname is obsolete. Naming deprecations cause too much trouble for too little benefit.

msg122434 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-11-26 03:59

If I implement what I suggested in #10535, it will be possible to deprecate them without too much trouble. I offer to do it after #10535.

msg122758 - (view)

Author: Raymond Hettinger (rhettinger) * (Python committer)

Date: 2010-11-29 02:39

Ezio, please do the regexp-->regex changes and move the tests under Lib/test.

msg122788 - (view)

Author: Michael Foord (michael.foord) * (Python committer)

Date: 2010-11-29 11:24

Raymond - I created a new issue for moving the tests: issue 10572

However, it seems that you are incorrect in saying that Python practise is to avoid putting tests inside standard library packages. In fact current Python practise seems to be that where tests themselves are a package they are always inside the standard library package and not inside Lib/test. For example: email, distutils, ctypes, importlib, json, lib2to3, sqlite3, tkinter,

I couldn't see any counter-examples. There are no test packages inside Lib/test (other than leakers that are obviously a category of tests and not tests for a particular package).

msg122971 - (view)

Author: Ezio Melotti (ezio.melotti) * (Python committer)

Date: 2010-12-01 02:35

s/regexp/regex/ done in r86910.

msg123713 - (view)

Author: Gregory P. Smith (gregory.p.smith) * (Python committer)

Date: 2010-12-10 01:46

fyi - since I didn't chime in earlier on this: I think you made the right choice with what was decided in and implemented in the renaming done in r86910 and the work done in .

History

Date

User

Action

Args

2022-04-11 14:57:08

admin

set

github: 54482

2010-12-10 01:46:44

gregory.p.smith

set

messages: +

2010-12-01 02:35:37

ezio.melotti

set

status: open -> closed
resolution: fixed
messages: +

stage: resolved

2010-11-29 11:24:13

michael.foord

set

messages: +

2010-11-29 02:39:09

rhettinger

set

assignee: rhettinger -> ezio.melotti
messages: +

2010-11-26 03:59:34

ezio.melotti

set

messages: +

2010-11-26 01:12:06

rhettinger

set

messages: +

2010-11-25 22:56:45

ezio.melotti

set

messages: +

2010-11-25 22:16:55

rhettinger

set

messages: +

2010-11-06 08🔞19

rhettinger

set

messages: +

2010-11-06 05:26:39

eric.araujo

set

nosy: + eric.araujo

2010-11-04 14:50:07

ezio.melotti

set

nosy: + gregory.p.smith, flox

2010-11-04 11:53:00

ezio.melotti

set

messages: +

2010-11-04 02:23:59

rhettinger

set

messages: +

2010-11-04 01:54:31

r.david.murray

set

messages: +

2010-11-04 01:25:43

rhettinger

set

messages: +

2010-11-04 00:27:02

ezio.melotti

set

messages: +

2010-11-04 00:04:30

pitrou

set

messages: +

2010-11-03 23:52:33

michael.foord

set

messages: +

2010-11-03 13:01:23

r.david.murray

set

messages: +

2010-11-03 02:29:49

rhettinger

set

messages: +

2010-11-03 01:31:42

r.david.murray

set

nosy: + r.david.murray
messages: +

2010-11-03 00:33:52

rhettinger

set

messages: +

2010-11-02 13:14:53

michael.foord

set

messages: +

2010-11-02 13:11:37

ezio.melotti

set

nosy:brett.cannon, rhettinger, pitrou, ezio.melotti, michael.foord
messages: +
components: + Tests

2010-11-02 02:39:40

brett.cannon

set

nosy: + brett.cannon
messages: +

2010-11-02 00:29:17

rhettinger

set

assignee: michael.foord -> rhettinger

2010-11-02 00:28:58

rhettinger

set

messages: +

2010-11-01 23:34:00

pitrou

set

messages: +

2010-11-01 14:01:19

ezio.melotti

set

messages: +

2010-11-01 03:32:33

michael.foord

set

assignee: rhettinger -> michael.foord
messages: +

2010-11-01 00🔞09

pitrou

set

nosy: + pitrou
messages: +

2010-11-01 00:15:16

ezio.melotti

set

nosy: + ezio.melotti, michael.foord

2010-11-01 00:13:41

rhettinger

create