~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/lore/test/test_lmath.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
"""
 
5
Tests for L{twisted.lore.lmath}.
 
6
"""
 
7
 
 
8
from xml.dom.minidom import Element, Text
 
9
 
 
10
from twisted.trial.unittest import TestCase
 
11
from twisted.python.filepath import FilePath
 
12
 
 
13
from twisted.lore.lmath import formulaeToImages
 
14
 
 
15
 
 
16
class FormulaeTests(TestCase):
 
17
    """
 
18
    Tests for L{formulaeToImages}.
 
19
    """
 
20
    def test_insertImages(self):
 
21
        """
 
22
        L{formulaeToImages} replaces any elements with the I{latexformula}
 
23
        class with I{img} elements which refer to external images generated
 
24
        based on the latex in the original elements.
 
25
        """
 
26
        parent = Element('div')
 
27
        base = FilePath(self.mktemp())
 
28
        base.makedirs()
 
29
 
 
30
        macros = Element('span')
 
31
        macros.setAttribute('class', 'latexmacros')
 
32
        text = Text()
 
33
        text.data = 'foo'
 
34
        macros.appendChild(text)
 
35
        parent.appendChild(macros)
 
36
 
 
37
        formula = Element('span')
 
38
        formula.setAttribute('class', 'latexformula')
 
39
        text = Text()
 
40
        text.data = 'bar'
 
41
        formula.appendChild(text)
 
42
        parent.appendChild(formula)
 
43
 
 
44
        # Avoid actually executing the commands to generate images from the
 
45
        # latex.  It might be nice to have some assertions about what commands
 
46
        # are executed, or perhaps even execute them and make sure an image
 
47
        # file is created, but that is a task for another day.
 
48
        commands = []
 
49
        formulaeToImages(parent, base.path, _system=commands.append)
 
50
 
 
51
        self.assertEqual(
 
52
            parent.toxml(),
 
53
            '<div><span><br/><img src="latexformula0.png"/><br/></span></div>')