Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
c00d94c7
Commit
c00d94c7
authored
Jun 03, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X workaround lack of exception chaining on Python2 with xdefer
parent
49e73a6d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
20 deletions
+41
-20
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+41
-20
No files found.
wcfs/wcfs_test.py
View file @
c00d94c7
...
...
@@ -33,7 +33,7 @@ from persistent import Persistent
from
persistent.timestamp
import
TimeStamp
from
ZODB.utils
import
z64
import
os
,
os
.
path
,
subprocess
,
threading
import
sys
,
os
,
os
.
path
,
subprocess
,
threading
,
inspect
,
traceback
from
errno
import
EINVAL
from
golang
import
chan
,
func
,
defer
,
select
from
golang
import
context
,
sync
,
time
...
...
@@ -76,6 +76,36 @@ def teardown_function(f):
os
.
rmdir
(
testmntpt
)
# xdefer is like defer, but makes sure exception raised before deferred
# function is called is not lost.
#
# if deferred function raises exception itself - it prints previous exception to stderr.
#
# XXX xdefer is workaround for Python2 not having exception chanining (PEP 3134)
# without which, if e.g. tDB.close() raises exception, it prevents to see
# whether and which an assert in the test failed.
#
# XXX merge into defer?
def
xdefer
(
f
):
# hack - imitate as if defer called from under xdefer was called directly by caller func
fgo
=
inspect
.
currentframe
().
f_back
.
f_back
__goframe__
=
fgo
.
f_locals
[
'__goframe__'
]
_xdefer
(
f
)
def
_xdefer
(
f
):
def
_
():
# call f, but print previous exception if f raises
exc_type
,
exc_value
,
exc_traceback
=
sys
.
exc_info
()
try
:
f
()
except
:
traceback
.
print_exception
(
exc_type
,
exc_value
,
exc_traceback
)
raise
defer
(
_
)
# ---- test join/autostart ----
# test that zurl does not change from one open to another storage open.
...
...
@@ -94,14 +124,14 @@ def test_join():
wcfs
.
join
(
zurl
,
autostart
=
False
)
wc
=
wcfs
.
_start
(
zurl
)
defer
(
wc
.
close
)
x
defer
(
wc
.
close
)
assert
wc
.
mountpoint
==
testmntpt
assert
readfile
(
wc
.
mountpoint
+
"/.wcfs/zurl"
)
==
zurl
assert
os
.
path
.
isdir
(
wc
.
mountpoint
+
"/head"
)
assert
os
.
path
.
isdir
(
wc
.
mountpoint
+
"/head/bigfile"
)
wc2
=
wcfs
.
join
(
zurl
,
autostart
=
False
)
defer
(
wc2
.
close
)
x
defer
(
wc2
.
close
)
assert
wc2
.
mountpoint
==
wc
.
mountpoint
# test that join(autostart=y) works.
...
...
@@ -112,7 +142,7 @@ def test_join_autostart():
wcfs
.
join
(
zurl
,
autostart
=
False
)
wc
=
wcfs
.
join
(
zurl
,
autostart
=
True
)
defer
(
wc
.
close
)
x
defer
(
wc
.
close
)
assert
wc
.
mountpoint
==
testmntpt
assert
readfile
(
wc
.
mountpoint
+
"/.wcfs/zurl"
)
==
zurl
assert
os
.
path
.
isdir
(
wc
.
mountpoint
+
"/head"
)
...
...
@@ -764,12 +794,11 @@ def _expectPin(w, ctx, zf, expect):
return
reqv
# test_wcfs exercises wcfs functionality.
@
func
def
test_wcfs
():
t
=
tDB
()
defer
(
t
.
close
)
x
defer
(
t
.
close
)
t
.
root
[
'!file'
]
=
nonfile
=
Persistent
()
t
.
root
[
'zfile'
]
=
zf
=
ZBigFile
(
blksize
)
...
...
@@ -850,11 +879,7 @@ def test_wcfs():
# XXX -> separate test?
w
=
t
.
openwatch
()
print
(
'
\
n
\
n
zzzzzzz
\
n
\
n
'
)
try
:
assert
w
.
sendReq
(
context
.
background
(),
b'bla bla'
)
==
""
except
:
#import traceback; traceback.print_exc()
raise
assert
w
.
sendReq
(
context
.
background
(),
b'bla bla'
)
==
""
# assert w closed
print
(
'
\
n
\
n
0000000
\
n
\
n
'
)
...
...
@@ -919,21 +944,17 @@ def test_wcfs():
@
func
def
test_wcfs_invproto
():
# XXX temp debug
import
sys
,
traceback
"""
def
_
():
print
(
'BBB'
)
1
/
0
defer(_)
"""
xdefer
(
_
)
#raise RuntimeError('zzz')
try
:
print
(
'
\
n
AAA'
)
assert
1
==
2
finally
:
2
/
0
print
(
'
\
n
AAA'
)
assert
1
==
2
# ---- misc ---
...
...
@@ -957,7 +978,7 @@ def tidtime(tid):
@
func
def
test_tidtime_notrough
():
t
=
tDB
()
defer
(
t
.
close
)
x
defer
(
t
.
close
)
atprev
=
t
.
commit
()
for
i
in
range
(
10
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment