def test_getAttrDict2(self): htmlStr = """<a href0="el 'tiempo com" href1="el 'tiempo" com' href2='el 'tiempo' com' href3=''el tiempo' com' href4='el 'tiempo com''>""" parser = CustomRegEx.ExtRegexParser() attrD = parser.getAttrDict(htmlStr) assert attrD[ 'href0'] == "el \'tiempo com", "Error comilla interior simple" assert attrD[ 'href1'] == "el \'tiempo\" com", "Error comillas interiores mixtas" assert attrD[ 'href2'] == "el \'tiempo\' com", "Error comillas interiores" assert attrD[ 'href3'] == "\'el tiempo\' com", "Error comillas interiores ajustadas a la izquierda" assert attrD[ 'href4'] == "el \'tiempo com\'", "Error comillas interiores ajustadas a la derecha"
def test_getAttrDict1(self, cycle): htmlLst = [ '<a', 'href0="eltiempo.com"', 'href1="eltiempo.com\'', 'href2=\'eltiempo.com\'', 'href3=eltiempo.com' ] htmlLst.append(htmlLst.pop(cycle)) htmlStr = ' '.join(htmlLst) + '>' print htmlStr parser = CustomRegEx.ExtRegexParser() tag, attrD = parser.getAttrDict(htmlStr, noTag=False) attrD.pop('*ParamPos*') assert sorted(attrD.keys()) == [ 'href%d' % k for k in range(4) ], "Los attributos reportados no corresponde a los reales" assert set(attrD.values()) == set( ["eltiempo.com"] ), "Por lo menos el valor de un attributo reportado no corresponde al real"
def HTMLstruct(self): tagSpan = self.regexpEd.getSelRange('actMatch') content = self.regexpEd.getContent(*tagSpan) try: htmlParse = CustomRegEx.ExtRegexParser({}, []).htmlStruct(content, 0) except: equis = 'Not HTML conform' tkMessageBox.showinfo('Actual match HTMLstruct', equis) else: fmt = '{:<20} {:<40}'.format # equis = '\n'.join([fmt(x[0].count('.')*' ' + '*' + x[0].rpartition('.')[2],x[1][:40]) for x in htmlParse]) equis = [ fmt(x[0].count('.') * ' ' + '*' + x[0].rpartition('.')[2], x[1][:40]) for x in htmlParse ] from xbmcgui import Dialog k = Dialog().select('Actual match HTMLstruct', equis)
def test_getAttrDict0(self, cycle): htmlLst = [ '<a', 'href2=eltiempo.com', 'href1', 'href0=\"eltiempo.com\"' ] htmlLst.append(htmlLst.pop(cycle)) htmlStr = ' '.join(htmlLst) + '>' print htmlStr parser = CustomRegEx.ExtRegexParser() htmlStr = 18 * ' ' + htmlStr tag, attrD = parser.getAttrDict(htmlStr, offset=18, noTag=False) attrP = attrD.pop('*ParamPos*') assert tag == 'a', "El tag reportado no corresponde al tag real" assert len(attrD) == 3 assert attrD[ 'href0'] == "eltiempo.com", "Error valor de attributo normal" assert attrD['href1'] == "", "Error atributo sin valor" assert attrD[ 'href2'] == "eltiempo.com", "Error valor de attributo sin comillas" getSlice = htmlStr.__getslice__ print '***' + htmlStr + '***' for k in attrD: print k, attrD[k], getSlice(*attrP[k]), attrP[k] assert all([attrD[k] == getSlice(*attrP[k]) for k in attrD])