Skip to content

Commit

Permalink
Renamed S class to n and removed the SubNode class
Browse files Browse the repository at this point in the history
  • Loading branch information
bigjason committed Jun 16, 2011
1 parent 50f91eb commit bb3c038
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
6 changes: 3 additions & 3 deletions datatree/__init__.py
@@ -1,5 +1,5 @@
from .node import Tree, S, SubNode, Name, __
from .node import Tree, n, Node, Name, __

__all__ = ['Tree', 'S', 'SubNode', 'Name', '__']
__all__ = ['Tree', 'Node', 'n', 'Name', '__']

VERSION = (0, 1, 0)
VERSION = (0, 1, 1)
13 changes: 3 additions & 10 deletions datatree/node.py
Expand Up @@ -3,7 +3,7 @@
from .symbols import Symbol
from .utils import get_class

__all__ = ['Tree', 'Node', 'SubNode', 'S', 'Name', '__']
__all__ = ['Tree', 'Node', 'n', 'Name', '__']

Name = Symbol('Name')
__ = Name
Expand Down Expand Up @@ -141,7 +141,7 @@ def add_child_node(self, child_node):
### Operator Overloads ###

def __lshift__(self, other):
if isinstance(other, SubNode) or isinstance(other, BaseNode):
if isinstance(other, BaseNode):
other = [other]
for item in other:
self.add_child_node(item)
Expand Down Expand Up @@ -180,6 +180,7 @@ def DECLARE(self, name, *attrs):
class Node(Vertice):
def __init__(self, node_name='root', node_value=None, **attrs):
super(Node, self).__init__(node_name=node_name, node_value=node_value, **attrs)
n = Node

class InstructionNode(Leaf):
pass
Expand All @@ -199,11 +200,3 @@ def __str__(self):
class CDataNode(Leaf):
pass

"""
class SubNode(object):
def __init__(self, *args, **kwargs):
self.args, self.kwargs = args, kwargs
"""
# TODO: Revisit. Replace SubNode with Node?
SubNode = Node
S = SubNode
4 changes: 2 additions & 2 deletions datatree/tests/test_dictrenderer.py
@@ -1,6 +1,6 @@
import unittest

from datatree import Tree, S
from datatree import Tree, n
from datatree.render.dictrender import DictTreeRenderer, NodeLossError

class test_DictRenderer(unittest.TestCase):
Expand Down Expand Up @@ -50,7 +50,7 @@ def test__children_distinct_names_large(self):
render = DictTreeRenderer()
tree = Tree()
with tree.root() as root:
root << [S('Node', i) for i in range(1000)]
root << [n('Node', i) for i in range(1000)]

expected = set(["Node"])
self.assertSetEqual(render._children_distinct_names(root.__children__), expected)
Expand Down
8 changes: 4 additions & 4 deletions datatree/tests/test_node.py
@@ -1,6 +1,6 @@
import unittest

from datatree.node import Node, S, Tree
from datatree.node import Node, n, Tree

class test_Node(unittest.TestCase):

Expand Down Expand Up @@ -64,7 +64,7 @@ def test_add_duplicate_nodes(self):

def test_lshift_operator_single(self):
root = Node('test_lshift_operator_single')
root << S('level1', 'two', some='attr')
root << n('level1', 'two', some='attr')

self.assertEqual(root.__node_name__, 'test_lshift_operator_single')
child = root.__children__[0]
Expand All @@ -74,7 +74,7 @@ def test_lshift_operator_single(self):

def test_lshift_operator_multi(self):
root = Node('test_lshift_operator_multi')
root << [S('level1', 'two', some='attr'), S('level1', 'two', some='attr')]
root << [n('level1', 'two', some='attr'), n('level1', 'two', some='attr')]

self.assertEqual(root.__node_name__, 'test_lshift_operator_multi')
for child in root.__children__:
Expand All @@ -84,7 +84,7 @@ def test_lshift_operator_multi(self):

def test_lshift_operator_chained(self):
root = Node()
root << S('level1', 'two', some='attr') << S('level1', 'two', some='attr')
root << n('level1', 'two', some='attr') << n('level1', 'two', some='attr')

for child in root.__children__:
self.assertEqual(child.__node_name__, 'level1')
Expand Down
4 changes: 3 additions & 1 deletion datatree/tests/test_xmlrenderer.py
Expand Up @@ -85,6 +85,8 @@ def test_parse_complex_doc(self):
novels.novel('Small Gods', year=1992)
novels.novel('The Fifth Elephant', year=1999)

e.fromstring(tree())
etree = e.fromstring(tree())
self.assertEqual(etree.find('.//genre').text, 'Fantasy/Comedy')
self.assertEqual(len(etree.findall('.//novel')), 2)


0 comments on commit bb3c038

Please sign in to comment.