diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-01-16 11:30:16 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-01-16 11:34:57 +0000 |
commit | 724274268ee6423da508499a31450b08e20316d7 (patch) | |
tree | 10bb82967b80ce42413a5dfbe8116de76aa08ddf /morphlib | |
parent | 0f14928fb700d14ed1ebb8675c26b263bf2bc58c (diff) | |
download | morph-724274268ee6423da508499a31450b08e20316d7.tar.gz |
Add first tests for BuildDependencyGraph.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/builddependencygraph.py | 8 | ||||
-rw-r--r-- | morphlib/builddependencygraph_tests.py | 71 |
2 files changed, 75 insertions, 4 deletions
diff --git a/morphlib/builddependencygraph.py b/morphlib/builddependencygraph.py index 146cdc54..7a432005 100644 --- a/morphlib/builddependencygraph.py +++ b/morphlib/builddependencygraph.py @@ -45,16 +45,16 @@ class Node(object): def depends_on(self, other): return other in self.dependencies - def __str__(self): + def __str__(self): # pragma: no cover return '%s (%s)' % (self.morphology.name, self.morphology.kind) - def __deepcopy__(self, memo): + def __deepcopy__(self, memo): # pragma: no cover return Node(self.morphology) class NodeList(list): - def __deepcopy__(self, memo): + def __deepcopy__(self, memo): # pragma: no cover nodes = NodeList() old_to_new = {} @@ -73,7 +73,7 @@ class NodeList(list): return nodes -class BuildDependencyGraph(object): +class BuildDependencyGraph(object): # pragma: no cover def __init__(self, loader, morphology): self.loader = loader diff --git a/morphlib/builddependencygraph_tests.py b/morphlib/builddependencygraph_tests.py new file mode 100644 index 00000000..dec4e49c --- /dev/null +++ b/morphlib/builddependencygraph_tests.py @@ -0,0 +1,71 @@ +# Copyright (C) 2012 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import os +import StringIO +import unittest + +import morphlib + + +class BuildDependencyGraphTests(unittest.TestCase): + + def test_create_node_with_morphology(self): + fake_morphology = "fake morphology" + + node = morphlib.builddependencygraph.Node(fake_morphology) + self.assertEqual(node.morphology, fake_morphology) + + def test_node_add_remove_dependency(self): + node1 = morphlib.builddependencygraph.Node(None) + node2 = morphlib.builddependencygraph.Node(None) + + node1.add_dependency(node2) + + assert(node2 in node1.dependencies) + assert(node1 in node2.dependents) + + assert(node1.depends_on(node2)) + + node2.add_dependency(node1) + + assert(node2 in node1.dependencies) + assert(node1 in node2.dependents) + assert(node1 in node2.dependencies) + assert(node2 in node1.dependents) + + assert(node1.depends_on(node2)) + assert(node2.depends_on(node1)) + + node1.remove_dependency(node2) + + assert(node2 not in node1.dependencies) + assert(node1 not in node2.dependents) + assert(node1 in node2.dependencies) + assert(node2 in node1.dependents) + + assert(not node1.depends_on(node2)) + assert(node2.depends_on(node1)) + + node2.remove_dependency(node1) + + assert(node2 not in node1.dependencies) + assert(node1 not in node2.dependents) + assert(node1 not in node2.dependencies) + assert(node2 not in node1.dependents) + + assert(not node1.depends_on(node2)) + assert(not node2.depends_on(node1)) |