File: test_exiftool_configfile.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 (74 lines) | stat: -rw-r--r-- 2,097 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
"""
Test :: ExifTool base class - config_file attribute
"""
# standard
import unittest

# test helpers
from tests.common_util import et_get_temp_dir

# custom
import exiftool
from exiftool.exceptions import ExifToolRunning




class TestExifToolConfigFile(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_configfile_attribute(self):
		current = self.et.config_file

		with self.assertRaises(FileNotFoundError):
			self.et.config_file = "foo.bar"

		# see if Python 3.9.5 fixed this ... raises OSError right now and is a pathlib glitch https://bugs.python.org/issue35306
		#self.et.config_file = "\"C:\\\"\"C:\\"

		# then restore current config_file
		self.et.config_file = current

		self.assertFalse(self.et.running)
		self.et.run()
		self.assertTrue(self.et.running)

		with self.assertRaises(ExifToolRunning):
			self.et.config_file = None

		self.et.terminate()

	# ---------------------------------------------------------------------------------------------------------
	def test_configfile_set(self):
		(temp_obj, temp_dir) = et_get_temp_dir(suffix="config")

		# set config file to empty, which is valid (should not throw error)
		self.et.config_file = ""

		# create a config file, and set it and test that it works
		# a file that returns 1 is valid as a config file
		tmp_config_file = temp_dir / "config_test.txt"
		with open(tmp_config_file, 'w') as f:
			f.write("1;\n")

		self.et.config_file = tmp_config_file

		self.et.run()
		self.assertTrue(self.et.running)

		self.et.terminate()



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