Skip to content

Commit

Permalink
Merge 3.5-slp (Stackless python#126, fix C-Python tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselm Kruis committed Oct 5, 2017
2 parents 0ae6c0f + 29476f5 commit 7cfb797
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 38 deletions.
8 changes: 1 addition & 7 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
import test.support
import test.support.script_helper

try:
import stackless
usingStackless = True
except ImportError:
usingStackless = False


# Skip tests if _multiprocessing wasn't built.
_multiprocessing = test.support.import_module('_multiprocessing')
Expand Down Expand Up @@ -1931,7 +1925,7 @@ def errback(exc):
p.close()
p.join()

@unittest.skipIf(usingStackless, "Stackless can pickle lambdas")
@unittest.skipIf(test.support.stackless, "Stackless can pickle lambdas")
def test_unpickleable_result(self):
from multiprocessing.pool import MaybeEncodingError
p = multiprocessing.Pool(2)
Expand Down
13 changes: 5 additions & 8 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from test.support import (
TestFailed, TESTFN, run_with_locale, no_tracing,
_2G, _4G, bigmemtest,
_2G, _4G, bigmemtest, stackless,
)

from pickle import bytes_types
Expand Down Expand Up @@ -403,12 +403,9 @@ def create_dynamic_class(name, bases):

# xrange(5) pickled from 2.x with protocol 2
DATA4 = b'\x80\x02c__builtin__\nxrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02.'
try:
import stackless
has_stackless = True
if stackless:
DATA4_SLP = b'\x80\x02cstackless._wrap\nrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02)b.'
except ImportError:
has_stackless = False
else:
DATA4_SLP = DATA4


Expand Down Expand Up @@ -1348,7 +1345,7 @@ def test_unpickle_from_2x(self):
loaded = self.loads(DATA3)
self.assertEqual(loaded, set([1, 2]))
loaded = self.loads(DATA4_SLP)
if not has_stackless:
if not stackless:
# stackless provides a fake range for unpickling
self.assertEqual(type(loaded), type(range(0)))
self.assertEqual(list(loaded), list(range(5)))
Expand Down Expand Up @@ -1774,7 +1771,7 @@ def test_compat_unpickle(self):
def test_local_lookup_error(self):
# Test that whichmodule() errors out cleanly when looking up
# an assumed globally-reachable object fails.
if has_stackless:
if stackless:
self.skipTest("Stackless can pickle functions by value")
def f():
pass
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import urllib.error
import warnings

try:
import stackless
except ImportError:
stackless = None

try:
import _thread, threading
except ImportError:
Expand Down
8 changes: 2 additions & 6 deletions Lib/test/test_pep352.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings
import os
from platform import system as platform_system
from test.support import stackless


class ExceptionClassTests(unittest.TestCase):
Expand Down Expand Up @@ -31,11 +32,6 @@ def test_inheritance(self):

inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
'exception_hierarchy.txt'))
try:
import stackless
haveStackless = True
except:
haveStackless = False
try:
superclass_name = inheritance_tree.readline().rstrip()
try:
Expand All @@ -61,7 +57,7 @@ def test_inheritance(self):
if '[' in exc_name:
left_bracket = exc_name.index('[')
exc_name = exc_name[:left_bracket-1] # cover space
if not haveStackless and exc_name == "TaskletExit":
if stackless is None and exc_name == "TaskletExit":
exc_set.discard(exc_name)
continue
try:
Expand Down
8 changes: 1 addition & 7 deletions Lib/test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
except ImportError:
has_c_implementation = False

try:
import stackless
has_stackless = True
except ImportError:
has_stackless = False


class PickleTests(AbstractPickleModuleTests):
pass
Expand Down Expand Up @@ -156,7 +150,7 @@ class SizeofTests(unittest.TestCase):

def test_pickler(self):
basesize = support.calcobjsize('5P2n3i2n3iP' +
('P' if has_stackless else ''))
('P' if support.stackless else ''))
p = _pickle.Pickler(io.BytesIO())
self.assertEqual(object.__sizeof__(p), basesize)
MT_size = struct.calcsize('3nP0n')
Expand Down
12 changes: 2 additions & 10 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,11 +877,7 @@ def inner():
import collections
check(collections.defaultdict.default_factory, size('3PP'))
# wrapper_descriptor (descriptor object)
try:
import stackless
slxtra = 'i'
except:
slxtra = ''
slxtra = 'i' if test.support.stackless else ''
check(int.__add__, size('3P2P' + slxtra))
# method-wrapper (descriptor object)
check({}.__iter__, size('2P'))
Expand Down Expand Up @@ -930,11 +926,7 @@ class C(object): pass
nfrees = len(x.f_code.co_freevars)
extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\
ncells + nfrees - 1
try:
import stackless
slextra = 'P'
except:
slextra = ''
slextra = 'P' if test.support.stackless else ''
check(x, vsize('12P3ic' + CO_MAXBLOCKS*'3i' + slextra + 'P' + extras*'P'))
# function
def func(): pass
Expand Down
10 changes: 10 additions & 0 deletions Python/_warnings.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ is_internal_frame(PyFrameObject *frame)
Py_INCREF(bootstrap_string);
}

#ifdef STACKLESS
/* ignore any CFrame objects */
while (frame != NULL && !PyFrame_Check(frame))
frame = frame->f_back;
#endif
if (frame == NULL || frame->f_code == NULL ||
frame->f_code->co_filename == NULL) {
return 0;
Expand Down Expand Up @@ -567,6 +572,11 @@ next_external_frame(PyFrameObject *frame)
{
do {
frame = frame->f_back;
#ifdef STACKLESS
/* ignore any CFrame objects */
while (frame != NULL && !PyFrame_Check(frame))
frame = frame->f_back;
#endif
} while (frame != NULL && is_internal_frame(frame));

return frame;
Expand Down
4 changes: 4 additions & 0 deletions Stackless/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ What's New in Stackless 3.X.X?

*Release date: 20XX-XX-XX*

- https://bitbucket.org/stackless-dev/stackless/issues/126
Load the module stackless early in all C-Python tests. This ensures a defined
behaviour of the tests even, if the execution order gets randomised.

- https://bitbucket.org/stackless-dev/stackless/issues/125
This document (changelog.txt) is included in the documentation as
"What’s New in Stackless-Python ..."
Expand Down

0 comments on commit 7cfb797

Please sign in to comment.