Hypothesis-networkx
This module provides a Hypothesis strategy for generating networkx graphs. This can be used to efficiently and thoroughly test your code.
Installation
This module can be installed via pip:
pip install hypothesis-networkx
User guide
The module exposes a single function: graph_builder. This function is a
hypothesis composite strategy for building graphs. You can use it as follows:
from hypothesis_networkx import graph_builder
from hypothesis import strategies as st
import networkx as nx
node_data = st.fixed_dictionaries({'name': st.text(),
'number': st.integers()})
edge_data = st.fixed_dictionaries({'weight': st.floats(allow_nan=False,
allow_infinity=False)})
builder = graph_builder(graph_type=nx.Graph,
node_keys=st.integers(),
node_data=node_data,
edge_data=edge_data,
min_nodes=2, max_nodes=10,
min_edges=1, max_edges=None,
self_loops=False,
connected=True)
graph = builder.example()
print(graph.nodes(data=True))
print(graph.edges(data=True))
Of course this builder is a valid hypothesis strategy, and using it to just make examples is not super useful. Instead, you can (and should) use it in your testing framework:
from hypothesis import given
@given(graph=builder)
def test_my_function(graph):
assert my_function(graph) == known_function(graph)
The meaning of the arguments given to graph_builder are pretty
self-explanatory, but they must be given as keyword arguments.
node_data: The strategy from which node attributes will be drawn.edge_data: The strategy from which edge attributes will be drawn.node_keys: Either the strategy from which node keys will be draw, or None. If None, node keys will be integers from the range (0, number of nodes).min_nodesandmax_nodes: The minimum and maximum number of nodes the produced graphs will contain.min_edgesandmax_edges: The minimum and maximum number of edges the produced graphs will contain. Note that less edges thanmin_edgesmay be added if there are not enough nodes, and more thanmax_edgesifconnectedis True.graph_type: This function (or class) will be called without arguments to create an empty initial graph.connected: If True, the generated graph is guaranteed to be a single connected component.self_loops: If False, there will be no self-loops in the generated graph. Self-loops are edges between a node and itself.
Known limitations
There are a few (minor) outstanding issues with this module:
- Graph generation may be slow for large graphs.
- The
min_edgesargument is not always respected when the produced graph is too small. - The
max_edgesargument is not always respected ifconnectedis True. - It currently works for Python 2.7, but this is considered deprecated and may stop working without notice.
See also
Metadata
Release files for hypothesis-networkx 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hypothesis_networkx-0.3.0.tar.gz | 12.3 kB | Without provenance | Details for hypothesis_networkx-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hypothesis_networkx-0.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for hypothesis_networkx-0.3.0-py2.py3-none-any.whl |
Total release size: 22.9 kB
Release files / hypothesis_networkx-0.3.0.tar.gz
| Download URL | hypothesis_networkx-0.3.0.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8211dec83cbeea6b3fcddd9fc6879d852d15f7a3bc2896045057d0cd67ebfbe
|
|
BLAKE2b-256 checksum How to use checksums |
6aa19300093166310e734dad3396531c38a3e32f0da3b977884e7899d74f7a0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / hypothesis_networkx-0.3.0-py2.py3-none-any.whl
| Download URL | hypothesis_networkx-0.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
85ae8c4986cd311f0edebcf720b4b3a31ffa7800d560b6f1aa85efb38b4178eb
|
|
BLAKE2b-256 checksum How to use checksums |
1dd20a05f16d030f96e91e4e89fa0be96f7554b7c0d9992c5ec716fc6608df93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for hypothesis-networkx 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.