from subprocess import Popen, PIPE from post import sanitize import unittest class SanitizeTest(unittest.TestCase): def comp_smjs(self, input): script="document=''; load('live_preview.js'); print(sanitize(%s))" proc=Popen('smjs', stdin=PIPE, stdout=PIPE, stderr=None) stdout,stderr=proc.communicate(script % repr(input)) self.assertEqual(stdout.strip(), sanitize(input).replace(' & ') # canonicalize line control characters def test_whitespace(self): self.comp_smjs('foo\r\n\r\n\r\nbar') # map windows-1252 to unicode def test_win1252(self): self.comp_smjs('can\x92t') # remove control characters def test_control(self): self.comp_smjs('foo\r\n\x0C\r\nbar') # , , , ,
,
,

def test_a(self): self.comp_smjs('foo link bar') self.comp_smjs("foo link bar") def test_em(self): self.comp_smjs('foo text bar') def test_i(self): self.comp_smjs('foo text bar') def test_b(self): self.comp_smjs('foo text bar') def test_blockquote(self): self.comp_smjs('foo

text
bar') def test_br(self): self.comp_smjs('foo
bar') def test_p(self): self.comp_smjs('foo

text

bar') # typographic support for mdash, curly quotes def test_smartquotes(self): self.comp_smjs("can't") self.comp_smjs("foo 'one two three' bar") self.comp_smjs('foo "one two three" bar') # wiki like support: _em_, -del-, *b*, [url title] def test_wiki_em(self): self.comp_smjs("foo _em_ bar") def test_wiki_del(self): self.comp_smjs("foo -del- bar") def test_wiki_b(self): self.comp_smjs("foo *b* bar") def test_wiki_url(self): self.comp_smjs("foo [http://example.com/cat.jpg cat] bar") self.comp_smjs("foo [http://example.com/cat.gif cat] bar") self.comp_smjs("foo [http://example.com/cat.png cat] bar") self.comp_smjs("foo [http://example.com/cat.html cat] bar") # cvs urls def test_cvs_url(self): self.comp_smjs("foo http://example.com/*checkout*/x bar") self.comp_smjs("foo http://example.com/_checkout_/x bar") # email style quotes (lines beginning with '>') def test_email_quotes(self): self.comp_smjs(">>>three\n>>two\n>one\n>more") self.comp_smjs(">>>three\n>>two\n>one\n>more\nresponse") self.comp_smjs(">>>three\n>>two\n>one\n>more\n\nresponse") # unordered lists: consecutive lines starting with spaces and an asterisk def test_unordered_lists(self): self.comp_smjs("before\n * one\n * two\n * a\n * b\n *c\n * three\nafter") self.comp_smjs("before\n\n * one\n * two\n * a\n * b\n *c\n * three\n\nafter") # white space def test_paragraphs(self): self.comp_smjs("before\n\n\n\nafter") def test_linebreak(self): self.comp_smjs("before\nafter") def test_doublespace(self): self.comp_smjs("foo bar") if __name__ == '__main__': unittest.main()