Skip to content

Commit

Permalink
100% coverage of stdom, mostly by marking things pragma:no cover for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Aug 24, 2017
1 parent e6c8095 commit a3d1edf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 52 deletions.
69 changes: 32 additions & 37 deletions src/zope/structuredtext/stdom.py
Expand Up @@ -95,7 +95,7 @@ def getChildNodes(self, type=type, sts=string_types):

return NodeList(r)

def getFirstChild(self, type=type, sts=string_types):
def getFirstChild(self, type=type, sts=string_types): # pragma: no cover (not used in this project)
"""
The first child of this node. If there is no such node
this returns None
Expand All @@ -112,7 +112,7 @@ def getFirstChild(self, type=type, sts=string_types):

return n.__of__(self)

def getLastChild(self, type=type, sts=string_types):
def getLastChild(self, type=type, sts=string_types): # pragma: no cover (not used in this project)
"""
The last child of this node. If there is no such node
this returns None.
Expand All @@ -125,7 +125,6 @@ def getLastChild(self, type=type, sts=string_types):
n = TextNode(n)
return n.__of__(self)


class NodeWrapper(ParentNode):
"""
This is an acquisition-like wrapper that provides parent access for
Expand All @@ -144,7 +143,7 @@ def getParentNode(self):
The parent of this node. All nodes except Document
DocumentFragment and Attr may have a parent
"""
return self.aq_parent
return self.aq_parent # pragma: no cover (not used in this project)

def _getDOMIndex(self, children, getattr=getattr):
i = 0
Expand All @@ -153,8 +152,7 @@ def _getDOMIndex(self, children, getattr=getattr):
if getattr(child, 'aq_self', child) is self:
self._DOMIndex = i
return i
i = i+1
return None
i = i + 1

def getPreviousSibling(self):
"""
Expand All @@ -163,21 +161,21 @@ def getPreviousSibling(self):
"""

children = self.aq_parent.getChildren()
if not children:
if not children: # pragma: no cover
return None

index = getattr(self, '_DOMIndex', None)
if index is None:
index = self._getDOMIndex(children)
if index is None:
return None
return None # pragma: no cover

index = index-1
index = index - 1
if index < 0:
return None
try:
n = children[index]
except IndexError:
except IndexError: # pragma: no cover
return None
else:
if isinstance(n, string_types):
Expand All @@ -192,22 +190,22 @@ def getNextSibling(self):
there is no such node, this returns None.
"""
children = self.aq_parent.getChildren()
if not children:
if not children: # pragma: no cover
return None

index = getattr(self, '_DOMIndex', None)
if index is None:
if index is None: # pragma: no cover
index = self._getDOMIndex(children)
if index is None:
return None

index = index + 1
try:
n = children[index]
except IndexError:
except IndexError: # pragma: no cover
return None
else:
if isinstance(n, string_types):
if isinstance(n, string_types): # pragma: no cover
n = TextNode(n)
n._DOMIndex = index
return n.__of__(self)
Expand All @@ -216,7 +214,7 @@ def getOwnerDocument(self):
"""
The Document object associated with this node, if any.
"""
return self.aq_parent.getOwnerDocument()
return self.aq_parent.getOwnerDocument() # pragma: no cover (not used)

class Node(ParentNode):
"""Node Interface
Expand All @@ -235,7 +233,6 @@ def getNodeName(self):
def getNodeValue(self):
"""The value of this node, depending on its type
"""
return None

def getParentNode(self):
"""
Expand All @@ -246,7 +243,7 @@ def getParentNode(self):
def getChildren(self):
"""Get a Python sequence of children
"""
return ()
return () # pragma: no cover (not used in this project)

def getPreviousSibling(self):
"""
Expand All @@ -265,7 +262,7 @@ def getAttributes(self):
Returns a NamedNodeMap containing the attributes
of this node (if it is an element) or None otherwise.
"""
return None


def getOwnerDocument(self):
"""The Document object associated with this node, if any.
Expand All @@ -279,7 +276,7 @@ def hasChildNodes(self):
Returns true if the node has any children, false
if it doesn't.
"""
return len(self.getChildren())
return len(self.getChildren()) # pragma: no cover (not used in this project)

class TextNode(Node):

Expand All @@ -306,9 +303,7 @@ def getTagName(self):
"""The name of the element"""
return self.__class__.__name__

def getNodeName(self):
"""The name of this node, depending on its type"""
return self.__class__.__name__
getNodeName = getTagName

def getNodeType(self):
"""A code representing the type of the node."""
Expand Down Expand Up @@ -349,7 +344,7 @@ def getAttributes(self):
d[a] = getattr(self, a, '')
return NamedNodeMap(d)

def getElementsByTagName(self, tagname):
def getElementsByTagName(self, tagname): # pragma: no cover (not used in this project)
"""
Returns a NodeList of all the Elements with a given tag
name in the order in which they would be encountered in a
Expand Down Expand Up @@ -389,7 +384,7 @@ def __getitem__(self, index, type=type, sts=string_types):
def __getslice__(self, i, j):
return self._data[i:j]

def item(self, index):
def item(self, index): # pragma: no cover (not used in this project)
"""Returns the index-th item in the collection
"""
return self._data.get(index, None)
Expand All @@ -412,30 +407,30 @@ class NamedNodeMap(object):
"""

def __init__(self, data=None):
if data is None:
data = {}
self._data = data
self._data = data if data is not None else {}

def item(self, index):
"""Returns the index-th item in the map
def item(self, index): # pragma: no cover (not used in this project)
"""Returns the index-th item in the map.
This is broken on Python 3 and random on Python 2.
"""
return self._data.values().get(index, None)


def __getitem__(self, key):
def __getitem__(self, key): # pragma: no cover (not used in this project)
if isinstance(key, int):
return self.item(key)
return self._data[key]

def getLength(self):
def getLength(self): # pragma: no cover (not used in this project)
"""
The length of the NodeList
"""
return len(self._data)

__len__ = getLength

def getNamedItem(self, name):
def getNamedItem(self, name): # pragma: no cover (not used in this project)
"""
Retrieves a node specified by name. Parameters:
name Name of a node to retrieve. Return Value A Node (of any
Expand All @@ -455,31 +450,31 @@ def __init__(self, name, value, specified=1):
self.value = value
self.specified = specified

def getNodeName(self):
def getNodeName(self): # pragma: no cover (not used in this project)
"""
The name of this node, depending on its type
"""
return self.name

def getName(self):
def getName(self): # pragma: no cover (not used in this project)
"""
Returns the name of this attribute.
"""
return self.name

def getNodeValue(self):
def getNodeValue(self): # pragma: no cover (not used in this project)
"""
The value of this node, depending on its type
"""
return self.value

def getNodeType(self):
def getNodeType(self): # pragma: no cover (not used in this project)
"""
A code representing the type of the node.
"""
return ATTRIBUTE_NODE

def getSpecified(self):
def getSpecified(self): # pragma: no cover (not used in this project)
"""
If this attribute was explicitly given a value in the
original document, this is true; otherwise, it is false.
Expand Down
15 changes: 0 additions & 15 deletions src/zope/structuredtext/stng.py
Expand Up @@ -191,21 +191,6 @@ def getChildren(self):
src = [src]
return src+self._subs

def getAttribute(self, name):
return getattr(self, name, None)

def getAttributeNode(self, name):
if hasattr(self, name):
return stdom.Attr(name, getattr(self, name))
else:
return None

def getAttributes(self):
d = {}
for a in self._attributes:
d[a] = getattr(self, a, '')
return stdom.NamedNodeMap(d)

def getSubparagraphs(self):
return self._subs

Expand Down

0 comments on commit a3d1edf

Please sign in to comment.