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:
Lucas Alvares Gomes 2016-07-27 17:06:50 +01:00
parent c5918adcea
commit f43d78d358
2 changed files with 40 additions and 1 deletions

View File

@ -28,8 +28,10 @@ op_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),
's!=': operator.ne,
's<': operator.lt,
's<=': operator.le,
@ -52,6 +54,7 @@ def make_grammar():
Literal("==") | Literal("=") |
Literal("!=") | Literal("<in>") |
Literal(">=") | Literal("<=") |
Literal(">") | Literal("<") |
Literal("s==") | Literal("s!=") |
# Order matters here (so that '<' doesn't match before '<=')
Literal("s<=") | Literal("s<") |

View File

@ -47,7 +47,7 @@ class SpecsMatcherTestCase(test_base.BaseTestCase):
def test_specs_fails_with_bogus_ops(self):
self._do_specs_matcher_test(
value='4',
req='> 2',
req='! 2',
matches=False)
def test_specs_matches_with_op_eq(self):
@ -266,6 +266,42 @@ class SpecsMatcherTestCase(test_base.BaseTestCase):
req='>= 3',
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):
self._do_specs_matcher_test(
value='2',