Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 29476f5

Browse files
author
Anselm Kruis
committed
merge 3.4-slp (Stackless #126, fix C-Python tests)
2 parents 470e792 + 131beaf commit 29476f5

File tree

7 files changed

+20
-38
lines changed

7 files changed

+20
-38
lines changed

Lib/test/_test_multiprocessing.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
import test.support
2222
import test.support.script_helper
2323

24-
try:
25-
import stackless
26-
usingStackless = True
27-
except ImportError:
28-
usingStackless = False
29-
3024

3125
# Skip tests if _multiprocessing wasn't built.
3226
_multiprocessing = test.support.import_module('_multiprocessing')
@@ -1931,7 +1925,7 @@ def errback(exc):
19311925
p.close()
19321926
p.join()
19331927

1934-
@unittest.skipIf(usingStackless, "Stackless can pickle lambdas")
1928+
@unittest.skipIf(test.support.stackless, "Stackless can pickle lambdas")
19351929
def test_unpickleable_result(self):
19361930
from multiprocessing.pool import MaybeEncodingError
19371931
p = multiprocessing.Pool(2)

Lib/test/pickletester.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from test.support import (
1515
TestFailed, TESTFN, run_with_locale, no_tracing,
16-
_2G, _4G, bigmemtest,
16+
_2G, _4G, bigmemtest, stackless,
1717
)
1818

1919
from pickle import bytes_types
@@ -403,12 +403,9 @@ def create_dynamic_class(name, bases):
403403

404404
# xrange(5) pickled from 2.x with protocol 2
405405
DATA4 = b'\x80\x02c__builtin__\nxrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02.'
406-
try:
407-
import stackless
408-
has_stackless = True
406+
if stackless:
409407
DATA4_SLP = b'\x80\x02cstackless._wrap\nrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02)b.'
410-
except ImportError:
411-
has_stackless = False
408+
else:
412409
DATA4_SLP = DATA4
413410

414411

@@ -1348,7 +1345,7 @@ def test_unpickle_from_2x(self):
13481345
loaded = self.loads(DATA3)
13491346
self.assertEqual(loaded, set([1, 2]))
13501347
loaded = self.loads(DATA4_SLP)
1351-
if not has_stackless:
1348+
if not stackless:
13521349
# stackless provides a fake range for unpickling
13531350
self.assertEqual(type(loaded), type(range(0)))
13541351
self.assertEqual(list(loaded), list(range(5)))
@@ -1774,7 +1771,7 @@ def test_compat_unpickle(self):
17741771
def test_local_lookup_error(self):
17751772
# Test that whichmodule() errors out cleanly when looking up
17761773
# an assumed globally-reachable object fails.
1777-
if has_stackless:
1774+
if stackless:
17781775
self.skipTest("Stackless can pickle functions by value")
17791776
def f():
17801777
pass

Lib/test/support/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
import urllib.error
3131
import warnings
3232

33+
try:
34+
import stackless
35+
except ImportError:
36+
stackless = None
37+
3338
try:
3439
import _thread, threading
3540
except ImportError:

Lib/test/test_pep352.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import warnings
44
import os
55
from platform import system as platform_system
6+
from test.support import stackless
67

78

89
class ExceptionClassTests(unittest.TestCase):
@@ -31,11 +32,6 @@ def test_inheritance(self):
3132

3233
inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
3334
'exception_hierarchy.txt'))
34-
try:
35-
import stackless
36-
haveStackless = True
37-
except:
38-
haveStackless = False
3935
try:
4036
superclass_name = inheritance_tree.readline().rstrip()
4137
try:
@@ -61,7 +57,7 @@ def test_inheritance(self):
6157
if '[' in exc_name:
6258
left_bracket = exc_name.index('[')
6359
exc_name = exc_name[:left_bracket-1] # cover space
64-
if not haveStackless and exc_name == "TaskletExit":
60+
if stackless is None and exc_name == "TaskletExit":
6561
exc_set.discard(exc_name)
6662
continue
6763
try:

Lib/test/test_pickle.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
except ImportError:
2424
has_c_implementation = False
2525

26-
try:
27-
import stackless
28-
has_stackless = True
29-
except ImportError:
30-
has_stackless = False
31-
3226

3327
class PickleTests(AbstractPickleModuleTests):
3428
pass
@@ -156,7 +150,7 @@ class SizeofTests(unittest.TestCase):
156150

157151
def test_pickler(self):
158152
basesize = support.calcobjsize('5P2n3i2n3iP' +
159-
('P' if has_stackless else ''))
153+
('P' if support.stackless else ''))
160154
p = _pickle.Pickler(io.BytesIO())
161155
self.assertEqual(object.__sizeof__(p), basesize)
162156
MT_size = struct.calcsize('3nP0n')

Lib/test/test_sys.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,7 @@ def inner():
877877
import collections
878878
check(collections.defaultdict.default_factory, size('3PP'))
879879
# wrapper_descriptor (descriptor object)
880-
try:
881-
import stackless
882-
slxtra = 'i'
883-
except:
884-
slxtra = ''
880+
slxtra = 'i' if test.support.stackless else ''
885881
check(int.__add__, size('3P2P' + slxtra))
886882
# method-wrapper (descriptor object)
887883
check({}.__iter__, size('2P'))
@@ -930,11 +926,7 @@ class C(object): pass
930926
nfrees = len(x.f_code.co_freevars)
931927
extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\
932928
ncells + nfrees - 1
933-
try:
934-
import stackless
935-
slextra = 'P'
936-
except:
937-
slextra = ''
929+
slextra = 'P' if test.support.stackless else ''
938930
check(x, vsize('12P3ic' + CO_MAXBLOCKS*'3i' + slextra + 'P' + extras*'P'))
939931
# function
940932
def func(): pass

Stackless/changelog.txt

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://bitbucket.org/stackless-dev/stackless/issues/126
13+
Load the module stackless early in all C-Python tests. This ensures a defined
14+
behaviour of the tests even, if the execution order gets randomised.
15+
1216
- https://bitbucket.org/stackless-dev/stackless/issues/125
1317
This document (changelog.txt) is included in the documentation as
1418
"What’s New in Stackless-Python ..."

0 commit comments

Comments
 (0)