What I am trying to check is whether the user is part of the graph or not.
import graph_creator
def test_user():
assert "user" in graph
Sadly, this approach results in an error:
'user' != <networkx.classes.multidigraph.MultiDiGraph object at 0x000002164D4567A0>
Expected :<networkx.classes.multidigraph.MultiDiGraph object at 0x000002164D4567A0> Actual :'user'
def test_user(): assert 'user' in graph
E AssertionError: assert 'user' in <networkx.classes.multidigraph.MultiDiGraph object at 0x000002164D4567A0>
import graph_creator
if "user" in graph_creater.graph:
print("true")
Testing like this works and returns "true". This means that the "user" is part of my graph?
CodePudding user response:
It's not clear what graph_creater
library/module is doing, but given the traceback, it might be that a specific graph
object needs to be created. Possibly, in the snippet above, this would be G = graph()
.
Here's an example with networkx
:
from networkx import Graph
G = Graph()
print("user" in G)
# False
print("user" in Graph)
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: argument of type 'type' is not iterable
CodePudding user response:
Had to call a method within my test to add nodes to my graph.
import graph_creator
def test_user():
graph_creator.create_nodes()
assert 'user' in graph_creator.graph.nodes