mirror of
https://github.com/python/cpython.git
synced 2025-08-18 07:41:05 +00:00
[3.12] gh-94722: fix DocTest.__eq__ for case of no line number on one side (GH-112385) (#112400)
gh-94722: fix DocTest.__eq__ for case of no line number on one side (GH-112385)
(cherry picked from commit fbb9027a03
)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
44eb329490
commit
e93af80749
3 changed files with 23 additions and 2 deletions
|
@ -575,9 +575,11 @@ class DocTest:
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if not isinstance(other, DocTest):
|
if not isinstance(other, DocTest):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return ((self.name, self.filename, self.lineno, id(self))
|
self_lno = self.lineno if self.lineno is not None else -1
|
||||||
|
other_lno = other.lineno if other.lineno is not None else -1
|
||||||
|
return ((self.name, self.filename, self_lno, id(self))
|
||||||
<
|
<
|
||||||
(other.name, other.filename, other.lineno, id(other)))
|
(other.name, other.filename, other_lno, id(other)))
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
## 3. DocTestParser
|
## 3. DocTestParser
|
||||||
|
|
|
@ -414,6 +414,23 @@ Compare `DocTest`:
|
||||||
False
|
False
|
||||||
>>> test != other_test
|
>>> test != other_test
|
||||||
True
|
True
|
||||||
|
>>> test < other_test
|
||||||
|
False
|
||||||
|
>>> other_test < test
|
||||||
|
True
|
||||||
|
|
||||||
|
Test comparison with lineno None on one side
|
||||||
|
|
||||||
|
>>> no_lineno = parser.get_doctest(docstring, globs, 'some_test',
|
||||||
|
... 'some_test', None)
|
||||||
|
>>> test.lineno is None
|
||||||
|
False
|
||||||
|
>>> no_lineno.lineno is None
|
||||||
|
True
|
||||||
|
>>> test < no_lineno
|
||||||
|
False
|
||||||
|
>>> no_lineno < test
|
||||||
|
True
|
||||||
|
|
||||||
Compare `DocTestCase`:
|
Compare `DocTestCase`:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix bug where comparison between instances of :class:`~doctest.DocTest` fails if
|
||||||
|
one of them has ``None`` as its lineno.
|
Loading…
Add table
Add a link
Reference in a new issue