-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight_tests.py
87 lines (76 loc) · 4.44 KB
/
highlight_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import highlight
import unittest
import json
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
highlight.app.config['TESTING'] = True
self.app = highlight.app.test_client()
def tearDown(self):
return
def test_format_python(self):
rv = self.app.post('/python', data={
'body-plain': 'print "Hello World"',
'body-html': '',
'stripped-text': 'print "Hello Stripped World"',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
output = json.loads(rv.data)
assert rv.content_type == 'application/json'
assert output['body-html'] == "<html>\n<head></head>\n<body><div><pre style=\"font-size:12px\"><span style=\"color:#008000; font-weight:bold\">print</span> <span style=\"color:#BA2121\">\"Hello World\"</span>\n</pre></div></body>\n</html>\n"
assert output['stripped-html'] == "<html>\n<head></head>\n<body><div><pre style=\"font-size:12px\"><span style=\"color:#008000; font-weight:bold\">print</span> <span style=\"color:#BA2121\">\"Hello Stripped World\"</span>\n</pre></div></body>\n</html>\n"
def test_skip_formatting_with_html_part(self):
rv = self.app.post('/python', data={
'body-plain': 'print "Hello World"',
'body-html': '<pre>print "Hello World"</pre>',
'stripped-text': '',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
output = json.loads(rv.data)
assert rv.content_type == 'application/json'
assert output['body-html'] == '<pre>print "Hello World"</pre>'
def test_format_diff(self):
rv = self.app.post('/diff', data={
'body-plain': "1c1\n< Hello\n---\n\n> There\n",
'body-html': '',
'stripped-text': '',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
output = json.loads(rv.data)
assert output['body-html'] == "<html>\n<head></head>\n<body><div><pre style=\"font-size:12px\">1c1\n< Hello\n<span style=\"color:#A00000\">---</span>\n\n> There\n</pre></div></body>\n</html>\n"
def test_format_diff_with_long_line(self):
rv = self.app.post('/diff', data={
'body-plain': "1c1\n< Breathe in your fears. Face them. To conquer fear, you must become fear. You must bask in the fear of other men. And men fear most what they cannot see. You have to become a terrible thought. A wraith. You have to become an idea! Feel terror cloud your senses. Feel its power to distort. To control. And know that this power can be yours. Embrace your worst fear. Become one with the darkness.\n---\n\n> There\n",
'body-html': '',
'stripped-text': '',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
output = json.loads(rv.data)
assert output['body-html'] == "<html>\n<head></head>\n<body><div><pre style=\"font-size:12px\">1c1\n< Breathe in your fears. Face them. To conquer fear, you must become fear. You must bask in the fear of other men. And men fear most what they cannot see. You have to become a terrible thought. A wraith. You have to become an idea! Feel terror cloud your senses. Feel its power to distort. To control. And know that this power can be yours. Embrace your worst fear. Become one with the darkness.\n<span style=\"color:#A00000\">---</span>\n\n> There\n</pre></div></body>\n</html>\n"
def test_format_diff_with_unicode(self):
rv = self.app.post('/diff', data={
'body-plain': u"1c1\n< Hello\n---\n\n> There\xa9\n",
'body-html': '',
'stripped-text': '',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
output = json.loads(rv.data)
assert output['body-html'] == u"<html>\n<head></head>\n<body><div><pre style=\"font-size:12px\">1c1\n< Hello\n<span style=\"color:#A00000\">---</span>\n\n> There©\n</pre></div></body>\n</html>\n"
def test_format_missing(self):
rv = self.app.post('/notreal', data={
'body-plain': 'print "Hello World"',
'body-html': '',
'stripped-text': '',
'stripped-html': '',
'Message-Id': 'amessageidgoeshere'
})
assert rv.status == '404 NOT FOUND'
def test_info(self):
rv = self.app.get('/')
assert 'Syntax highlighting' in rv.data
if __name__ == '__main__':
unittest.main()