File: test_exiftool_misc.py

package info (click to toggle)
pyexiftool 0.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 356 kB
  • sloc: python: 1,406; makefile: 5
file content (96 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
"""
Test :: ExifTool base class - misc tests
"""

# standard
import unittest
import warnings
from pathlib import Path

# test helpers
from tests.common_util import TEST_IMAGE_JPG

# custom
import exiftool
from exiftool.exceptions import ExifToolNotRunning


class TestExifToolMisc(unittest.TestCase):

	# ---------------------------------------------------------------------------------------------------------
	def setUp(self):
		self.et = exiftool.ExifTool(common_args=["-G", "-n", "-overwrite_original"])

	def tearDown(self):
		if self.et.running:
			self.et.terminate()


	# ---------------------------------------------------------------------------------------------------------
	def test_get_version_protected(self):
		""" test the protected method which can't be called when exiftool not running """
		self.assertFalse(self.et.running)
		self.assertRaises(ExifToolNotRunning, self.et._parse_ver)


	# ---------------------------------------------------------------------------------------------------------
	def test_invalid_args_list(self):
		# test to make sure passing in an invalid args list will cause it to error out
		with self.assertRaises(TypeError):
			exiftool.ExifTool(common_args="not a list")


	# ---------------------------------------------------------------------------------------------------------
	def test_common_args(self):
		# test to make sure passing in an invalid args list will cause it to error out
		with self.assertRaises(TypeError):
			exiftool.ExifTool(common_args={})

		# set to common_args=None == []
		self.assertEqual(exiftool.ExifTool(common_args=None).common_args, [])


	# ---------------------------------------------------------------------------------------------------------
	def test_run_twice(self):
		""" test that a UserWarning is thrown when run() is called twice """
		self.assertFalse(self.et.running)
		self.et.run()

		with warnings.catch_warnings(record=True) as w:
			self.assertTrue(self.et.running)
			self.et.run()
			self.assertEqual(len(w), 1)
			self.assertTrue(issubclass(w[0].category, UserWarning))


	# ---------------------------------------------------------------------------------------------------------
	def test_execute_types(self):
		""" test execute with different types """
		self.assertFalse(self.et.running)
		self.et.run()

		# no error with str
		self.et.execute("-ver")

		# no error with bytes
		self.et.execute(b"-ver")

		# no error with str
		self.et.execute(str(TEST_IMAGE_JPG))

		# error with Path
		with self.assertRaises(TypeError):
			self.et.execute(Path(TEST_IMAGE_JPG))


	# ---------------------------------------------------------------------------------------------------------






# ---------------------------------------------------------------------------------------------------------
if __name__ == '__main__':
	unittest.main()