10000 Issue #126: fix undefined behaviour of C-Python tests · stackless-dev/stackless@afa7916 · GitHub
[go: up one dir, main page]

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

Commit afa7916

Browse files
author
Anselm Kruis
committed
Issue #126: fix undefined behaviour of C-Python tests
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/126
1 parent ae1d0a4 commit afa7916

File tree

6 files changed

+20
-33
lines changed

6 files changed

+20
-33
lines changed

Lib/test/pickletester.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from test.support import (
1111
TestFailed, TESTFN, run_with_locale, no_tracing,
12-
_2G, _4G, bigmemtest,
12+
_2G, _4G, bigmemtest, stackless,
1313
)
1414

1515
from pickle import bytes_types
@@ -393,12 +393,11 @@ def create_dynamic_class(name, bases):
393393

394394
# xrange(5) pickled from 2.x with protocol 2
395395
DATA4 = b'\x80\x02c__builtin__\nxrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02.'
396-
try:
397-
import stackless
396+
if stackless:
398397
DATA4_SLP = b'\x80\x02cstackless._wrap\nrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02)b.'
399-
except:
398+
else:
400399
DATA4_SLP = DATA4
401-
400+
402401

403402
# a SimpleCookie() object pickled from 2.x with protocol 2
404403
DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key'
@@ -1222,9 +1221,7 @@ def test_unpickle_from_2x(self):
12221221
loaded = self.loads(DATA3)
12231222
self.assertEqual(loaded, set([1, 2]))
12241223
loaded = self.loads(DATA4_SLP)
1225-
try:
1226-
import stackless
1227-
except ImportError:
1224+
if not stackless:
12281225
self.assertEqual(type(loaded), type(range(0)))
12291226
else:
12301227
pass # stackless provides a fake range for unpickling

Lib/test/support/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
import struct
2727
import tempfile
2828

29+
try:
30+
import stackless
31+
except ImportError:
32+
stackless = None
33+
2934
try:
3035
import _thread, threading
3136
except ImportError:

Lib/test/test_multiprocessing.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
import test.support
2222
import test.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')
@@ -1812,8 +1806,8 @@ def errback(exc):
18121806
p.close()
18131807
p.join()
18141808

1815-
@unittest.skipIf(usingStackless, "Stackless can pickle lambdas")
1816-
def test_unpickleable_result(self):
1809+
@unittest.skipIf(test.support.stackless, "Stackless can pickle lambdas")
1810+
def test_unpickleable_result(self):
18171811
from multiprocessing.pool import MaybeEncodingError
18181812
p = multiprocessing.Pool(2)
18191813

Lib/test/test_pep352.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import builtins
33
import warnings
4-
from test.support import run_unittest
4+
from test.support import run_unittest, stackless
55
import os
66
from platform import system as platform_system
77

@@ -32,11 +32,6 @@ def test_inheritance(self):
3232

3333
inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
3434
'exception_hierarchy.txt'))
35-
try:
36-
import stackless
37-
haveStackless = True
38-
except:
39-
haveStackless = False
4035
try:
4136
superclass_name = inheritance_tree.readline().rstrip()
4237
try:
@@ -62,7 +57,7 @@ def test_inheritance(self):
6257
if '[' in exc_name:
6358
left_bracket = exc_name.index('[')
6459
exc_name = exc_name[:left_bracket-1] # cover space
65-
if not haveStackless and exc_name == "TaskletExit":
60+
if stackless is None and exc_name == "TaskletExit":
6661
exc_set.discard(exc_name)
6762
continue
6863
try:

Lib/test/test_sys.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,7 @@ def inner():
665665
import collections
666666
check(collections.defaultdict.default_factory, size('3PP'))
667667
# wrapper_descriptor (descriptor object)
668-
try:
669-
import stackless
670-
slxtra = 'i'
671-
except:
672-
slxtra = ''
668+
slxtra = 'i' if test.support.stackless else ''
673669
check(int.__add__, size('3P2P' + slxtra))
674670
# method-wrapper (descriptor object)
675671
check({}.__iter__, size('2P'))
@@ -718,11 +714,7 @@ class C(object): pass
718714
nfrees = len(x.f_code.co_freevars)
719715
extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\
720716
ncells + nfrees - 1
721-
try:
722-
import stackless
723-
slextra = 'P'
724-
except:
725-
slextra = ''
717+
slextra = 'P' if test.support.stackless else ''
726718
check(x, vsize('12P3i' + CO_MAXBLOCKS*'3i' + slextra + 'P' + extras*'P'))
727719
# function
728720
def func(): pass

Stackless/changelog.txt

Lines changed: 4 additions & 0 deletions
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)
0