2019-01-13 20:00:12 +03:00
|
|
|
from .helper import unittest, PillowTestCase
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
from PIL import _util
|
|
|
|
|
|
|
|
|
|
|
|
class TestUtil(PillowTestCase):
|
|
|
|
|
|
|
|
def test_is_string_type(self):
|
|
|
|
# Arrange
|
2014-07-08 00:40:37 +04:00
|
|
|
color = "red"
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Act
|
2014-07-08 00:40:37 +04:00
|
|
|
it_is = _util.isStringType(color)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(it_is)
|
|
|
|
|
|
|
|
def test_is_not_string_type(self):
|
|
|
|
# Arrange
|
2014-07-08 00:40:37 +04:00
|
|
|
color = (255, 0, 0)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Act
|
2014-07-08 00:40:37 +04:00
|
|
|
it_is_not = _util.isStringType(color)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertFalse(it_is_not)
|
|
|
|
|
|
|
|
def test_is_path(self):
|
|
|
|
# Arrange
|
2014-07-08 00:40:37 +04:00
|
|
|
fp = "filename.ext"
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Act
|
2014-07-08 00:40:37 +04:00
|
|
|
it_is = _util.isStringType(fp)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(it_is)
|
|
|
|
|
|
|
|
def test_is_not_path(self):
|
|
|
|
# Arrange
|
2014-07-08 00:40:37 +04:00
|
|
|
filename = self.tempfile("temp.ext")
|
|
|
|
fp = open(filename, 'w').close()
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Act
|
2014-07-08 00:40:37 +04:00
|
|
|
it_is_not = _util.isPath(fp)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertFalse(it_is_not)
|
|
|
|
|
|
|
|
def test_is_directory(self):
|
|
|
|
# Arrange
|
|
|
|
directory = "Tests"
|
|
|
|
|
|
|
|
# Act
|
|
|
|
it_is = _util.isDirectory(directory)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(it_is)
|
|
|
|
|
|
|
|
def test_is_not_directory(self):
|
|
|
|
# Arrange
|
|
|
|
text = "abc"
|
|
|
|
|
|
|
|
# Act
|
|
|
|
it_is_not = _util.isDirectory(text)
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertFalse(it_is_not)
|
|
|
|
|
|
|
|
def test_deferred_error(self):
|
|
|
|
# Arrange
|
|
|
|
|
|
|
|
# Act
|
|
|
|
thing = _util.deferred_error(ValueError("Some error text"))
|
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertRaises(ValueError, lambda: thing.some_attr)
|
|
|
|
|
2018-03-03 12:54:00 +03:00
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|