-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_main.py
47 lines (41 loc) · 1.96 KB
/
test_main.py
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
import unittest
import os
import main
from PIL import Image
class MainTest(unittest.TestCase):
def test_getInfoFromFilePath(self):
image_path = os.path.abspath("test/test_with_exif.jpg")
title, desc, timestamp = main.getInfoFromFilePath(image_path)
self.assertEqual(title, None)
self.assertEqual(desc, "#photo_gyazo #include_no_exif")
self.assertEqual(timestamp, 1585900168)
def test_getInfoFromExif(self):
image_path = os.path.abspath("test/test_with_exif.jpg")
image = Image.open(image_path)
exif = image._getexif()
title, desc, timestamp = main.getInfoFromExif(exif)
print(title, desc ,timestamp)
self.assertEqual(title, "Apple, iPhone SE")
self.assertEqual(desc, "#photo_gyazo #Apple #iPhone_SE ")
self.assertEqual(timestamp, 1583283648.0)
def test_getInfoFromExifOrFilePath(self):
image_path = os.path.abspath("test/test_with_exif.jpg")
title, desc, timestamp = main.getInfoFromExifOrFilePath(image_path)
self.assertEqual(title,"Apple, iPhone SE")
self.assertEqual(desc, "#photo_gyazo #Apple #iPhone_SE ")
self.assertEqual(timestamp, 1583283648.0)
def test_getInfoFromExifOrFilePath(self):
image_path = os.path.abspath("test/test_without_exif.jpeg")
title, desc, timestamp = main.getInfoFromExifOrFilePath(image_path)
self.assertEqual(title, None)
self.assertEqual(desc, "#photo_gyazo #include_no_exif")
self.assertEqual(timestamp, 1585900154)
def test_checkFileFormat(self):
image_path = os.path.abspath("test/test_with_exif.jpg")
newer_file_format = main.checkFileFormat(image_path)
if (image_path.endswith("jpg") or image_path.endswith("jpeg")):
self.assertEqual(newer_file_format, "JPEG")
elif(image_path.endswith("png")):
self.assertEqual(newer_file_format, "PNG")
else:
print("not a image file")