Extend specs matcher to support ">" and "<"
This patch is exteding the specs matcher and adding support for the ">" and "<" operators. Prior to this patch, only the "equal" forms were supported (">=" and "<="). It also looks inconsistent because for the "s" prefixed operators all the 4 forms are supported already: "s<=", "s<", "s>=" and "s>". Change-Id: I82a72b0ef6ee277e7b09b0eb138e058687ce8804
This commit is contained in:
parent
c5918adcea
commit
f43d78d358
@ -28,8 +28,10 @@ op_methods = {
|
|||||||
# More sane ops/methods
|
# More sane ops/methods
|
||||||
'!=': lambda x, y: float(x) != float(y),
|
'!=': lambda x, y: float(x) != float(y),
|
||||||
'<=': lambda x, y: float(x) <= float(y),
|
'<=': lambda x, y: float(x) <= float(y),
|
||||||
|
'<': lambda x, y: float(x) < float(y),
|
||||||
'==': lambda x, y: float(x) == float(y),
|
'==': lambda x, y: float(x) == float(y),
|
||||||
'>=': lambda x, y: float(x) >= float(y),
|
'>=': lambda x, y: float(x) >= float(y),
|
||||||
|
'>': lambda x, y: float(x) > float(y),
|
||||||
's!=': operator.ne,
|
's!=': operator.ne,
|
||||||
's<': operator.lt,
|
's<': operator.lt,
|
||||||
's<=': operator.le,
|
's<=': operator.le,
|
||||||
@ -52,6 +54,7 @@ def make_grammar():
|
|||||||
Literal("==") | Literal("=") |
|
Literal("==") | Literal("=") |
|
||||||
Literal("!=") | Literal("<in>") |
|
Literal("!=") | Literal("<in>") |
|
||||||
Literal(">=") | Literal("<=") |
|
Literal(">=") | Literal("<=") |
|
||||||
|
Literal(">") | Literal("<") |
|
||||||
Literal("s==") | Literal("s!=") |
|
Literal("s==") | Literal("s!=") |
|
||||||
# Order matters here (so that '<' doesn't match before '<=')
|
# Order matters here (so that '<' doesn't match before '<=')
|
||||||
Literal("s<=") | Literal("s<") |
|
Literal("s<=") | Literal("s<") |
|
||||||
|
@ -47,7 +47,7 @@ class SpecsMatcherTestCase(test_base.BaseTestCase):
|
|||||||
def test_specs_fails_with_bogus_ops(self):
|
def test_specs_fails_with_bogus_ops(self):
|
||||||
self._do_specs_matcher_test(
|
self._do_specs_matcher_test(
|
||||||
value='4',
|
value='4',
|
||||||
req='> 2',
|
req='! 2',
|
||||||
matches=False)
|
matches=False)
|
||||||
|
|
||||||
def test_specs_matches_with_op_eq(self):
|
def test_specs_matches_with_op_eq(self):
|
||||||
@ -266,6 +266,42 @@ class SpecsMatcherTestCase(test_base.BaseTestCase):
|
|||||||
req='>= 3',
|
req='>= 3',
|
||||||
matches=True)
|
matches=True)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_g(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='3',
|
||||||
|
req='> 1',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_g2(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='3',
|
||||||
|
req='> 3',
|
||||||
|
matches=False)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_g3(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='3.0',
|
||||||
|
req='> 2',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_l(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='3',
|
||||||
|
req='< 5',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_l2(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='3',
|
||||||
|
req='< 3',
|
||||||
|
matches=False)
|
||||||
|
|
||||||
|
def test_specs_matches_with_op_l3(self):
|
||||||
|
self._do_specs_matcher_test(
|
||||||
|
value='1.0',
|
||||||
|
req='< 6',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
def test_specs_fails_with_op_ge(self):
|
def test_specs_fails_with_op_ge(self):
|
||||||
self._do_specs_matcher_test(
|
self._do_specs_matcher_test(
|
||||||
value='2',
|
value='2',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user