2019-11-21 05:42:52 +03:00
|
|
|
import unittest
|
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
from PIL import _util
|
|
|
|
|
2019-11-21 05:42:52 +03:00
|
|
|
from .helper import PillowTestCase
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
class TestUtil(PillowTestCase):
|
|
|
|
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
|
2019-01-28 20:23:19 +03:00
|
|
|
it_is = _util.isPath(fp)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(it_is)
|
|
|
|
|
2019-12-25 06:13:16 +03:00
|
|
|
@unittest.skipUnless(_util.py36, "os.path support for Paths added in 3.6")
|
2019-01-28 20:14:42 +03:00
|
|
|
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")
|
2019-01-28 20:14:42 +03:00
|
|
|
|
|
|
|
# Act
|
2019-02-04 18:36:34 +03:00
|
|
|
it_is = _util.isPath(test_path)
|
2019-01-28 20:14:42 +03:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
self.assertTrue(it_is)
|
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
def test_is_not_path(self):
|
|
|
|
# Arrange
|
2014-07-08 00:40:37 +04:00
|
|
|
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
|
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)
|