Skip to content

Commit bc96d95

Browse files
authored
Add tests for no-attr-in-host (#31)
* Add tests for no-attr-in-host * Add broken-motif tests * Fix counting bug (thanks test-coverage obsession!) * Update changelog * Update to version 2.1.1 in notation * Add Python 3.9, 3.10 to CI * Fix Python 3.10 notation in CI
1 parent 27cd474 commit bc96d95

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [3.6, 3.7, 3.8]
18+
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
1919

2020
steps:
2121
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## [v2.1.1 (December 21 2021)](https://pypi.org/project/grandiso/2.1.0/)
4+
5+
- Fixes
6+
- Fixed a minor bug in which counts were one-off when using `count_only=False` and `limit=int`.
7+
- Achieved 100% test coverage, woo!
8+
- Added support for Python 3.6 (thanks @aleclearmind!), and added 3.9 and 3.10 to CI.
9+
310
## [v2.1.0 (December 16 2021)](https://pypi.org/project/grandiso/2.1.0/)
411

512
- Features

grandiso/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import networkx as nx
2626
from .queues import SimpleQueue
2727

28-
__version__ = "2.1.0"
28+
__version__ = "2.1.1"
2929

3030

3131
@lru_cache()
@@ -157,8 +157,9 @@ def get_next_backbone_candidates(
157157
# interesting node to start with:
158158
if next_node is None and len(backbone) == 0:
159159
# This is the starting-case, where we have NO backbone nodes set yet.
160-
next_node = max(interestingness.keys(),
161-
key=lambda node: interestingness.get(node, 0.0))
160+
next_node = max(
161+
interestingness.keys(), key=lambda node: interestingness.get(node, 0.0)
162+
)
162163
# Let's return ALL possible node choices for this next_node. To do this
163164
# without being an insane person, let's filter on max degree in host:
164165
return [
@@ -201,8 +202,10 @@ def get_next_backbone_candidates(
201202
_nodes_with_greatest_backbone_count.append(motif_node_id)
202203
# Now we have _node_with_greatest_backbone_count as the best candidate
203204
# for `next_node`.
204-
next_node = max(_nodes_with_greatest_backbone_count,
205-
key=lambda node: interestingness.get(node, 0.0))
205+
next_node = max(
206+
_nodes_with_greatest_backbone_count,
207+
key=lambda node: interestingness.get(node, 0.0),
208+
)
206209

207210
# Now we have a node `next_node` which we know is connected to the current
208211
# backbone. Get all edges between `next_node` and nodes in the backbone,
@@ -480,7 +483,10 @@ def find_motifs(
480483
if count_only:
481484
return results_count
482485
else:
483-
if limit and results_count >= limit:
486+
# Subtract 1 from results_count because we have not yet
487+
# added the new result to the results list, but we HAVE
488+
# already added +1 to the count.
489+
if limit and (results_count - 1) >= limit:
484490
return results
485491
if not count_only:
486492
results.append(result)

grandiso/test_grandiso.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def test_limit_one(self):
437437
def test_limit_eq_answer(self):
438438
host = nx.complete_graph(8)
439439
motif = nx.complete_graph(3)
440-
assert find_motifs(motif, host, count_only=True, limit=336) == 336
440+
assert len(find_motifs(motif, host, limit=300)) == 300
441441

442442
def test_limit_gt_answer(self):
443443
host = nx.complete_graph(8)
@@ -507,3 +507,50 @@ def test_node_and_edge_attributes(self):
507507
motif.add_node("c", flavor="lint")
508508

509509
assert find_motifs(motif, host) == []
510+
511+
def test_attr_not_in_node(self):
512+
host = nx.DiGraph()
513+
nx.add_path(host, ["A", "B", "C", "A"])
514+
host.add_edge("A", "B")
515+
host.add_edge("B", "C")
516+
host.add_edge("C", "A")
517+
host.add_node("A")
518+
host.add_node("B")
519+
host.add_node("C")
520+
521+
motif = nx.DiGraph()
522+
motif.add_edge("a", "b")
523+
motif.add_node("a", flavor="coffee")
524+
525+
assert find_motifs(motif, host) == []
526+
527+
def test_attr_not_in_edge(self):
528+
host = nx.DiGraph()
529+
nx.add_path(host, ["A", "B", "C", "A"])
530+
host.add_edge("A", "B")
531+
host.add_edge("B", "C")
532+
host.add_edge("C", "A")
533+
host.add_node("A")
534+
host.add_node("B")
535+
host.add_node("C")
536+
537+
motif = nx.DiGraph()
538+
motif.add_edge("a", "b", type="delicious")
539+
540+
assert find_motifs(motif, host) == []
541+
542+
543+
class TestBrokenMotifFailures:
544+
def test_disconnected_motif(self):
545+
host = nx.complete_graph(8, nx.DiGraph())
546+
motif = nx.DiGraph()
547+
motif.add_node("a")
548+
motif.add_node("b")
549+
with pytest.raises(ValueError):
550+
find_motifs(motif, host)
551+
552+
def test_empty_motif(self):
553+
host = nx.complete_graph(8, nx.DiGraph())
554+
motif = nx.DiGraph()
555+
with pytest.raises(ValueError):
556+
find_motifs(motif, host)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
networkx==2.5.1
1+
networkx>=2.5.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="grandiso",
8-
version="2.1.0",
8+
version="2.1.1",
99
author="Jordan Matelsky",
1010
author_email="opensource@matelsky.com",
1111
description="Performant subgraph isomorphism",

0 commit comments

Comments
 (0)