Skip to content

Commit

Permalink
twisted.web._newresource: test child of path leaf
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.twistedmatrix.com/svn/Twisted/branches/new-resource-5379-2@38359 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
  • Loading branch information
glyph committed May 6, 2013
1 parent 585ff5f commit 4f432c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion twisted/web/_newresource.py
Expand Up @@ -56,7 +56,9 @@ def child(self):
@raises Something: If this is a leaf path.
"""
return self.segments[0], self.__class__(self.segments[1:])
segments, child = self.descend(1)
segment = segments[0]
return segment, child


def descend(self, depth):
Expand Down
13 changes: 8 additions & 5 deletions twisted/web/test/test_newresource.py
Expand Up @@ -44,7 +44,6 @@ def test_leaf(self):
l = Path.leaf()
self.assertEqual(l.segments, ())

# XXX Test child() of leaf raises.

def test_child(self):
"""
Expand All @@ -57,6 +56,12 @@ def test_child(self):
self.assertEqual(child.segments, (u"bar", u"baz"))


def test_leafHasNoChild(self):
"""L{Path.child} raises ValueError on leaf nodes."""
l = Path.leaf()
self.assertRaises(ValueError, l.child)


def test_traverseUsing(self):
"""
L{Path.traverseUsing} returns a L{_TraversalStep}.
Expand All @@ -72,17 +77,15 @@ def test_descend(self):
p = Path.fromString("/foo/bar/baz")
consumed, remainder = p.descend(2)
self.assertEqual(consumed, (u"foo", u"bar"))
# XXX: Should the resulting remainder Path have some indicaton
# of its history?
self.assertEqual(remainder, Path((u"baz",)))


def test_descendAll(self):
"""L{Path.descend}ing through all segments leaves empty remainder."""
"""L{Path.descend}ing through all segments leaves a leaf."""
p = Path.fromString("/foo/bar/baz")
consumed, remainder = p.descend(3)
self.assertEqual(consumed, (u"foo", u"bar", u"baz"))
self.assertEqual(remainder, Path(()))
self.assertEqual(remainder, Path.leaf())


def test_descendTooDeepRaises(self):
Expand Down

0 comments on commit 4f432c4

Please sign in to comment.