src/cm/tests/test_spannifier.py
author Simon Descarpentries <sid@sopinspace.com>
Wed, 30 Oct 2013 18:08:42 +0100
changeset 556 69503659fe8f
parent 271 542f1b389a29
permissions -rw-r--r--
[c_selection.js] If safari_mobile, get current selection from a previously created global variable [c_sync.js] ref where the safari_mobile global is used [c_text_view_comments.js] if safari_mobile update selection also on selectionChange event [text_view_comments.html] if safari_mobile store a clone of the current selection on each selectionChange set layout width to 99% to improve display factorize safari mobile detection code

# -*- coding: utf-8 -*-
from django.test import TestCase
from cm.utils.spannifier import *
from BeautifulSoup import BeautifulSoup

# python manage.py test 

# python manage.py test cm.SpannifyTest

file_tests = ["simple.html",]

class SpannifyTest(TestCase):
    
    def test_spannify(self):
        string_tests_spannify = [
                                 [u"""<body>kéké</body>""", 
                                  u"""<body><span id="sv_0" class="c-s"><span id="sv-0" class="c-count-0 c-c">kéké</span></span></body>""",
                                  u'kéké',
                                  ],
                                  
                                 [u"""<body>aaa <span>bbb</span> ccc ddd <b>eee</b></body>""",
                                  u"""<body><span id="sv_0" class="c-s"><span id="sv-0" class="c-count-0 c-c">aaa </span></span><span><span id="sv_1" class="c-s"><span id="sv-1" class="c-count-0 c-c">bbb</span></span></span><span id="sv_2" class="c-s"><span id="sv-2" class="c-count-0 c-c"> ccc ddd </span></span><b><span id="sv_3" class="c-s"><span id="sv-3" class="c-count-0 c-c">eee</span></span></b></body>""",
                                  u"""aaa bbb ccc ddd eee""",]                                  
                                ]

#        
        for input, expected_spanned, expected_raw in string_tests_spannify :
            res, raw_text, corresp = spannify(input)
            self.assertEqual(unicode(res),expected_spanned)
            self.assertEqual(unicode(raw_text),expected_raw)

#        for filename in file_tests :
#            if filename[:5] == "span_" :
#                doc = xml.dom.minidom.parse('cm/tests/data/%s' % filename)
#                soup = BeautifulSoup('cm/tests/data/%s' % filename, convertEntities=["xml", "html"])
#                
#                res = spannifier.spannify(doc)
#                res2 = spannifier.spannify_new(soup)
#                
#                expectedResult = file('cm/tests/data/res_%s' % filename).read()
##                print res
#                self.assertEqual(res2,expectedResult)



    def test_long_spannify(self):
        content =  unicode(file('src/cm/tests/data/long_text_to_spannify.html').read(), 'utf8')
        
        res, raw_text, corresp = spannify(content)