-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathassertions.py
More file actions
26 lines (23 loc) · 797 Bytes
/
Copy pathassertions.py
File metadata and controls
26 lines (23 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
def assert_unavailable(fun, *args):
import cql
try:
if len(args) == 0:
fun(None)
else:
fun(*args)
except cql.OperationalError as e:
msg = str(e)
assert re.search('one or more nodes were unavailable', msg), "Expecting unavailable exception, got: " + msg
except Exception as e:
assert False, "Expecting unavailable exception, got: " + str(e)
else:
assert False, "Expecting unavailable exception but no exception was raised"
def assert_almost_equal(*args, **kwargs):
try:
error = kwargs['error']
except KeyError:
error = 0.1
vmax = max(args)
vmin = min(args)
assert vmin > vmax * (1.0 - error), "values not within %.2f%% of the max: %s" % (error * 100, args)