{"id":15359661,"url":"https://github.com/pckroon/hypothesis-networkx","last_synced_at":"2025-04-15T07:23:23.435Z","repository":{"id":47011868,"uuid":"140573662","full_name":"pckroon/hypothesis-networkx","owner":"pckroon","description":"Hypothesis strategy to generate NetworkX graphs.","archived":false,"fork":false,"pushed_at":"2023-09-15T12:47:26.000Z","size":73,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T17:48:06.618Z","etag":null,"topics":["graph","graph-generation","hacktoberfest","hypothesis","networkx","python","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pckroon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-11T12:43:07.000Z","updated_at":"2024-11-28T16:33:59.000Z","dependencies_parsed_at":"2024-10-16T04:40:49.706Z","dependency_job_id":null,"html_url":"https://github.com/pckroon/hypothesis-networkx","commit_stats":{"total_commits":39,"total_committers":4,"mean_commits":9.75,"dds":"0.41025641025641024","last_synced_commit":"d884c71f3af0a4b059f525889eba3f7fb8aa6c49"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pckroon%2Fhypothesis-networkx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pckroon%2Fhypothesis-networkx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pckroon%2Fhypothesis-networkx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pckroon%2Fhypothesis-networkx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pckroon","download_url":"https://codeload.github.com/pckroon/hypothesis-networkx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249024491,"owners_count":21200129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph","graph-generation","hacktoberfest","hypothesis","networkx","python","testing"],"created_at":"2024-10-01T12:45:34.458Z","updated_at":"2025-04-15T07:23:23.410Z","avatar_url":"https://github.com/pckroon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build\nStatus](https://travis-ci.org/pckroon/hypothesis-networkx.svg?branch=master)](https://travis-ci.org/pckroon/hypothesis-networkx)\n[![codecov](https://codecov.io/gh/pckroon/hypothesis-networkx/branch/master/graph/badge.svg)](https://codecov.io/gh/pckroon/hypothesis-networkx)\n\n# Hypothesis-networkx\n\nThis module provides a Hypothesis strategy for generating networkx graphs.\nThis can be used to efficiently and thoroughly test your code.\n\n## Installation\n\nThis module can be installed via `pip`:\n```\npip install hypothesis-networkx\n```\n\n## User guide\n\nThe module exposes a single function: `graph_builder`. This function is a\nhypothesis composite strategy for building graphs. You can use it as follows:\n\n```python3\nfrom hypothesis_networkx import graph_builder\nfrom hypothesis import strategies as st\nimport networkx as nx\n\nnode_data = st.fixed_dictionaries({'name': st.text(),\n                                   'number': st.integers()})\nedge_data = st.fixed_dictionaries({'weight': st.floats(allow_nan=False,\n                                                       allow_infinity=False)})\n\n\nbuilder = graph_builder(graph_type=nx.Graph,\n                        node_keys=st.integers(),\n                        node_data=node_data,\n                        edge_data=edge_data,\n                        min_nodes=2, max_nodes=10,\n                        min_edges=1, max_edges=None,\n                        self_loops=False,\n                        connected=True)\n\ngraph = builder.example()\nprint(graph.nodes(data=True))\nprint(graph.edges(data=True))\n```\n\nOf course this builder is a valid hypothesis strategy, and using it to just\nmake examples is not super useful. Instead, you can (and should) use it in\nyour testing framework:\n\n```python3\nfrom hypothesis import given\n\n@given(graph=builder)\ndef test_my_function(graph):\n    assert my_function(graph) == known_function(graph)\n\n```\n\nThe meaning of the arguments given to `graph_builder` are pretty\nself-explanatory, but they *must* be given as keyword arguments. \n  - `node_data`: The strategy from which node attributes will be drawn.\n  - `edge_data`: The strategy from which edge attributes will be drawn.\n  - `node_keys`: Either the strategy from which node keys will be draw, or\n                 None. If None, node keys will be integers from the range (0, number of nodes).\n  - `min_nodes` and `max_nodes`: The minimum and maximum number of nodes the \n                                 produced graphs will contain.\n  - `min_edges` and `max_edges`: The minimum and maximum number of edges the\n                                 produced graphs will contain. Note that less \n                                 edges than `min_edges` may be added if there \n                                 are not enough nodes, and more than\n                                 `max_edges` if `connected` is True.\n  - `graph_type`: This function (or class) will be called without arguments to\n                  create an empty initial graph.\n  - `connected`: If True, the generated graph is guaranteed to be a single\n                 connected component.\n  - `self_loops`: If False, there will be no self-loops in the generated graph.\n                  Self-loops are edges between a node and itself.\n\n## Known limitations\n\nThere are a few (minor) outstanding issues with this module:\n\n  - Graph generation may be slow for large graphs.\n  - The `min_edges` argument is not always respected when the produced graph\n    is too small.\n  - The `max_edges` argument is not always respected if `connected` is True.\n  - It currently works for Python 2.7, but this is considered deprecated and\n    may stop working without notice.\n\n## See also\n\n[Networkx](https://networkx.github.io/documentation/stable/index.html)\n\n[Hypothesis](https://hypothesis.readthedocs.io/en/latest/index.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpckroon%2Fhypothesis-networkx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpckroon%2Fhypothesis-networkx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpckroon%2Fhypothesis-networkx/lists"}