Skip to content

Add regression tests for ancient str methods #98536

Closed
@larryhastings

Description

@larryhastings

I just noticed that Python's test suite doesn't seem to include any tests for the split, rsplit, and splitlines methods on strings. There are plenty of uses of these methods, of course--they're fundamental. But there are no regression tests ensuring they behave in a consistent manner from release to release.

This isn't a huge cause for concern, both because they don't change much, and because so much code is reliant on these functions, we'd notice very quickly if they changed. Still, I think it's worthwhile to build up a test suite that exercises all their quirks.

For example, I only recently discovered that when using the split method on strings to split on whitespace, if maxsplit prevents split from splitting the entire string, it won't actually strip trailing whitespace:

>>> "   a b c   ".split(None, 1)
['a', 'b c   ']

Verifying this sort of thing is exactly what unit test suites are for!

There's slightly more testing for split on bytes objects, but not much. So I'd say both need doing. Might also be worth checking all the core builtin types and ensuring that they have unit tests for all their methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    easytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions