Pillow/Tests/test_util.py
Jon Dufresne 7da17ad41e Improve pytest configuration to allow specific tests as CLI args
The previous test configuration made it difficult to run a single test
with the pytest CLI. There were two major issues:

- The Tests directory was not a package. It now includes a __init__.py
  file and imports from other tests modules are done with relative
  imports.

- setup.cfg always specified the Tests directory. So even if a specific
  test were specified as a CLI arg, this configuration would also always
  include all tests. This configuration has been removed to allow
  specifying a single test on the command line.

Contributors can now run specific tests with a single command such as:

  $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb

This makes it easy and faster to iterate on a single test failure and is
very familiar to those that have previously used tox and pytest.

When running tox or pytest with no arguments, they still discover and
runs all tests in the Tests directory.
2019-01-13 09:00:12 -08:00

81 lines
1.5 KiB
Python

from .helper import unittest, PillowTestCase
from PIL import _util
class TestUtil(PillowTestCase):
def test_is_string_type(self):
# Arrange
color = "red"
# Act
it_is = _util.isStringType(color)
# Assert
self.assertTrue(it_is)
def test_is_not_string_type(self):
# Arrange
color = (255, 0, 0)
# Act
it_is_not = _util.isStringType(color)
# Assert
self.assertFalse(it_is_not)
def test_is_path(self):
# Arrange
fp = "filename.ext"
# Act
it_is = _util.isStringType(fp)
# Assert
self.assertTrue(it_is)
def test_is_not_path(self):
# Arrange
filename = self.tempfile("temp.ext")
fp = open(filename, 'w').close()
# Act
it_is_not = _util.isPath(fp)
# 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)
if __name__ == '__main__':
unittest.main()