Pillow/Tests/test_util.py

89 lines
1.8 KiB
Python
Raw Normal View History

2019-02-20 12:57:52 +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
color = "red"
2014-07-06 02:47:30 +04:00
# Act
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
color = (255, 0, 0)
2014-07-06 02:47:30 +04:00
# Act
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
fp = "filename.ext"
2014-07-06 02:47:30 +04:00
# Act
it_is = _util.isPath(fp)
2014-07-06 02:47:30 +04:00
# Assert
self.assertTrue(it_is)
2019-06-13 18:54:46 +03:00
@unittest.skipIf(not _util.py36, "os.path support for Paths added in 3.6")
def test_path_obj_is_path(self):
# Arrange
from pathlib import Path
2019-06-13 18:54:46 +03:00
test_path = Path("filename.ext")
# Act
it_is = _util.isPath(test_path)
# Assert
self.assertTrue(it_is)
2014-07-06 02:47:30 +04:00
def test_is_not_path(self):
# Arrange
filename = self.tempfile("temp.ext")
2019-06-13 18:54:46 +03:00
fp = open(filename, "w").close()
2014-07-06 02:47:30 +04:00
# Act
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)