Skip to content

Commit 23bbaea

Browse files
changed switch_session() to only assign new active session as last step and raise more SessionError wrappers for exceptions from custom switch and close funcs
--HG-- branch : draft
1 parent 633bd6b commit 23bbaea

3 files changed

Lines changed: 90 additions & 78 deletions

File tree

robottools/library/session/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def switch_session(cls, name):
6363
"""
6464
name = str(name)
6565
try:
66-
session = cls.session = cls.sessions[name]
66+
session = cls.sessions[name]
6767
except KeyError:
6868
raise cls.SessionError('Session not found: %s' % repr(name))
6969
return session

robottools/library/session/meta.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import re
3030
from copy import deepcopy
3131

32-
from moretools import dictitems
32+
from moretools import qualname, dictitems
3333

3434
from robottools.library.keywords import KeywordsDict
3535
from .metaoptions import Meta
@@ -190,9 +190,21 @@ def switch_session(self, name):
190190
if session is previous:
191191
break
192192
else:
193-
close_func(self, previous)
193+
try:
194+
close_func(self, previous)
195+
except Exception as exc:
196+
raise cls.SessionError(
197+
"Couldn't close unnamed session "
198+
"on switching to %s (%s: %s)"
199+
% (repr(name), qualname(type(exc)), exc))
194200
if switch_func:
195-
switch_func(self, active)
201+
try:
202+
switch_func(self, active)
203+
except Exception as exc:
204+
raise cls.SessionError(
205+
"Couldn't switch session to %s (%s: %s)"
206+
% (repr(name), qualname(type(exc)), exc))
207+
cls.session = active
196208

197209
keywordname = 'switch_' + meta.identifier_name
198210
cls.keywords[keywordname] = switch_session

setup.py

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
# This file was auto-generated by zetup
2-
#
3-
# https://bitbucket.org/userzimmermann/zetup.py
4-
5-
6-
7-
from __future__ import print_function
8-
9-
import sys
10-
import os
11-
import re
12-
try:
13-
from setuptools import setup
14-
except ImportError:
15-
from distutils.core import setup
16-
17-
18-
SETUP_REQUIRES = [
19-
'zetup >= 0.2.31',
20-
21-
] + (os.path.exists('requirements.setup.txt')
22-
and [line for line in map(str.strip, open('requirements.setup.txt'))
23-
if line and not line.startswith('#')]
24-
or []) + [
25-
]
26-
27-
28-
try:
29-
from setuptools.dist import Distribution
30-
from pkg_resources import get_distribution, working_set, \
31-
DistributionNotFound, VersionConflict
32-
except ImportError: # no setuptools
33-
pass
34-
else:
35-
# make sure that setup requirements
36-
# are always correctly resolved and accessible by:
37-
# - pre-processing them one after another
38-
# - recursively resolving their runtime requirements
39-
# - moving any installed eggs to the front of sys.path
40-
# - updating pkg_resources.working_set accordingly
41-
42-
installer = Distribution().fetch_build_egg
43-
44-
# don't pollute stdout
45-
stdout = sys.__stdout__
46-
sys.stdout = sys.__stdout__ = sys.__stderr__
47-
48-
def resolve(requirements, parent=None):
49-
for req in requirements:
50-
qualreq = parent and '%s->%s' % (req, parent) or req
51-
print("Resolving setup requirement %s:" % qualreq)
52-
try:
53-
dist = get_distribution(req)
54-
print(repr(dist))
55-
except (DistributionNotFound, VersionConflict):
56-
dist = installer(req)
57-
sys.path.insert(0, dist.location)
58-
working_set.entries.insert(0, dist.location)
59-
working_set.by_key[dist.key] = dist
60-
extras = re.match(r'[^#\[]*\[([^#\]]*)\]', req)
61-
if extras:
62-
extras = list(map(str.strip, extras.group(1).split(',')))
63-
resolve(map(str, dist.requires(extras=extras or ())), qualreq)
64-
65-
resolve(SETUP_REQUIRES)
66-
sys.stdout = sys.__stdout__ = stdout
67-
68-
69-
dist = setup(
70-
71-
setup_requires=SETUP_REQUIRES,
72-
73-
use_zetup=True,
74-
1+
# This file was auto-generated by zetup
2+
#
3+
# https://bitbucket.org/userzimmermann/zetup.py
4+
5+
6+
7+
from __future__ import print_function
8+
9+
import sys
10+
import os
11+
import re
12+
try:
13+
from setuptools import setup
14+
except ImportError:
15+
from distutils.core import setup
16+
17+
18+
SETUP_REQUIRES = [
19+
'zetup >= 0.2.31',
20+
21+
] + (os.path.exists('requirements.setup.txt')
22+
and [line for line in map(str.strip, open('requirements.setup.txt'))
23+
if line and not line.startswith('#')]
24+
or []) + [
25+
]
26+
27+
28+
try:
29+
from setuptools.dist import Distribution
30+
from pkg_resources import get_distribution, working_set, \
31+
DistributionNotFound, VersionConflict
32+
except ImportError: # no setuptools
33+
pass
34+
else:
35+
# make sure that setup requirements
36+
# are always correctly resolved and accessible by:
37+
# - pre-processing them one after another
38+
# - recursively resolving their runtime requirements
39+
# - moving any installed eggs to the front of sys.path
40+
# - updating pkg_resources.working_set accordingly
41+
42+
installer = Distribution().fetch_build_egg
43+
44+
# don't pollute stdout
45+
stdout = sys.__stdout__
46+
sys.stdout = sys.__stdout__ = sys.__stderr__
47+
48+
def resolve(requirements, parent=None):
49+
for req in requirements:
50+
qualreq = parent and '%s->%s' % (req, parent) or req
51+
print("Resolving setup requirement %s:" % qualreq)
52+
try:
53+
dist = get_distribution(req)
54+
print(repr(dist))
55+
except (DistributionNotFound, VersionConflict):
56+
dist = installer(req)
57+
sys.path.insert(0, dist.location)
58+
working_set.entries.insert(0, dist.location)
59+
working_set.by_key[dist.key] = dist
60+
extras = re.match(r'[^#\[]*\[([^#\]]*)\]', req)
61+
if extras:
62+
extras = list(map(str.strip, extras.group(1).split(',')))
63+
resolve(map(str, dist.requires(extras=extras or ())), qualreq)
64+
65+
resolve(SETUP_REQUIRES)
66+
sys.stdout = sys.__stdout__ = stdout
67+
68+
69+
dist = setup(
70+
71+
setup_requires=SETUP_REQUIRES,
72+
73+
use_zetup=True,
74+
7575
)

0 commit comments

Comments
 (0)