forked from kleopatra999/content-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentScreenshotTests.py
executable file
·58 lines (45 loc) · 2.62 KB
/
contentScreenshotTests.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
#!/usr/bin/env python
import hashlib
import unittest
import contentScreenshot
class TestSvgOutput(unittest.TestCase):
def setUp(self):
# Use a prebuilt content shell by default
self.contentShellBinary = contentScreenshot.contentShellBinary(None)
def imageMd5(self, image):
return hashlib.md5(image).hexdigest()
def fileMd5(self, inFile):
return hashlib.md5(open(inFile, "rb").read()).hexdigest()
def test_svgWidthAndHeight(self):
image = contentScreenshot.svgAsPng(self.contentShellBinary, "test/greenSquare.svg", "", 200, 200)
expected = self.fileMd5("test/200x200greenSquare.png")
self.assertEqual(self.imageMd5(image), expected)
def test_svgWidthWithoutHeight(self):
image = contentScreenshot.svgAsPng(self.contentShellBinary, "test/greenSquare.svg", "", 200, None)
expected = self.fileMd5("test/200x200greenSquare.png")
self.assertEqual(self.imageMd5(image), expected)
def test_svgTransparency(self):
image = contentScreenshot.svgAsPng(self.contentShellBinary, "test/greenCircle.svg", "", None, 50)
expected = self.fileMd5("test/50x50greenCircle.png")
self.assertEqual(self.imageMd5(image), expected)
def test_svgWithFractionalSize(self):
image = contentScreenshot.svgAsPng(self.contentShellBinary, "test/16ptBy100ptGreenSquare.svg", "", 200, None)
expected = self.fileMd5("test/200x1250GreenSquare.png")
self.assertEqual(self.imageMd5(image), expected)
def test_htmlWidthAndHeight(self):
image = contentScreenshot.htmlAsPng(self.contentShellBinary, "test/greenSquare.html", "", 100, 100)
expected = self.fileMd5("test/100x100greenSquare.png")
self.assertEqual(self.imageMd5(image), expected)
def test_htmlBackgroundIsWhite(self):
image = contentScreenshot.htmlAsPng(self.contentShellBinary, "test/greenSquare.html", "", 150, 150)
expected = self.fileMd5("test/greenSquareOnWhiteBackground.png")
self.assertEqual(self.imageMd5(image), expected)
def test_htmlSizeFlag(self):
image = contentScreenshot.htmlAsPng(self.contentShellBinary, "test/greenSquare.html", "--content-shell-host-window-size=100x100", None, None)
expected = self.fileMd5("test/100x100greenSquare.png")
self.assertEqual(self.imageMd5(image), expected)
def test_missingBinary(self):
self.assertRaises(Exception, contentScreenshot.htmlAsPng, (None, "test/greenSquare.html", "", None, None))
self.assertRaises(Exception, contentScreenshot.svgAsPng, (None, "test/greenSquare.svg", "", None, None))
if __name__ == "__main__":
unittest.main()