python类settings()的实例源码

generate.py 文件源码 项目:dustbunny 作者: Teamworksapp 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
test_regex.py 文件源码 项目:hypothesis-regex 作者: maximkulkin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
test_external_programs.py 文件源码 项目:isambard 作者: woolfson-group 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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()
test_external_programs.py 文件源码 项目:isambard 作者: woolfson-group 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
swagger_fuzzer.py 文件源码 项目:swagger-fuzzer 作者: Lothiraldan 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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()


问题


面经


文章

微信
公众号

扫码关注公众号