Skip to content

Commit 4a11ebc

Browse files
authored
Cleanup qt_dotgraph and make the tests more robust. (#296)
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 <clalancette@gmail.com>
1 parent ee23724 commit 4a11ebc

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

qt_dotgraph/src/qt_dotgraph/pydotfactory.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@
3030
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3131
# POSSIBILITY OF SUCH DAMAGE.
3232

33-
from distutils.version import LooseVersion
34-
try:
35-
from urllib.request import quote
36-
except ImportError:
37-
from urllib import quote
38-
3933
import os
34+
from urllib.request import quote
4035

4136
import pydot
4237

@@ -64,22 +59,15 @@ def escape_name(self, name):
6459
def get_graph(
6560
self, graph_type='digraph', rank='same', simplify=True,
6661
rankdir='TB', ranksep=0.2, compound=True):
67-
# Lucid version of pydot bugs with certain settings, not sure which
68-
# version exactly fixes those
69-
if LooseVersion(pydot.__version__) > LooseVersion('1.0.10'):
70-
graph = pydot.Dot('graphname',
71-
graph_type=graph_type,
72-
rank=rank,
73-
rankdir=rankdir,
74-
simplify=simplify
75-
)
76-
graph.set_ranksep(ranksep)
77-
graph.set_compound(compound)
78-
else:
79-
graph = pydot.Dot('graphname',
80-
graph_type=graph_type,
81-
rank=rank,
82-
rankdir=rankdir)
62+
graph = pydot.Dot('graphname',
63+
graph_type=graph_type,
64+
rank=rank,
65+
rankdir=rankdir,
66+
simplify=simplify
67+
)
68+
graph.set_ranksep(ranksep)
69+
graph.set_compound(compound)
70+
8371
return graph
8472

8573
def add_node_to_graph(self,
@@ -138,9 +126,8 @@ def add_subgraph_to_graph(self,
138126
g.set_style(style)
139127
if 'set_shape' in g.__dict__:
140128
g.set_shape(shape)
141-
if LooseVersion(pydot.__version__) > LooseVersion('1.0.10'):
142-
g.set_compound(compound)
143-
g.set_ranksep(ranksep)
129+
g.set_compound(compound)
130+
g.set_ranksep(ranksep)
144131
subgraphlabel = subgraphname if subgraphlabel is None else subgraphlabel
145132
subgraphlabel = self.escape_label(subgraphlabel)
146133
if subgraphlabel:
@@ -153,11 +140,7 @@ def add_subgraph_to_graph(self,
153140

154141
def add_edge_to_graph(
155142
self, graph, nodename1, nodename2, label=None, url=None,
156-
simplify=True, style=None, penwidth=1, color=None,
157-
edgetooltip=None):
158-
if simplify and LooseVersion(pydot.__version__) < LooseVersion('1.0.10'):
159-
if graph.get_edge(self.escape_name(nodename1), self.escape_name(nodename2)) != []:
160-
return
143+
style=None, penwidth=1, color=None, edgetooltip=None):
161144
edge = pydot.Edge(self.escape_name(nodename1), self.escape_name(nodename2))
162145
if label is not None and label != '':
163146
edge.set_label(label)

qt_dotgraph/test/pydot_factory_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ def test_create_dot(self):
114114
except FileNotFoundError:
115115
raise unittest.SkipTest('skipping test since dot is unavailable')
116116
# get rid of version specific whitespaces
117-
result = re.sub('[\n\t ]+', ' ', result)
117+
result = re.sub('[\n\t\r ]+', ' ', result)
118118
for sn in snippets:
119119
self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))

0 commit comments

Comments
 (0)