我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用hypothesis.strategies.booleans()。
def services( draw, ids=uuids(), names=text(), descriptions=text(), registration_schemas=dictionaries(text(), text()), result_schemas=dictionaries(text(), text()), are_available=booleans(), service_job_lists=job_lists(), timeouts=timedeltas() ) -> ServiceInterface: return Service( draw(ids), draw(names), draw(descriptions), draw(registration_schemas), draw(result_schemas), draw(are_available), draw(service_job_lists), draw(timeouts) )
def bare_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields values appropriate for that attribute. """ default = NOTHING if defaults is True or (defaults is None and draw(st.booleans())): default = None return ((attr.ib(default=default), st.just(None)))
def int_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields ints for that attribute. """ default = NOTHING if defaults is True or (defaults is None and draw(st.booleans())): default = draw(st.integers()) return ((attr.ib(default=default), st.integers()))
def str_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields strs for that attribute. """ default = NOTHING if defaults is True or (defaults is None and draw(st.booleans())): default = draw(st.text()) return ((attr.ib(default=default), st.text()))
def float_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields floats for that attribute. """ default = NOTHING if defaults is True or (defaults is None and draw(st.booleans())): default = draw(st.floats()) return ((attr.ib(default=default), st.floats()))
def dict_attrs(draw, defaults=None): """ Generate a tuple of an attribute and a strategy that yields dictionaries for that attribute. The dictionaries map strings to integers. """ default = NOTHING val_strat = st.dictionaries(keys=st.text(), values=st.integers()) if defaults is True or (defaults is None and draw(st.booleans())): default_val = draw(val_strat) default = attr.Factory(lambda: default_val) return ((attr.ib(default=default), val_strat))
def services( draw, service_id=uuids(), name=text(), description=text(), is_available=booleans() ) -> IService: return Service( draw(service_id), draw(name), draw(description), draw(is_available) )
def ifexp_node(draw, test=const_node(hs.booleans()), body=const_node(), orelse=const_node()): test = draw(test) body = draw(body) orelse = draw(orelse) node = astroid.IfExp() node.postinit(test, body, orelse) return node
def bipartite_graph(draw): m = draw(st.integers(min_value=1, max_value=4)) n = draw(st.integers(min_value=m, max_value=5)) graph = BipartiteGraph() for i in range(n): for j in range(m): b = draw(st.booleans()) if b: graph[i, j] = b return graph
def test_transpose(booleans): npmatrix = np.array(booleans).transpose() bitarrays = create_bitarrays(booleans) tbitarrays = transpose(bitarrays) for j in range(len(booleans)): for i in range(SIZE): assert npmatrix[i, j] == tbitarrays[i][j]
def provide_require_st(draw, filter_=True): # pragma: no cover commands = draw(range_intagers_st) provides = draw( st.lists( st.lists(range_intagers_st, max_size=10), min_size = commands, max_size = commands ), ) is_func = draw( st.lists( st.booleans(), min_size = commands, max_size = commands ) ) provides_set = set() for command in provides: provides_set.update(command) requires = [] if provides_set: for command in provides: if command: max_prov = max(command) else: max_prov = 0 if filter_: provides_filter = [x for x in provides_set if x > max_prov] else: provides_filter = provides_set if provides_filter: sample = st.sampled_from(provides_filter) requires.append(draw(st.lists(sample, max_size=10))) else: requires.append([]) else: requires = [[]] * commands return (provides, requires, is_func)
def mapreduce_application(): """Mock of the mapreduce jobs REST resource.""" if 'last' in request.args: return jsonify(redis.get(request.base_url)) d = st.fixed_dictionaries({ 'startTime': st.integers(0), 'finishTime': st.integers(0), 'elapsedTime': st.integers(0), 'id': st.integers(0), 'name': st.text(), 'user': st.text(), 'state': st.sampled_from(['NEW', 'SUCCEEDED', 'RUNNING', 'FAILED', 'KILLED']), 'mapsTotal': st.integers(0), 'mapsCompleted': st.integers(0), 'reducesTotal': st.integers(0), 'reducesCompleted': st.integers(0), 'mapProgress': st.floats(0, 100), 'reduceProgress': st.floats(0, 100), 'mapsPending': st.integers(0), 'mapsRunning': st.integers(0), 'reducesPending': st.integers(0), 'reducesRunning': st.integers(0), 'uberized': st.booleans(), 'diagnostics': st.text(), 'newReduceAttempts': st.integers(0), 'runningReduceAttempts': st.integers(0), 'failedReduceAttempts': st.integers(0), 'killedReduceAttempts': st.integers(0), 'successfulReduceAttempts': st.integers(0), 'newMapAttempts': st.integers(0), 'runningMapAttempts': st.integers(0), 'failedMapAttempts': st.integers(0), 'killedMapAttempts': st.integers(0), 'successfulMapAttempts': st.integers(0) }) result = json.dumps({ 'jobs': { 'job': st.lists(d, average_size=3).example() } }) redis.set(request.base_url, result) return jsonify(result)