[Python-checkins] distutils2: Added test case for graph_to_dot
tarek.ziade
python-checkins at python.org
Sun Jun 20 23:04:52 CEST 2010
tarek.ziade pushed 7bfa383dd0bf to distutils2:
http://hg.python.org/distutils2/rev/7bfa383dd0bf
changeset: 212:7bfa383dd0bf
user: Josip Djolonga
date: Wed Jun 16 20:27:45 2010 +0200
summary: Added test case for graph_to_dot
files: src/distutils2/depgraph.py, src/distutils2/tests/test_depgraph.py
diff --git a/src/distutils2/depgraph.py b/src/distutils2/depgraph.py
--- a/src/distutils2/depgraph.py
+++ b/src/distutils2/depgraph.py
@@ -75,12 +75,9 @@
If *skip_disconnected* is set to ``True``, then all distributions
that are not dependent on any other distribution are skipped.
- :type f: ``file``
+ :type f: has to support ``file``-like operations
:type skip_disconnected: ``bool``
"""
- if not isinstance(f, file):
- raise TypeError('the argument has to be of type file')
-
disconnected = []
f.write("digraph dependencies {\n")
diff --git a/src/distutils2/tests/test_depgraph.py b/src/distutils2/tests/test_depgraph.py
--- a/src/distutils2/tests/test_depgraph.py
+++ b/src/distutils2/tests/test_depgraph.py
@@ -7,12 +7,20 @@
import os
import sys
+import re
+try:
+ import cStringIO as StringIO
+except ImportErorr:
+ import StringIO
class DepGraphTestCase(support.LoggingSilencer,
unittest.TestCase):
DISTROS_DIST = ('choxie', 'grammar', 'towel-stuff')
DISTROS_EGG = ('bacon', 'banana', 'strawberry', 'cheese')
+ EDGE = re.compile(
+ r'"(?P<from>.*)" -> "(?P<to>.*)" \[label="(?P<label>.*)"\]'
+ )
def checkLists(self, l1, l2):
""" Compare two lists without taking the order into consideration """
@@ -139,6 +147,35 @@
deps = [d.name for d in depgraph.dependent_dists(dists, cheese)]
self.checkLists([], deps)
+ def test_graph_to_dot(self):
+ expected = (
+ ('towel-stuff', 'bacon', 'bacon (<=0.2)'),
+ ('grammar', 'bacon', 'truffles (>=1.2)'),
+ ('choxie', 'towel-stuff', 'towel-stuff (0.1)'),
+ ('banana', 'strawberry', 'strawberry (>=0.5)')
+ )
+
+ dists = []
+ for name in self.DISTROS_DIST + self.DISTROS_EGG:
+ dist = pkgutil.get_distribution(name, use_egg_info=True)
+ self.assertNotEqual(dist, None)
+ dists.append(dist)
+
+ graph = depgraph.generate_graph(dists)
+ buf = StringIO.StringIO()
+ depgraph.graph_to_dot(graph, buf)
+ buf.seek(0)
+ matches = []
+ lines = buf.readlines()
+ for line in lines[1:-1]: # skip the first and the last lines
+ if line[-1] == '\n':
+ line = line[:-1]
+ match = self.EDGE.match(line.strip())
+ self.assertTrue(match is not None)
+ matches.append(match.groups())
+
+ self.checkLists(matches, expected)
+
def tearDown(self):
super(unittest.TestCase, self).tearDown()
sys.path = self.sys_path
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list