Ejemplo n.º 1
0
    def _getCountersList(self, page):
        parser = ParserFactory().make(page, self._config)
        parser.addCommand(NameHarvester(parser))
        parser.toHtml(page.content)

        result = [u""] + sorted(list(NameHarvester.counters))

        return result
Ejemplo n.º 2
0
    def _getCountersList(self, page):
        parser = ParserFactory().make(page, self._config)
        parser.addCommand(NameHarvester(parser))
        parser.toHtml(page.content)

        result = [u""] + sorted(list(NameHarvester.counters))

        return result
Ejemplo n.º 3
0
class TexEquationTest(unittest.TestCase):
    def setUp(self):
        self.filesPath = u"../test/samplefiles/"
        self.__createWiki()

        dirlist = [u"../plugins/texequation"]

        self.loader = PluginsLoader(Application)
        self.loader.load(dirlist)

        self.testPage = self.wikiroot[u"Страница 1"]
        self.parser = ParserFactory().make(self.testPage, Application.config)

    def tearDown(self):
        removeDir(self.path)
        self.loader.clear()

    def __createWiki(self):
        # Здесь будет создаваться вики
        self.path = u"../test/testwiki"
        removeDir(self.path)

        self.wikiroot = WikiDocument.create(self.path)

        WikiPageFactory().create(self.wikiroot, u"Страница 1", [])
        self.testPage = self.wikiroot[u"Страница 1"]

    def testPluginLoad(self):
        self.assertEqual(len(self.loader), 1)

    def testTex1(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn = u"y = f(x)"
        text = u"{$ %s $}" % (eqn)

        fname = texrender.getImageName(eqn)
        path = os.path.join(Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<img src="{0}"/>'.format(path.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def testTex2(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn1 = u"y = f(x)"
        eqn2 = u"y = e^x"
        eqn3 = u"y = \sum_{i=0}\pi"

        text = u"""бла-бла-бла
* бла-бла-бла {$ %s $} 1111
* бла-бла-бла {$ %s $} 222
* бла-бла-бла {$ %s $} 333""" % (eqn1, eqn2, eqn3)

        fname1 = texrender.getImageName(eqn1)
        fname2 = texrender.getImageName(eqn2)
        fname3 = texrender.getImageName(eqn3)

        path1 = os.path.join(Thumbnails.getRelativeThumbDir(), fname1)
        path2 = os.path.join(Thumbnails.getRelativeThumbDir(), fname2)
        path3 = os.path.join(Thumbnails.getRelativeThumbDir(), fname3)

        result_right = u'''бла-бла-бла
<ul><li>бла-бла-бла <img src="{path1}"/> 1111</li><li>бла-бла-бла <img src="{path2}"/> 222</li><li>бла-бла-бла <img src="{path3}"/> 333</li></ul>'''.format(
            path1=path1.replace("\\", "/"),
            path2=path2.replace("\\", "/"),
            path3=path3.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path1 = os.path.join(self.parser.page.path, path1)
        full_path2 = os.path.join(self.parser.page.path, path2)
        full_path3 = os.path.join(self.parser.page.path, path3)

        self.assertTrue(os.path.exists(full_path1), full_path1)
        self.assertTrue(os.path.exists(full_path2), full_path2)
        self.assertTrue(os.path.exists(full_path3), full_path3)

    def testTex3(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn = u"y = f(x)"
        text = u"[[{$ %s $} -> http://jenyay.net]]" % (eqn)

        fname = texrender.getImageName(eqn)
        path = os.path.join(Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<a href="http://jenyay.net"><img src="{0}"/></a>'.format(
            path.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def testTex4(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn = u"y = f(x)"
        text = u"[[http://jenyay.net | {$ %s $}]]" % (eqn)

        fname = texrender.getImageName(eqn)
        path = os.path.join(Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<a href="http://jenyay.net"><img src="{0}"/></a>'.format(
            path.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def testTex5(self):
        text = u"{$ $}"
        result_right = u''

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

    def testTexRussian(self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails(self.parser.page)
        texrender = getTexRender(thumb.getThumbPath(True))

        eqn = u"y = бла-бла-бла"
        text = u"{$ %s $}" % (eqn)

        fname = texrender.getImageName(eqn)
        path = os.path.join(Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<img src="{0}"/>'.format(path.replace("\\", "/"))

        result = self.parser.toHtml(text)

        self.assertEqual(result_right, result, result)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def testHeaderTex(self):
        text = u"бла-бла-бла \n!!! Заголовок {$e^x$}\nбла-бла-бла"
        result_parse = self.parser.toHtml(text)

        self.assertTrue(
            result_parse.startswith(
                u'бла-бла-бла \n<h2>Заголовок <img src="__attach/__thumb/eqn_')
        )

    def testTexLinks1(self):
        pagelinks = [u"Страница 1", u"/Страница 1", u"/Страница 2/Страница 3"]
        for link in pagelinks:
            text = u"бла-бла-бла \n[[%s | {$e^x$} ]] бла-бла-бла\nбла-бла-бла" % (
                link)
            result_begin = u'бла-бла-бла \n<a href="%s"><img src="__attach/__thumb/eqn_' % (
                link)

            self.assertTrue(self.parser.toHtml(text).startswith(result_begin))

    def testTexLinks2(self):
        pagelinks = [u"Страница 1", u"/Страница 1", u"/Страница 2/Страница 3"]
        for link in pagelinks:
            text = u"бла-бла-бла \n[[{$e^x$} -> %s]] бла-бла-бла\nбла-бла-бла" % (
                link)
            result_begin = u'бла-бла-бла \n<a href="%s"><img src="__attach/__thumb/eqn_' % (
                link)

            self.assertTrue(self.parser.toHtml(text).startswith(result_begin))

    def testThumbnailsClear2_attach(self):
        fname = u"accept.png"
        attachPath = os.path.join(self.filesPath, fname)
        Attachment(self.parser.page).attach([attachPath])

        thumb = Thumbnails(self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml(text)

        self.assertFalse(len(os.listdir(thumb.getThumbPath(False))) == 0)

        thumb.clearDir()

        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 0)

    def testThumbnailsClear3_attach(self):
        fname = u"accept.png"
        attachPath = os.path.join(self.filesPath, fname)
        Attachment(self.parser.page).attach([attachPath])

        thumb = Thumbnails(self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml("{$ %s $}" % (eqn1))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)

        self.parser.toHtml("{$ %s $}" % (eqn2))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)

    def testThumbnailsClear2(self):
        thumb = Thumbnails(self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml(text)

        self.assertFalse(len(os.listdir(thumb.getThumbPath(False))) == 0)

        thumb.clearDir()

        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 0)

    def testThumbnailsClear3(self):
        thumb = Thumbnails(self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml("{$ %s $}" % (eqn1))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)

        self.parser.toHtml("{$ %s $}" % (eqn2))
        self.assertEqual(len(os.listdir(thumb.getThumbPath(False))), 2)
Ejemplo n.º 4
0
class TexEquationTest(unittest.TestCase, BaseOutWikerGUIMixin):
    def setUp(self):
        self.initApplication()
        self.wikiroot = self.createWiki()
        self.testPage = WikiPageFactory().create(self.wikiroot, "Страница 1",
                                                 [])

        self.filesPath = "testdata/samplefiles/"
        dirlist = ["plugins/texequation"]

        self.loader = PluginsLoader(self.application)
        self.loader.load(dirlist)

        self.testPage = self.wikiroot["Страница 1"]
        self.parser = ParserFactory().make(self.testPage,
                                           self.application.config)

    def tearDown(self):
        self.loader.clear()
        self.destroyApplication()
        self.destroyWiki(self.wikiroot)

    def testPluginLoad(self):
        self.assertEqual(len(self.loader), 1)

    def test_inline_01(self):
        from texequation.defines import KATEX_DIR_NAME
        eqn = "y = f(x)"
        text = "{{$ {eqn} $}}".format(eqn=eqn)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), KATEX_DIR_NAME)

        result_lines = [
            '<span class="texequation-inline" id="texequation-inline-0"></span>',
        ]

        footer_lines = [
            'var element_0 = document.getElementById("texequation-inline-0");',
            'katex.render("{}",'.format(eqn),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_inline_02(self):
        from texequation.defines import KATEX_DIR_NAME
        eqn1 = "y = f1(x)"
        eqn2 = "y = f2(x)"
        text = "{{$ {eqn1} $}} {{$ {eqn2} $}}".format(eqn1=eqn1, eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), KATEX_DIR_NAME)

        result_lines = [
            '<span class="texequation-inline" id="texequation-inline-0"></span>',
            '<span class="texequation-inline" id="texequation-inline-1"></span>',
        ]

        footer_lines = [
            'var element_0 = document.getElementById("texequation-inline-0");',
            'var element_1 = document.getElementById("texequation-inline-1");',
            'katex.render("{}",'.format(eqn1),
            'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_inline_03(self):
        eqn = "y = f(x)"
        text = "Это строчная формула. {{$ {eqn} $}} Она не разрывает строку.".format(
            eqn=eqn)

        result = self.parser.toHtml(text)

        self.assertIn(
            'Это строчная формула. <span class="texequation-inline" id="texequation-inline-0"></span> Она не разрывает строку.',
            result)

    def test_block_01(self):
        from texequation.defines import KATEX_DIR_NAME
        eqn = "y = f(x)"
        text = "{{$$ {eqn} $$}}".format(eqn=eqn)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), KATEX_DIR_NAME)

        result_lines = [
            '<span class="texequation-block" id="texequation-block-0"></span>',
        ]

        footer_lines = [
            'var element_0 = document.getElementById("texequation-block-0");',
            'katex.render("{}",'.format(eqn),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_block_02(self):
        from texequation.defines import KATEX_DIR_NAME
        eqn1 = "y = f1(x)"
        eqn2 = "y = f2(x)"

        text = "{{$$ {eqn1} $$}} {{$$ {eqn2} $$}}".format(eqn1=eqn1, eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), KATEX_DIR_NAME)

        result_lines = [
            '<span class="texequation-block" id="texequation-block-0"></span>',
            '<span class="texequation-block" id="texequation-block-1"></span>',
        ]

        footer_lines = [
            'var element_0 = document.getElementById("texequation-block-0");',
            'var element_1 = document.getElementById("texequation-block-1");',
            'katex.render("{}",'.format(eqn1),
            'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_mixed_01(self):
        from texequation.defines import KATEX_DIR_NAME
        eqn1 = "y = f1(x)"
        eqn2 = "y = f2(x)"

        text = "{{$$ {eqn1} $$}} {{$ {eqn2} $}}".format(eqn1=eqn1, eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), KATEX_DIR_NAME)

        result_lines = [
            '<span class="texequation-block" id="texequation-block-0"></span>',
            '<span class="texequation-inline" id="texequation-inline-0"></span>',
        ]

        footer_lines = [
            'var element_0 = document.getElementById("texequation-block-0");',
            'var element_0 = document.getElementById("texequation-inline-0");',
            'katex.render("{}",'.format(eqn1),
            'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)
Ejemplo n.º 5
0
class TexEquationTest(unittest.TestCase):
    def setUp(self):
        self.filesPath = u"../test/samplefiles/"
        self.__createWiki()

        dirlist = [u"../plugins/texequation"]

        self.loader = PluginsLoader(Application)
        self.loader.load(dirlist)

        self.testPage = self.wikiroot[u"Страница 1"]
        self.parser = ParserFactory().make(self.testPage, Application.config)

    def tearDown(self):
        removeDir(self.path)
        self.loader.clear()

    def __createWiki(self):
        # Здесь будет создаваться вики
        self.path = u"../test/testwiki"
        removeDir(self.path)

        self.wikiroot = WikiDocument.create(self.path)

        WikiPageFactory().create(self.wikiroot, u"Страница 1", [])
        self.testPage = self.wikiroot[u"Страница 1"]

    def testPluginLoad(self):
        self.assertEqual(len(self.loader), 1)

    def test_inline_01(self):
        eqn = u"y = f(x)"
        text = u"{{$ {eqn} $}}".format(eqn=eqn)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), 'katex')

        result_lines = [
            u'<span class="texequation-inline" id="texequation-inline-0"></span>',
        ]

        footer_lines = [
            u'var element = document.getElementById("texequation-inline-0");',
            u'katex.render("{}",'.format(eqn),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_inline_02(self):
        eqn1 = u"y = f1(x)"
        eqn2 = u"y = f2(x)"
        text = u"{{$ {eqn1} $}} {{$ {eqn2} $}}".format(eqn1=eqn1, eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), 'katex')

        result_lines = [
            u'<span class="texequation-inline" id="texequation-inline-0"></span>',
            u'<span class="texequation-inline" id="texequation-inline-1"></span>',
        ]

        footer_lines = [
            u'var element = document.getElementById("texequation-inline-0");',
            u'var element = document.getElementById("texequation-inline-1");',
            u'katex.render("{}",'.format(eqn1),
            u'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_inline_03(self):
        eqn = u"y = f(x)"
        text = u"Это строчная формула. {{$ {eqn} $}} Она не разрывает строку.".format(
            eqn=eqn)

        result = self.parser.toHtml(text)

        self.assertIn(
            u'Это строчная формула. <span class="texequation-inline" id="texequation-inline-0"></span> Она не разрывает строку.',
            result)

    def test_block_01(self):
        eqn = u"y = f(x)"
        text = u"{{$$ {eqn} $$}}".format(eqn=eqn)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), 'katex')

        result_lines = [
            u'<span class="texequation-block" id="texequation-block-0"></span>',
        ]

        footer_lines = [
            u'var element = document.getElementById("texequation-block-0");',
            u'katex.render("{}",'.format(eqn),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_block_02(self):
        eqn1 = u"y = f1(x)"
        eqn2 = u"y = f2(x)"

        text = u"{{$$ {eqn1} $$}} {{$$ {eqn2} $$}}".format(eqn1=eqn1,
                                                           eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), 'katex')

        result_lines = [
            u'<span class="texequation-block" id="texequation-block-0"></span>',
            u'<span class="texequation-block" id="texequation-block-1"></span>',
        ]

        footer_lines = [
            u'var element = document.getElementById("texequation-block-0");',
            u'var element = document.getElementById("texequation-block-1");',
            u'katex.render("{}",'.format(eqn1),
            u'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)

    def test_mixed_01(self):
        eqn1 = u"y = f1(x)"
        eqn2 = u"y = f2(x)"

        text = u"{{$$ {eqn1} $$}} {{$ {eqn2} $}}".format(eqn1=eqn1, eqn2=eqn2)

        path = os.path.join(Thumbnails.getRelativeThumbDir(), 'katex')

        result_lines = [
            u'<span class="texequation-block" id="texequation-block-0"></span>',
            u'<span class="texequation-inline" id="texequation-inline-0"></span>',
        ]

        footer_lines = [
            u'var element = document.getElementById("texequation-block-0");',
            u'var element = document.getElementById("texequation-inline-0");',
            u'katex.render("{}",'.format(eqn1),
            u'katex.render("{}",'.format(eqn2),
        ]

        result = self.parser.toHtml(text)

        for line in result_lines:
            self.assertIn(line, result)

        for line in footer_lines:
            self.assertIn(line, self.parser.footer)

        full_path = os.path.join(self.parser.page.path, path)
        self.assertTrue(os.path.exists(full_path), full_path)
Ejemplo n.º 6
0
class TexEquationTest (unittest.TestCase):
    def setUp (self):
        self.filesPath = u"../test/samplefiles/"
        self.__createWiki()

        dirlist = [u"../plugins/texequation"]

        self.loader = PluginsLoader(Application)
        self.loader.load (dirlist)

        self.testPage = self.wikiroot[u"Страница 1"]
        self.parser = ParserFactory().make (self.testPage, Application.config)


    def tearDown (self):
        removeDir (self.path)
        self.loader.clear()


    def __createWiki (self):
        # Здесь будет создаваться вики
        self.path = u"../test/testwiki"
        removeDir (self.path)

        self.wikiroot = WikiDocument.create (self.path)

        WikiPageFactory().create (self.wikiroot, u"Страница 1", [])
        self.testPage = self.wikiroot[u"Страница 1"]


    def testPluginLoad (self):
        self.assertEqual (len (self.loader), 1)


    def testTex1 (self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails (self.parser.page)
        texrender = getTexRender(thumb.getThumbPath (True))

        eqn = u"y = f(x)"
        text = u"{$ %s $}" % (eqn)

        fname = texrender.getImageName (eqn)
        path = os.path.join (Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<img src="{0}"/>'.format (path.replace ("\\", "/"))

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)

        full_path = os.path.join (self.parser.page.path, path)
        self.assertTrue (os.path.exists (full_path), full_path)


    def testTex2 (self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails (self.parser.page)
        texrender = getTexRender(thumb.getThumbPath (True))

        eqn1 = u"y = f(x)"
        eqn2 = u"y = e^x"
        eqn3 = u"y = \sum_{i=0}\pi"

        text = u"""бла-бла-бла
* бла-бла-бла {$ %s $} 1111
* бла-бла-бла {$ %s $} 222
* бла-бла-бла {$ %s $} 333""" % (eqn1, eqn2, eqn3)

        fname1 = texrender.getImageName (eqn1)
        fname2 = texrender.getImageName (eqn2)
        fname3 = texrender.getImageName (eqn3)

        path1 = os.path.join (Thumbnails.getRelativeThumbDir(), fname1)
        path2 = os.path.join (Thumbnails.getRelativeThumbDir(), fname2)
        path3 = os.path.join (Thumbnails.getRelativeThumbDir(), fname3)

        result_right = u'''бла-бла-бла
<ul><li>бла-бла-бла <img src="{path1}"/> 1111</li><li>бла-бла-бла <img src="{path2}"/> 222</li><li>бла-бла-бла <img src="{path3}"/> 333</li></ul>'''.format (path1=path1.replace ("\\", "/"),
                                                                                                                                                                                        path2=path2.replace ("\\", "/"),
                                                                                                                                                                                        path3=path3.replace ("\\", "/"))

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)

        full_path1 = os.path.join (self.parser.page.path, path1)
        full_path2 = os.path.join (self.parser.page.path, path2)
        full_path3 = os.path.join (self.parser.page.path, path3)

        self.assertTrue (os.path.exists (full_path1), full_path1)
        self.assertTrue (os.path.exists (full_path2), full_path2)
        self.assertTrue (os.path.exists (full_path3), full_path3)


    def testTex3 (self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails (self.parser.page)
        texrender = getTexRender(thumb.getThumbPath (True))

        eqn = u"y = f(x)"
        text = u"[[{$ %s $} -> http://jenyay.net]]" % (eqn)

        fname = texrender.getImageName (eqn)
        path = os.path.join (Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<a href="http://jenyay.net"><img src="{0}"/></a>'.format (path.replace ("\\", "/"))

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)

        full_path = os.path.join (self.parser.page.path, path)
        self.assertTrue (os.path.exists (full_path), full_path)


    def testTex4 (self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails (self.parser.page)
        texrender = getTexRender(thumb.getThumbPath (True))

        eqn = u"y = f(x)"
        text = u"[[http://jenyay.net | {$ %s $}]]" % (eqn)

        fname = texrender.getImageName (eqn)
        path = os.path.join (Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<a href="http://jenyay.net"><img src="{0}"/></a>'.format (path.replace ("\\", "/"))

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)

        full_path = os.path.join (self.parser.page.path, path)
        self.assertTrue (os.path.exists (full_path), full_path)


    def testTex5 (self):
        text = u"{$ $}"
        result_right = u''

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)


    def testTexRussian (self):
        from texequation.texrender import getTexRender
        thumb = Thumbnails (self.parser.page)
        texrender = getTexRender(thumb.getThumbPath (True))

        eqn = u"y = бла-бла-бла"
        text = u"{$ %s $}" % (eqn)

        fname = texrender.getImageName (eqn)
        path = os.path.join (Thumbnails.getRelativeThumbDir(), fname)

        result_right = u'<img src="{0}"/>'.format (path.replace ("\\", "/"))

        result = self.parser.toHtml (text)

        self.assertEqual (result_right, result, result)

        full_path = os.path.join (self.parser.page.path, path)
        self.assertTrue (os.path.exists (full_path), full_path)


    def testHeaderTex (self):
        text = u"бла-бла-бла \n!!! Заголовок {$e^x$}\nбла-бла-бла"
        result_parse = self.parser.toHtml (text)

        self.assertTrue (result_parse.startswith (u'бла-бла-бла \n<h2>Заголовок <img src="__attach/__thumb/eqn_'))


    def testTexLinks1 (self):
        pagelinks = [u"Страница 1", u"/Страница 1", u"/Страница 2/Страница 3"]
        for link in pagelinks:
            text = u"бла-бла-бла \n[[%s | {$e^x$} ]] бла-бла-бла\nбла-бла-бла" % (link)
            result_begin = u'бла-бла-бла \n<a href="%s"><img src="__attach/__thumb/eqn_' % (link)

            self.assertTrue (self.parser.toHtml (text).startswith (result_begin))


    def testTexLinks2 (self):
        pagelinks = [u"Страница 1", u"/Страница 1", u"/Страница 2/Страница 3"]
        for link in pagelinks:
            text = u"бла-бла-бла \n[[{$e^x$} -> %s]] бла-бла-бла\nбла-бла-бла" % (link)
            result_begin = u'бла-бла-бла \n<a href="%s"><img src="__attach/__thumb/eqn_' % (link)

            self.assertTrue (self.parser.toHtml (text).startswith (result_begin))


    def testThumbnailsClear2_attach (self):
        fname = u"accept.png"
        attachPath = os.path.join (self.filesPath, fname)
        Attachment (self.parser.page).attach ([attachPath])

        thumb = Thumbnails (self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml (text)

        self.assertFalse (len (os.listdir (thumb.getThumbPath (False))) == 0)

        thumb.clearDir()

        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 0)


    def testThumbnailsClear3_attach (self):
        fname = u"accept.png"
        attachPath = os.path.join (self.filesPath, fname)
        Attachment (self.parser.page).attach ([attachPath])

        thumb = Thumbnails (self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml ("{$ %s $}" % (eqn1))
        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 2)

        self.parser.toHtml ("{$ %s $}" % (eqn2))
        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 2)


    def testThumbnailsClear2 (self):
        thumb = Thumbnails (self.parser.page)

        eqn = "y = f(x)"

        text = "{$ %s $}" % (eqn)
        self.parser.toHtml (text)

        self.assertFalse (len (os.listdir (thumb.getThumbPath (False))) == 0)

        thumb.clearDir()

        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 0)


    def testThumbnailsClear3 (self):
        thumb = Thumbnails (self.parser.page)

        eqn1 = "y = f(x)"
        eqn2 = "y = f_2(x)"

        self.parser.toHtml ("{$ %s $}" % (eqn1))
        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 2)

        self.parser.toHtml ("{$ %s $}" % (eqn2))
        self.assertEqual (len (os.listdir (thumb.getThumbPath (False))), 2)