def test_incredibly_long_string(self): # make sure it doesn't take too long with a long string start = time() sp("a" * 10000) end = time() self.assertLess(end - start, 0.2)
def test_convert_entities(self): self.assertEqual(sp('"quote here"', Attr.set1 | Attr.u), '“quote here”') self.assertEqual(sp('"quote–here"', Attr.set1 | Attr.u), '“quote–here”') self.assertEqual(sp('"quote here"', Attr.set1 | Attr.h), '“quote here”') self.assertEqual(sp('"quote here"', Attr.set1 | Attr.s), '"quote here"')
def test_comments(self): self.assertEqual(sp("--"), "—") self.assertEqual(sp("-->"), "—>") self.assertEqual(sp("-- \t >"), "— \t >") TEXT = '<!-- "foo" --> blah--blah <!-- "bar" -->' T = sp(TEXT) E = '<!-- "foo" --> blah—blah <!-- "bar" -->' self.assertEqual(T, E) TEXT = ('<p>foo -- "bar"<!-- foo-bar\n' '<p>blah "this"</p>\n' '-->\n' '</p>') T = sp(TEXT) E = ('<p>foo — “bar”<!-- foo-bar\n' '<p>blah "this"</p>\n' '-->\n' '</p>') self.assertEqual(T, E) # nothing should be converted for TEXT in ('<!-- comment -->', '<!-- <li>Fee-fi-of-fum</li> -->', '<!-- "foo" --> <!-- "bar" -->'): self.assertEqual(sp(TEXT), TEXT) # not comments self.assertEqual(sp('<!-- -- -->'), '<!— — —>') self.assertEqual(sp('<!-- -- -- \t >'), '<!— — — \t >')
def mktitle(line): global categories global t categories["TITLE"] = line.strip() t, created = Thread.objects.get_or_create( title_plain=categories["TITLE"], title_html=sp(categories["TITLE"]), author=categories["AUTHOR"], category=c)
def parse_speaker(speaker, content): speaker = speaker.lower().title() p, created = Post.objects.get_or_create(thread=t, author=characters[speaker], content_plain=content) if created: p.content_html = sp(md(text=content, extensions=["nl2br"])) p.creation_date = datetime.datetime.now() # UTC? p.save()
def mktitle(line): global categories global t categories["TITLE"] = line.strip() t, created = Thread.objects.get_or_create(title_plain=categories["TITLE"], title_html=sp( categories["TITLE"]), author=categories["AUTHOR"], category=c)
def parse_speaker(speaker, content): speaker = speaker.lower().title() p, created = Post.objects.get_or_create( thread=t, author=characters[speaker], content_plain=content) if created: p.content_html = sp(md(text=content, extensions=["nl2br"])) p.creation_date = datetime.datetime.now() # UTC? p.save()
def test_change_default_attr(self): TEXT = '"foo" -- bar' attr = Attr.q Attr.default = attr self.assertEqual(Attr.default, attr) T = sp(TEXT) E = '“foo” -- bar' self.assertEquals(T, E) attr = Attr.q | Attr.d Attr.default = attr self.assertEqual(Attr.default, attr) T = sp(TEXT) E = '“foo” — bar' self.assertEquals(T, E)
def test_dates(self): self.assertEqual(sp("1440-80's"), "1440-80’s") self.assertEqual(sp("1440-'80s"), "1440-‘80s") self.assertEqual(sp("1440--'80s"), "1440—‘80s") self.assertEqual(sp("1960s"), "1960s") # no effect. self.assertEqual(sp("1960's"), "1960’s") self.assertEqual(sp("one two '60s"), "one two ‘60s") self.assertEqual(sp("'60s"), "‘60s")
def test_convert_quot(self): TEXT = ( "<p>He said "Let's write some code." " "This code here <code>if True:\n\tprint "Okay"</code> " "is python code.</p>") T = sp(TEXT) E = ("<p>He said "Let’s write some code." " "This code here <code>if True:\n\tprint "Okay"</code> " "is python code.</p>") self.assertEqual(T, E) T = sp(TEXT, Attr.w) E = ('<p>He said "Let\'s write some code." ' "This code here <code>if True:\n\tprint "Okay"</code> " "is python code.</p>") self.assertEqual(T, E) T = sp(TEXT, Attr.q | Attr.w) E = ("<p>He said “Let’s write some code.” " "This code here <code>if True:\n\tprint "Okay"</code> " "is python code.</p>") self.assertEqual(T, E)
def mktitle(line): global categories global t categories["TITLE"] = line.strip() t, created = Thread.objects.get_or_create( title_plain=categories["TITLE"], title_html=sp(categories["TITLE"]), author=categories["AUTHOR"], category=c) if created: t.author.get_profile().thread_count += 1 c.thread_count += 1 categories["AUTHOR"].get_profile().thread_count += 1 t.save() c.save() categories["AUTHOR"].get_profile().save()
def test_skip_tags(self): T = sp('''<script type="text/javascript"> <!-- var href = "http://www.google.com"; var linktext = "google"; document.write('<a href="' + href + '">' + linktext + "</a>"); //--> </script>''') E = '''<script type="text/javascript"> <!-- var href = "http://www.google.com"; var linktext = "google"; document.write('<a href="' + href + '">' + linktext + "</a>"); //--> </script>''' self.assertEqual(T, E)
def mktitle(line): global categories global t categories["TITLE"] = line.strip() t, created = Thread.objects.get_or_create(title_plain=categories["TITLE"], title_html=sp( categories["TITLE"]), author=categories["AUTHOR"], category=c) if created: t.author.get_profile().thread_count += 1 c.thread_count += 1 categories["AUTHOR"].get_profile().thread_count += 1 t.save() c.save() categories["AUTHOR"].get_profile().save()
def test_educated_quotes(self): self.assertEqual(sp('"Isn\'t this fun?"'), '“Isn’t this fun?”')
def test_ordinal_numbers(self): self.assertEqual(sp("21st century"), "21st century") # no effect. self.assertEqual(sp("3rd"), "3rd") # no effect.