我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用hypothesis.settings()。
def _do(self, **parents): if self.dist is not None: k = self.dist(1)[0] if k == 0: k = 1 else: k = self.n recs = [] @settings(max_examples=k) def gen(**kwargs): rels = {} for rv in self.relative_values: rels.update({name: xform(**kwargs, **parents, **self.fixtures, **rels, **self.extras) for name, xform in rv.items()}) recs.append(self.create(self.model, **kwargs, **parents, **self.fixtures, **rels)) if self.strategy: given(**self.strategy)(gen)() else: gen() self.db.session.commit() return recs
def assert_all_examples(strategy, predicate): ''' Checks that there are no examples with given strategy that do not match predicate. :param strategy: Hypothesis strategy to check :param predicate: (callable) Predicate that takes string example and returns bool ''' @h.settings(max_examples=1000, max_iterations=5000) @h.given(strategy) def assert_examples(s): assert predicate(s),'Found %r using strategy %s which does not match' % ( s, strategy, ) assert_examples()
def test_test_scwrl(self): """Test if ISAMBARD can detect Scwrl, check its availability and behave accordingly.""" old_path = isambard.settings.global_settings['scwrl']['path'] try: avail = isambard.external_programs.scwrl.test_scwrl() self.assertTrue(avail) helix = isambard.specifications.Helix(30) scwrl_out = isambard.external_programs.scwrl.pack_sidechains(helix.pdb, 'V'*30, path=False) self.assertEqual(type(scwrl_out[0]), str) self.assertEqual(type(scwrl_out[1]), float) isambard.settings.global_settings['scwrl']['path'] = '' avail = isambard.external_programs.scwrl.test_scwrl() isambard.settings.global_settings['scwrl']['available'] = avail self.assertFalse(avail) scwrl_out = isambard.external_programs.scwrl.pack_sidechains(helix.pdb, 'V'*30, path=False) self.assertIsNone(scwrl_out) finally: isambard.settings.global_settings['scwrl']['path'] = old_path isambard.settings.global_settings[ 'scwrl']['available'] = isambard.external_programs.scwrl.test_scwrl()
def test_test_dssp(self): """Test if ISAMBARD can detect DSSP, check its availability and behave accordingly.""" old_path = isambard.settings.global_settings['dssp']['path'] try: avail = isambard.external_programs.dssp.test_dssp() self.assertTrue(avail) helix = isambard.specifications.Helix(30) dssp_out_ampal = isambard.external_programs.dssp.run_dssp(helix.pdb, path=False) self.assertEqual(type(dssp_out_ampal), str) isambard.settings.global_settings['dssp']['path'] = '' avail = isambard.external_programs.dssp.test_dssp() isambard.settings.global_settings['dssp']['available'] = avail self.assertFalse(avail) dssp_out_ampal = isambard.external_programs.dssp.run_dssp(helix.pdb, path=False) self.assertIsNone(dssp_out_ampal) finally: isambard.settings.global_settings['dssp']['path'] = old_path isambard.settings.global_settings['dssp']['available'] = isambard.external_programs.dssp.test_dssp()
def do(settings): PARSED_HOST = urlparse(settings.spec_url) swagger_spec = requests.get(settings.spec_url) swagger_spec.raise_for_status() SPEC = swagger_spec.json() validator = get_validator(SPEC, settings.spec_url) validator.validate_spec(swagger_spec.json(), settings.spec_url) SPEC_HOST = urlunparse(list(PARSED_HOST)[:2] + [SPEC['basePath']] + ['', '', '']) s = requests.Session() @given(data()) @hsettings(max_examples=settings.iterations) def swagger_fuzzer(data): request = get_request(data, SPEC, SPEC_HOST) note("Curl command: {}".format(to_curl_command(request))) result = s.send(request) for validator in VALIDATORS: validator(SPEC, request, result, settings) # Call the function swagger_fuzzer()