Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions test/pickle1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
1
>>> pickle1_ext.world.__name__
'world'
>>> pickle1_ext.world('Hello').__reduce__()
>>> pickle1_ext.world('Hello').__reduce__() # doctest: +PY310
(<class 'pickle1_ext.world'>, ('Hello',))
>>> pickle1_ext.world('Hello').__reduce__() # doctest: +PY311
(<class 'pickle1_ext.world'>, ('Hello',), None)
>>> wd = pickle1_ext.world('California')
>>> pstr = pickle.dumps(wd)
>>> wl = pickle.loads(pstr)
Expand All @@ -31,7 +33,27 @@ def run(args = None):

if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))

# > https://docs.python.org/3.11/library/pickle.html#object.__reduce__
# object.__reduce__() returns
# - python 3.10 or prior: a 2-element tuple
# - python 3.11 or later: a 3-element tuple (object's state added)
PY310 = doctest.register_optionflag("PY310")
PY311 = doctest.register_optionflag("PY311")

class ConditionalChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if (optionflags & PY311) and (sys.version_info[:2] < (3, 11)):
return True
if (optionflags & PY310) and (sys.version_info[:2] >= (3, 11)):
return True
return doctest.OutputChecker.check_output(self, want, got, optionflags)

runner = doctest.DocTestRunner(ConditionalChecker())
for test in doctest.DocTestFinder().find(sys.modules.get(__name__)):
runner.run(test)

return doctest.TestResults(runner.failures, runner.tries)

if __name__ == '__main__':
print("running...")
Expand Down
26 changes: 24 additions & 2 deletions test/pickle4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
1
>>> pickle4_ext.world.__name__
'world'
>>> pickle4_ext.world('Hello').__reduce__()
>>> pickle4_ext.world('Hello').__reduce__() # doctest: +PY310
(<class 'pickle4_ext.world'>, ('Hello',))
>>> pickle4_ext.world('Hello').__reduce__() # doctest: +PY311
(<class 'pickle4_ext.world'>, ('Hello',), None)
>>> wd = pickle4_ext.world('California')
>>> pstr = pickle.dumps(wd)
>>> wl = pickle.loads(pstr)
Expand All @@ -29,7 +31,27 @@ def run(args = None):

if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))

# > https://docs.python.org/3.11/library/pickle.html#object.__reduce__
# object.__reduce__() returns
# - python 3.10 or prior: a 2-element tuple
# - python 3.11 or later: a 3-element tuple (object's state added)
PY310 = doctest.register_optionflag("PY310")
PY311 = doctest.register_optionflag("PY311")

class ConditionalChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if (optionflags & PY311) and (sys.version_info[:2] < (3, 11)):
return True
if (optionflags & PY310) and (sys.version_info[:2] >= (3, 11)):
return True
return doctest.OutputChecker.check_output(self, want, got, optionflags)

runner = doctest.DocTestRunner(ConditionalChecker())
for test in doctest.DocTestFinder().find(sys.modules.get(__name__)):
runner.run(test)

return doctest.TestResults(runner.failures, runner.tries)

if __name__ == '__main__':
print("running...")
Expand Down
Loading