def test_010_trigger_on_all(self): """Test trigger on all option""" config = { 'trigger-on-all': True, 'conditions': [{ 'match': 'hello', 'count': '1' }, { 'match': 'world', 'count': '2' }] } conditions = PluggableConditions(config, self.test_object) self.assertFalse(conditions.check('world')) self.assertFalse(conditions.check_final()) self.assertFalse(conditions.check('hello')) # 'world' not met self.assertFalse(conditions.check_final()) self.assertTrue(conditions.check('world')) self.assertTrue(conditions.check_final())
def test_005_count(self): """Test range count condition""" config = {'conditions': [{'match': 'hello', 'count': '2-4'}]} conditions = PluggableConditions(config, self.test_object) # Check with no message handled self.assertFalse(conditions.check_final()) # Check with one message handled self.assertFalse(conditions.check('hello')) self.assertFalse(conditions.check_final()) # Check with two messages handled self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final()) # Check with four messages handled self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final()) # Check with five messages handled self.assertFalse(conditions.check('hello')) self.assertTrue(conditions.check_final()) # min met
def test_007_max(self): """Test maximum condition""" config = {'conditions': [{'match': 'hello', 'count': '<2'}]} conditions = PluggableConditions(config, self.test_object) # Check with no message handled self.assertTrue(conditions.check_final()) # Check with one message handled self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final()) # Check with two messages handled self.assertFalse(conditions.check('hello')) self.assertTrue(conditions.check_final()) # min met
def test_002_match(self): """Test basic matching""" config = {'conditions': [{'match': 'hello'}]} conditions = PluggableConditions(config, self.test_object) self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final())
def test_001_defaults(self): """Test condition defaults""" config = {'conditions': ['hello']} conditions = PluggableConditions(config, self.test_object) self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final())
def test_003_optional(self): """Test optional matching""" config = {'conditions': [{'optional': 'hello'}]} conditions = PluggableConditions(config, self.test_object) # Check with no message handled self.assertTrue(conditions.check_final()) # Now check once message handled self.assertTrue(conditions.check('hello')) self.assertTrue(conditions.check_final())
def test_010_trigger_on_first(self): """Test trigger on first match (other conditions don't apply)""" config = { 'trigger-on-any': False, 'trigger-on-all': False, 'conditions': [{ 'match': 'hello', 'count': '1' }, { 'match': 'world', 'count': '2' }] } conditions = PluggableConditions(config, self.test_object) self.assertTrue(conditions.check('world')) self.assertFalse(conditions.check_final()) # 'hello' & 'world' not met