[Asterisk-code-review] matcher.py: Always check final conditions (testsuite[15])

Jenkins2 asteriskteam at digium.com
Thu Jun 28 07:23:10 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/9280 )

Change subject: matcher.py: Always check final conditions
......................................................................

matcher.py: Always check final conditions

The matcher functionality was checking the final conditions only if the test
was marked as passed. Since the initial default value for the test_case
variable is 'None' this could cause the test to fail, but without error messages
output.

This patch makes it so the final condtions in matcher are always checked when
the test ends. Also if all final conditions pass then the test object is set
to passing (passed=true). Lastly the error message output was updated to make
it a little more readable.

Change-Id: Ibdd3041e8fb023b9396d80ec766ade934e50bcaa
---
M lib/python/asterisk/matcher.py
M lib/python/asterisk/self_test/test2_matcher.py
2 files changed, 17 insertions(+), 22 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/lib/python/asterisk/matcher.py b/lib/python/asterisk/matcher.py
index 87c62be..3ab9c24 100644
--- a/lib/python/asterisk/matcher.py
+++ b/lib/python/asterisk/matcher.py
@@ -128,9 +128,13 @@
     def error(self):
         """Error out the conditional."""
 
-        return ("\nCondition: '{0}'\nExpected >= {1} and <= {2} but "
-                "received {3}".format(self.pattern, self.minimum,
-                                      self.maximum, self.count))
+        if self.minimum == self.maximum:
+            expected = "{0}".format(self.minimum)
+        else:
+            expected = ">= {0} and <= {1}".format(self.minimum, self.maximum)
+
+        return ("\nCondition: '{0}'\nExpected {1} but received {2}".format(
+            self.pattern, expected, self.count))
 
 
 class Conditions(object):
@@ -272,13 +276,14 @@
             return self.conditions.check(value)
         except ConditionError as e:
             self.fail_and_stop(e)
+        return False
 
     def check_final(self):
-        if self.test_object.passed:
-            try:
-                self.conditions.check_final()
-            except ConditionError as e:
-                self.fail_and_stop(e)
+        try:
+            self.test_object.set_passed(self.conditions.check_final())
+        except ConditionError as e:
+            self.fail_and_stop(e)
+
         return self.test_object.passed
 
     def __handle_stop(self, *args):
diff --git a/lib/python/asterisk/self_test/test2_matcher.py b/lib/python/asterisk/self_test/test2_matcher.py
index 0357ce9..b132353 100755
--- a/lib/python/asterisk/self_test/test2_matcher.py
+++ b/lib/python/asterisk/self_test/test2_matcher.py
@@ -110,18 +110,16 @@
         self.assertFalse(conditions.check_final())
 
         # Check with one message handled
-        self.test_object.set_passed(True)
         self.assertFalse(conditions.check('hello'))
         self.assertFalse(conditions.check_final())
 
         # Check with two messages handled
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('hello'))
         self.assertTrue(conditions.check_final())
 
         # Check with three messages handled
         self.assertFalse(conditions.check('hello'))
-        self.assertFalse(conditions.check_final())
+        self.assertTrue(conditions.check_final())  # min met
 
     def test_005_count(self):
         """Test range count condition"""
@@ -138,12 +136,10 @@
         self.assertFalse(conditions.check_final())
 
         # Check with one message handled
-        self.test_object.set_passed(True)
         self.assertFalse(conditions.check('hello'))
         self.assertFalse(conditions.check_final())
 
         # Check with two messages handled
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('hello'))
         self.assertTrue(conditions.check_final())
 
@@ -154,7 +150,7 @@
 
         # Check with five messages handled
         self.assertFalse(conditions.check('hello'))
-        self.assertFalse(conditions.check_final())
+        self.assertTrue(conditions.check_final())  # min met
 
     def test_006_min(self):
         """Test minimum condition"""
@@ -171,12 +167,10 @@
         self.assertFalse(conditions.check_final())
 
         # Check with one message handled
-        self.test_object.set_passed(True)
         self.assertFalse(conditions.check('hello'))
         self.assertFalse(conditions.check_final())
 
         # Check with two messages handled
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('hello'))
         self.assertTrue(conditions.check_final())
 
@@ -200,7 +194,7 @@
 
         # Check with two messages handled
         self.assertFalse(conditions.check('hello'))
-        self.assertFalse(conditions.check_final())
+        self.assertTrue(conditions.check_final())  # min met
 
     def test_008_max(self):
         """Test no match condition"""
@@ -218,7 +212,7 @@
 
         # Check with one message handled
         self.assertFalse(conditions.check('hello'))
-        self.assertFalse(conditions.check_final())
+        self.assertTrue(conditions.check_final())  # min met
 
     def test_009_trigger_on_any(self):
         """Test trigger on any option"""
@@ -236,7 +230,6 @@
         self.assertFalse(conditions.check('world'))
         self.assertFalse(conditions.check_final())
 
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('hello'))  # 'hello' is met
         self.assertFalse(conditions.check_final())  # 'world' not me
 
@@ -245,7 +238,6 @@
         self.assertFalse(conditions.check('world'))
         self.assertFalse(conditions.check_final())
 
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('world'))  # 'world' is met
         self.assertFalse(conditions.check_final())  # 'hello' not met
 
@@ -265,11 +257,9 @@
         self.assertFalse(conditions.check('world'))
         self.assertFalse(conditions.check_final())
 
-        self.test_object.set_passed(True)
         self.assertFalse(conditions.check('hello'))  # 'world' not met
         self.assertFalse(conditions.check_final())
 
-        self.test_object.set_passed(True)
         self.assertTrue(conditions.check('world'))
         self.assertTrue(conditions.check_final())
 

-- 
To view, visit https://gerrit.asterisk.org/9280
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibdd3041e8fb023b9396d80ec766ade934e50bcaa
Gerrit-Change-Number: 9280
Gerrit-PatchSet: 3
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180628/0aa9f3b4/attachment-0001.html>


More information about the asterisk-code-review mailing list