How to use a_rule method in hypothesis

Best Python code snippet using hypothesis

test_stastsd_rule_benchmark.py

Source:test_stastsd_rule_benchmark.py Github

copy

Full Screen

1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4from mock import patch, call, Mock5from nose.tools import eq_, ok_, assert_raises6from socorro.unittest.testbase import TestCase7from datetime import datetime8from configman.dotdict import DotDict9from socorro.external.statsd.statsd_rule_benchmark import (10 StatsdRuleBenchmarkWrapper,11 CountAnythingRuleBase,12 CountStackWalkerTimeoutKills,13 CountStackWalkerFailures,14)15from socorro.external.statsd.statsd_base import StatsdCounter16from socorro.unittest.lib.test_transform_rules import (17 TestRuleTestLaughable,18 TestRuleTestDangerous19)20from socorro.lib import transform_rules21from socorro.external.statsd.dogstatsd import StatsClient22#==============================================================================23class TestStatsdCounterRule(TestCase):24 #--------------------------------------------------------------------------25 def setup_config(self, prefix=None):26 config = DotDict()27 config.chatty_rules = False28 config.chatty = False29 config.tag = 'test.rule'30 config.action = 'apply_all_rules'31 config.rules_list = DotDict()32 config.rules_list.class_list = [33 (34 'TestRuleTestLaughable',35 StatsdRuleBenchmarkWrapper,36 'TestRuleTestLaughable'37 ),38 (39 'TestRuleTestDangerous',40 StatsdRuleBenchmarkWrapper,41 'TestRuleTestDangerous'42 )43 ]44 config.TestRuleTestLaughable = DotDict()45 config.TestRuleTestLaughable.laughable = 'wilma'46 config.TestRuleTestLaughable.statsd_class = StatsClient47 config.TestRuleTestLaughable.statsd_host = 'some_statsd_host'48 config.TestRuleTestLaughable.statsd_port = 333349 config.TestRuleTestLaughable.statsd_prefix = prefix if prefix else ''50 config.TestRuleTestLaughable.wrapped_object_class = TestRuleTestLaughable51 config.TestRuleTestLaughable.active_list = 'act'52 config.TestRuleTestDangerous = DotDict()53 config.TestRuleTestDangerous.dangerous = 'dwight'54 config.TestRuleTestDangerous.statsd_class = StatsClient55 config.TestRuleTestDangerous.statsd_host = 'some_statsd_host'56 config.TestRuleTestDangerous.statsd_port = 333357 config.TestRuleTestDangerous.statsd_prefix = prefix if prefix else ''58 config.TestRuleTestDangerous.wrapped_object_class = TestRuleTestDangerous59 config.TestRuleTestDangerous.active_list = 'act'60 return config61 #--------------------------------------------------------------------------62 @patch('socorro.external.statsd.dogstatsd.statsd')63 def test_apply_all(self, statsd_obj):64 config = self.setup_config('processor')65 trs = transform_rules.TransformRuleSystem(config)66 ok_(isinstance(trs.rules[0], StatsdRuleBenchmarkWrapper))67 ok_(isinstance(trs.rules[0].wrapped_object, TestRuleTestLaughable))68 ok_(isinstance(trs.rules[1], StatsdRuleBenchmarkWrapper))69 ok_(isinstance(trs.rules[1].wrapped_object, TestRuleTestDangerous))70 now_str = 'socorro.external.statsd.statsd_base.datetime'71 with patch(now_str) as now_mock:72 times = [73 datetime(2015, 5, 4, 15, 10, 3),74 datetime(2015, 5, 4, 15, 10, 2),75 datetime(2015, 5, 4, 15, 10, 1),76 datetime(2015, 5, 4, 15, 10, 0),77 ]78 ok_(trs.rules[0].predicate(None))79 statsd_obj.timing.has_calls([])80 ok_(trs.rules[1].action(None))81 statsd_obj.timing.has_calls([])82 trs.apply_all_rules()83 statsd_obj.timing.has_calls([84 call(85 'timing.TestRuleTestLaughable.act',86 1000 # 1 second87 ),88 call(89 'timing.TestRuleTestDangerous.act',90 1000 # 1 second91 ),92 ])93#==============================================================================94class TestStatsdCountAnythingRule(TestStatsdCounterRule):95 @patch('socorro.external.statsd.dogstatsd.statsd')96 def testCountAnythingRuleBase(self, statsd_obj):97 config = DotDict()98 config.counter_class = Mock()99 config.rule_name = 'dwight'100 config.statsd_class = Mock()101 config.statsd_host = 'some_statsd_host'102 config.statsd_port = 3333103 config.statsd_prefix = ''104 config.active_list = ['dwight']105 a_rule = CountAnythingRuleBase(config)106 raw_crash_mock = Mock()107 raw_dumps_mock = Mock()108 processed_crash_mock = Mock()109 proc_meta_mock = Mock()110 assert_raises(111 NotImplementedError,112 a_rule._predicate,113 raw_crash_mock,114 raw_dumps_mock,115 processed_crash_mock,116 proc_meta_mock117 )118 a_rule._action(119 raw_crash_mock,120 raw_dumps_mock,121 processed_crash_mock,122 proc_meta_mock123 )124 a_rule.counter._incr.assert_called_once_with(125 'dwight'126 )127 @patch('socorro.external.statsd.dogstatsd.statsd')128 def testCountStackWalkerTimeoutKills_success(self, statsd_obj):129 config = DotDict()130 config.counter_class = Mock()131 config.rule_name = 'stackwalker_timeout_kills'132 config.statsd_class = Mock()133 config.statsd_host = 'some_statsd_host'134 config.statsd_port = 3333135 config.statsd_prefix = ''136 config.active_list = ['stackwalker_timeout_kills']137 a_rule = CountStackWalkerTimeoutKills(config)138 raw_crash_mock = Mock()139 raw_dumps_mock = Mock()140 processed_crash_mock = Mock()141 proc_meta = DotDict()142 proc_meta.processor_notes = [143 'hello',144 'this is a list of notes from the processor',145 'it has information about the what the processor',146 'thought was important',147 'like, maybe, SIGKILL of the stackwalker',148 'or other such things.'149 ]150 ok_(151 a_rule._predicate(152 raw_crash_mock,153 raw_dumps_mock,154 processed_crash_mock,155 proc_meta156 )157 )158 a_rule._action(159 raw_crash_mock,160 raw_dumps_mock,161 processed_crash_mock,162 proc_meta163 )164 a_rule.counter._incr.assert_called_once_with(165 'stackwalker_timeout_kills'166 )167 @patch('socorro.external.statsd.dogstatsd.statsd')168 def testCountStackWalkerTimeoutKills_fail(self, statsd_obj):169 config = DotDict()170 config.counter_class = Mock()171 config.rule_name = 'stackwalker_timeout_kills'172 config.statsd_class = Mock()173 config.statsd_host = 'some_statsd_host'174 config.statsd_port = 3333175 config.statsd_prefix = ''176 config.active_list = ['stackwalker_timeout_kills']177 a_rule = CountStackWalkerTimeoutKills(config)178 raw_crash_mock = Mock()179 raw_dumps_mock = Mock()180 processed_crash_mock = Mock()181 proc_meta = DotDict()182 proc_meta.processor_notes = [183 'hello',184 'this is a list of notes from the processor',185 'it has information about the what the processor',186 'thought was important',187 ]188 ok_(189 not190 a_rule._predicate(191 raw_crash_mock,192 raw_dumps_mock,193 processed_crash_mock,194 proc_meta195 )196 )197 @patch('socorro.external.statsd.dogstatsd.statsd')198 def testCountStackWalkerFailures_success(self, statsd_obj):199 config = DotDict()200 config.counter_class = Mock()201 config.rule_name = 'stackwalker_timeout_kills'202 config.statsd_class = Mock()203 config.statsd_host = 'some_statsd_host'204 config.statsd_port = 3333205 config.statsd_prefix = ''206 config.active_list = ['stackwalker_timeout_kills']207 a_rule = CountStackWalkerFailures(config)208 raw_crash_mock = Mock()209 raw_dumps_mock = Mock()210 processed_crash_mock = Mock()211 proc_meta = DotDict()212 proc_meta.processor_notes = [213 'hello',214 'this is a list of notes from the processor',215 'it has information about the what the processor',216 'thought was important',217 'like, maybe when "MDSW failed"',218 'or other such things.'219 ]220 ok_(221 a_rule._predicate(222 raw_crash_mock,223 raw_dumps_mock,224 processed_crash_mock,225 proc_meta226 )227 )228 a_rule._action(229 raw_crash_mock,230 raw_dumps_mock,231 processed_crash_mock,232 proc_meta233 )234 a_rule.counter._incr.assert_called_once_with(235 'stackwalker_timeout_kills'236 )237 @patch('socorro.external.statsd.dogstatsd.statsd')238 def testCountStackWalkerFailures_fail(self, statsd_obj):239 config = DotDict()240 config.counter_class = Mock()241 config.rule_name = 'stackwalker_timeout_kills'242 config.statsd_class = Mock()243 config.statsd_host = 'some_statsd_host'244 config.statsd_port = 3333245 config.statsd_prefix = ''246 config.active_list = ['stackwalker_timeout_kills']247 a_rule = CountStackWalkerFailures(config)248 raw_crash_mock = Mock()249 raw_dumps_mock = Mock()250 processed_crash_mock = Mock()251 proc_meta = DotDict()252 proc_meta.processor_notes = [253 'hello',254 'this is a list of notes from the processor',255 'it has information about the what the processor',256 'thought was important',257 ]258 ok_(259 not260 a_rule._predicate(261 raw_crash_mock,262 raw_dumps_mock,263 processed_crash_mock,264 proc_meta265 )...

Full Screen

Full Screen

assocrules_tests.py

Source:assocrules_tests.py Github

copy

Full Screen

1import unittest2from pymining import itemmining, perftesting, assocrules3class TestAssocRule(unittest.TestCase):4 def testDefaultSupportConf(self):5 ts1 = perftesting.get_default_transactions()6 relim_input = itemmining.get_relim_input(ts1)7 report = itemmining.relim(relim_input, 2)8 rules = assocrules.mine_assoc_rules(report, min_support=2)9 self.assertEqual(20, len(rules))10 a_rule = (frozenset(['b', 'e']), frozenset(['d']), 2, 1.0)11 self.assertTrue(a_rule in rules)12 ts2 = perftesting.get_default_transactions_alt()13 relim_input = itemmining.get_relim_input(ts2)14 report = itemmining.relim(relim_input, 2)15 rules = assocrules.mine_assoc_rules(report, min_support=2)16 self.assertEqual(20, len(rules))17 a_rule = (frozenset(['e']), frozenset(['a', 'd']), 2, 2.0/3.0)18 self.assertTrue(a_rule in rules)19 def testConfidence075(self):20 ts1 = perftesting.get_default_transactions()21 relim_input = itemmining.get_relim_input(ts1)22 report = itemmining.relim(relim_input, 2)23 rules = assocrules.mine_assoc_rules(report, min_support=2,24 min_confidence=0.75)25 self.assertEqual(5, len(rules))26 a_rule = (frozenset(['b']), frozenset(['d']), 6, 0.75)27 self.assertTrue(a_rule in rules)28 def testSupport5(self):29 ts1 = perftesting.get_default_transactions()30 relim_input = itemmining.get_relim_input(ts1)31 report = itemmining.relim(relim_input, 5)32 rules = assocrules.mine_assoc_rules(report, min_support=5)33 self.assertEqual(2, len(rules))34 a_rule = (frozenset(['d']), frozenset(['b']), 6, 0.75)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful