2016-01-06 11:59:37 +03:00
|
|
|
from helper import unittest, PillowTestCase
|
|
|
|
|
|
|
|
from PIL import Image, DdsImagePlugin
|
|
|
|
|
|
|
|
TEST_FILE_DXT1 = "Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds"
|
2016-01-06 12:59:47 +03:00
|
|
|
TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
|
2016-01-06 11:59:37 +03:00
|
|
|
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
|
|
|
|
|
|
|
|
|
2016-01-06 13:26:58 +03:00
|
|
|
class TestFileDds(PillowTestCase):
|
|
|
|
"""Test DdsImagePlugin"""
|
2016-01-06 11:59:37 +03:00
|
|
|
|
|
|
|
def test_sanity_dxt1(self):
|
2016-01-06 13:26:58 +03:00
|
|
|
"""Check DXT1 images can be opened"""
|
2016-01-06 11:59:37 +03:00
|
|
|
im = Image.open(TEST_FILE_DXT1)
|
|
|
|
|
2016-01-06 12:24:09 +03:00
|
|
|
self.assertEqual(im.format, "DDS")
|
|
|
|
self.assertEqual(im.mode, "RGBA")
|
2016-01-06 11:59:37 +03:00
|
|
|
self.assertEqual(im.size, (256, 256))
|
|
|
|
self.assertIsInstance(im, DdsImagePlugin.DdsImageFile)
|
|
|
|
|
|
|
|
def test_sanity_dxt5(self):
|
2016-01-06 13:26:58 +03:00
|
|
|
"""Check DXT5 images can be opened"""
|
2016-01-06 11:59:37 +03:00
|
|
|
im = Image.open(TEST_FILE_DXT5)
|
|
|
|
|
2016-01-06 12:24:09 +03:00
|
|
|
self.assertEqual(im.format, "DDS")
|
|
|
|
self.assertEqual(im.mode, "RGBA")
|
2016-01-06 11:59:37 +03:00
|
|
|
self.assertEqual(im.size, (256, 256))
|
|
|
|
self.assertIsInstance(im, DdsImagePlugin.DdsImageFile)
|
|
|
|
|
2016-01-06 12:59:47 +03:00
|
|
|
def test_sanity_dxt3(self):
|
2016-01-06 13:26:58 +03:00
|
|
|
"""Check DXT3 images are not supported"""
|
2016-01-06 12:59:47 +03:00
|
|
|
self.assertRaises(NotImplementedError,
|
|
|
|
lambda: Image.open(TEST_FILE_DXT3))
|
|
|
|
|
2016-01-06 11:59:37 +03:00
|
|
|
def test__validate_true(self):
|
2016-01-06 13:26:58 +03:00
|
|
|
"""Check valid prefix"""
|
2016-01-06 11:59:37 +03:00
|
|
|
# Arrange
|
|
|
|
prefix = b"DDS etc"
|
|
|
|
|
|
|
|
# Act
|
|
|
|
output = DdsImagePlugin._validate(prefix)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(output)
|
|
|
|
|
|
|
|
def test__validate_false(self):
|
2016-01-06 13:26:58 +03:00
|
|
|
"""Check invalid prefix"""
|
2016-01-06 11:59:37 +03:00
|
|
|
# Arrange
|
|
|
|
prefix = b"something invalid"
|
|
|
|
|
|
|
|
# Act
|
|
|
|
output = DdsImagePlugin._validate(prefix)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertFalse(output)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|