diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-18 18:29:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-18 18:29:06 (GMT) |
commit | 92d4acb7a7f13fb785e9552ed486e301809008a5 (patch) | |
tree | e3bbee6f3f05e09f2a8091a6d02e8dc1d886ff6f /Lib/doctest.py | |
parent | 0f694d72a284ac656772806f09ea9bf454550a98 (diff) | |
parent | a74252633f2d86b3108b80c929583abd4193d7be (diff) | |
download | cpython-92d4acb7a7f13fb785e9552ed486e301809008a5.zip cpython-92d4acb7a7f13fb785e9552ed486e301809008a5.tar.gz cpython-92d4acb7a7f13fb785e9552ed486e301809008a5.tar.bz2 |
Issue #7502: Fix equality comparison for DocTestCase instances.
Patch by Cédric Krier.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 9d1501c..5d315cc 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -440,6 +440,21 @@ class Example: self.options = options self.exc_msg = exc_msg + def __eq__(self, other): + if type(self) is not type(other): + return NotImplemented + + return self.source == other.source and \ + self.want == other.want and \ + self.lineno == other.lineno and \ + self.indent == other.indent and \ + self.options == other.options and \ + self.exc_msg == other.exc_msg + + def __ne__(self, other): + return not self == other + + class DocTest: """ A collection of doctest examples that should be run in a single @@ -488,6 +503,19 @@ class DocTest: return ('<DocTest %s from %s:%s (%s)>' % (self.name, self.filename, self.lineno, examples)) + def __eq__(self, other): + if type(self) is not type(other): + return NotImplemented + + return self.examples == other.examples and \ + self.docstring == other.docstring and \ + self.globs == other.globs and \ + self.name == other.name and \ + self.filename == other.filename and \ + self.lineno == other.lineno + + def __ne__(self, other): + return not self == other # This lets us sort tests by name: def __lt__(self, other): @@ -2206,6 +2234,19 @@ class DocTestCase(unittest.TestCase): def id(self): return self._dt_test.name + def __eq__(self, other): + if type(self) is not type(other): + return NotImplemented + + return self._dt_test == other._dt_test and \ + self._dt_optionflags == other._dt_optionflags and \ + self._dt_setUp == other._dt_setUp and \ + self._dt_tearDown == other._dt_tearDown and \ + self._dt_checker == other._dt_checker + + def __ne__(self, other): + return not self == other + def __repr__(self): name = self._dt_test.name.split('.') return "%s (%s)" % (name[-1], '.'.join(name[:-1])) |