def test_sourceFragmentElement(self): """ L{_SourceFragmentElement} renders source lines at and around the line number indicated by a frame object. """ element = _SourceFragmentElement( TagLoader(tags.div( tags.span(render="lineNumber"), tags.span(render="sourceLine"), render="sourceLines")), self.frame) source = [ u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}message = ' u'"This is a problem"', u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}raise Exception(message)', u'# Figure out the line number from which the exception will be ' u'raised.', ] d = flattenString(None, element) d.addCallback( self.assertEqual, ''.join([ '<div class="snippet%sLine"><span>%d</span><span>%s</span>' '</div>' % ( ["", "Highlight"][lineNumber == 1], self.base + lineNumber, (u" \N{NO-BREAK SPACE}" * 4 + sourceLine).encode( 'utf-8')) for (lineNumber, sourceLine) in enumerate(source)])) return d
def test_sourceFragmentElement(self): """ L{_SourceFragmentElement} renders source lines at and around the line number indicated by a frame object. """ element = _SourceFragmentElement( TagLoader( tags.div(tags.span(render="lineNumber"), tags.span(render="sourceLine"), render="sourceLines")), self.frame) source = [ u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}message = ' u'"This is a problem"', u' \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}raise Exception(message)', u'# Figure out the line number from which the exception will be ' u'raised.', ] d = flattenString(None, element) d.addCallback( self.assertEqual, ''.join([ '<div class="snippet%sLine"><span>%d</span><span>%s</span>' '</div>' % (["", "Highlight"][lineNumber == 1], self.base + lineNumber, (u" \N{NO-BREAK SPACE}" * 4 + sourceLine).encode('utf-8')) for (lineNumber, sourceLine) in enumerate(source) ])) return d
def test_sourceFragmentElement(self): """ L{_SourceFragmentElement} renders source lines at and around the line number indicated by a frame object. """ element = _SourceFragmentElement( TagLoader( tags.div( tags.span(render="lineNumber"), tags.span(render="sourceLine"), render="sourceLines", )), self.frame, ) source = [ " \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}message = " '"This is a problem"', " \N{NO-BREAK SPACE} \N{NO-BREAK SPACE}raise Exception(message)", "", ] d = flattenString(None, element) stringToCheckFor = "" for (lineNumber, sourceLine) in enumerate(source): template = '<div class="snippet{}Line"><span>{}</span><span>{}</span></div>' if lineNumber <= 1: stringToCheckFor += template.format( ["", "Highlight"][lineNumber == 1], self.base + lineNumber, (" \N{NO-BREAK SPACE}" * 4 + sourceLine), ) else: stringToCheckFor += template.format("", self.base + lineNumber, ("" + sourceLine)) bytesToCheckFor = stringToCheckFor.encode("utf8") d.addCallback(self.assertEqual, bytesToCheckFor) return d