def testGetCommandsByPos_in_03 (self): text = u'(:command:)' pos = 1 result = getCommandsByPos (text, pos) self.assertEqual (len (result), 1) self.assertEqual (result[0].groupdict()['name'], u'command')
def testGetCommandsByPos_nested_01 (self): text = u'(:command:)(:comamnd2:)(:command2end:)(:commandend:)' pos = 1 result = getCommandsByPos (text, pos) self.assertEqual (len (result), 1) self.assertEqual (result[0].groupdict()['name'], u'command')
def testGetCommandsByPos_nested_03(self): text = '(:command:)(:command2:)(:command2end:)(:commandend:)' pos = 25 result = getCommandsByPos(text, pos) self.assertEqual(len(result), 2) self.assertEqual(result[0].groupdict()['name'], 'command') self.assertEqual(result[1].groupdict()['name'], 'command2')
def getTableByPos(text, position): """ Return suffix for command name for most nested (:tableNN:) command in the position """ regex = re.compile(r'table(?P<suffix>\d*)$', re.UNICODE) matches = getCommandsByPos(text, position) matches.reverse() for match in matches: name = match.groupdict()['name'] tableMatch = regex.match(name) if tableMatch: return tableMatch.groupdict()['suffix'] return None
def getTableByPos(text, position): """ Return suffix for command name for most nested (:tableNN:) command in the position """ regex = re.compile(r'table(?P<suffix>\d*)$') matches = getCommandsByPos(text, position) matches.reverse() for match in matches: name = match.groupdict()['name'] tableMatch = regex.match(name) if tableMatch: return tableMatch.groupdict()['suffix'] return None
def testGetCommandsByPos_empty (self): text = u'' pos = 0 result = getCommandsByPos (text, pos) self.assertEqual (result, [])
def testGetCommandsByPos_in_04 (self): text = u'(:command2:)(:command:)(:commandend:)' pos = 12 result = getCommandsByPos (text, pos) self.assertEqual (len (result), 0)
def testGetCommandsByPos_out_02 (self): text = u'(:command:)(:commandend:)' pos = 25 result = getCommandsByPos (text, pos) self.assertEqual (result, [])