Skip to content

Commit

Permalink
Use lowercase true|false in GEXF writer
Browse files Browse the repository at this point in the history
Fixes #912
  • Loading branch information
hagberg committed Jul 24, 2013
1 parent c566642 commit 1270e10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion networkx/readwrite/gexf.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ def add_attributes(self, node_or_edge, xml_obj, data, default):
# static data
e=Element("attvalue")
e.attrib['for']=attr_id
e.attrib['value']=make_str(v)
if type(v) == bool:
e.attrib['value']=make_str(v).lower()
else:
e.attrib['value']=make_str(v)
attvalues.append(e)
xml_obj.append(attvalues)
return data
Expand Down
9 changes: 8 additions & 1 deletion networkx/readwrite/tests/test_gexf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,11 @@ def test_write_with_node_attributes(self):
obtained = '\n'.join(nx.generate_gexf(G))
assert_equal( expected, obtained )


def test_bool(self):
G=nx.Graph()
G.add_node(1, testattr=True)
fh = io.BytesIO()
nx.write_gexf(G,fh)
fh.seek(0)
H=nx.read_gexf(fh,node_type=int)
assert_true(H.node[1]['testattr'], True)

0 comments on commit 1270e10

Please sign in to comment.