Skip to content

Commit

Permalink
Cleanup qt_dotgraph and make the tests more robust. (#296)
Browse files Browse the repository at this point in the history
1.  Remove all uses of LooseVersion here.  The issue it
was protecting against is long gone, and LooseVersion is
deprecated.  Just remove it.
2.  Remove the "simplify" parameter from "add_edge_to_graph".
While this is technically an API change, there are no downstream
users as far as I can tell and it had no effect.
3.  During the test, make sure to replace carriage return with
spaces.  This ensures that on Windows, the tests will pass
correctly.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Nov 7, 2024
1 parent ee23724 commit 4a11ebc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
43 changes: 13 additions & 30 deletions qt_dotgraph/src/qt_dotgraph/pydotfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from distutils.version import LooseVersion
try:
from urllib.request import quote
except ImportError:
from urllib import quote

import os
from urllib.request import quote

import pydot

Expand Down Expand Up @@ -64,22 +59,15 @@ def escape_name(self, name):
def get_graph(
self, graph_type='digraph', rank='same', simplify=True,
rankdir='TB', ranksep=0.2, compound=True):
# Lucid version of pydot bugs with certain settings, not sure which
# version exactly fixes those
if LooseVersion(pydot.__version__) > LooseVersion('1.0.10'):
graph = pydot.Dot('graphname',
graph_type=graph_type,
rank=rank,
rankdir=rankdir,
simplify=simplify
)
graph.set_ranksep(ranksep)
graph.set_compound(compound)
else:
graph = pydot.Dot('graphname',
graph_type=graph_type,
rank=rank,
rankdir=rankdir)
graph = pydot.Dot('graphname',
graph_type=graph_type,
rank=rank,
rankdir=rankdir,
simplify=simplify
)
graph.set_ranksep(ranksep)
graph.set_compound(compound)

return graph

def add_node_to_graph(self,
Expand Down Expand Up @@ -138,9 +126,8 @@ def add_subgraph_to_graph(self,
g.set_style(style)
if 'set_shape' in g.__dict__:
g.set_shape(shape)
if LooseVersion(pydot.__version__) > LooseVersion('1.0.10'):
g.set_compound(compound)
g.set_ranksep(ranksep)
g.set_compound(compound)
g.set_ranksep(ranksep)
subgraphlabel = subgraphname if subgraphlabel is None else subgraphlabel
subgraphlabel = self.escape_label(subgraphlabel)
if subgraphlabel:
Expand All @@ -153,11 +140,7 @@ def add_subgraph_to_graph(self,

def add_edge_to_graph(
self, graph, nodename1, nodename2, label=None, url=None,
simplify=True, style=None, penwidth=1, color=None,
edgetooltip=None):
if simplify and LooseVersion(pydot.__version__) < LooseVersion('1.0.10'):
if graph.get_edge(self.escape_name(nodename1), self.escape_name(nodename2)) != []:
return
style=None, penwidth=1, color=None, edgetooltip=None):
edge = pydot.Edge(self.escape_name(nodename1), self.escape_name(nodename2))
if label is not None and label != '':
edge.set_label(label)
Expand Down
2 changes: 1 addition & 1 deletion qt_dotgraph/test/pydot_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ def test_create_dot(self):
except FileNotFoundError:
raise unittest.SkipTest('skipping test since dot is unavailable')
# get rid of version specific whitespaces
result = re.sub('[\n\t ]+', ' ', result)
result = re.sub('[\n\t\r ]+', ' ', result)
for sn in snippets:
self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))

0 comments on commit 4a11ebc

Please sign in to comment.