gh-40 Add tests to increase coverage in geolocation and photo module

This commit is contained in:
Jaisen Mathai 2016-09-12 22:23:24 -07:00
parent 9e1c92aabf
commit 71b1e9f0ed
2 changed files with 14 additions and 23 deletions

View File

@ -10,7 +10,6 @@ from __future__ import absolute_import
import imghdr import imghdr
import os import os
import re import re
import subprocess
import time import time
from datetime import datetime from datetime import datetime
from re import compile from re import compile
@ -38,28 +37,6 @@ class Photo(Media):
# We only want to parse EXIF once so we store it here # We only want to parse EXIF once so we store it here
self.exif = None self.exif = None
def get_duration(self):
"""Get the duration of a photo in seconds. Uses ffmpeg/ffprobe.
:returns: str or None for a non-photo file
"""
if(not self.is_valid()):
return None
source = self.source
result = subprocess.Popen(
['ffprobe', source],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
for key in result.stdout.readlines():
if 'Duration' in key:
return re.search(
'(\d{2}:\d{2}.\d{2})',
key
).group(1).replace('.', ':')
return None
def get_date_taken(self): def get_date_taken(self):
"""Get the date which the photo was taken. """Get the date which the photo was taken.

View File

@ -32,6 +32,20 @@ def test_decimal_to_dms():
assert target_decimal_value == check_value, '%s does not match %s' % (check_value, target_decimal_value) assert target_decimal_value == check_value, '%s does not match %s' % (check_value, target_decimal_value)
def test_dms_to_decimal_positive_sign():
decimal = geolocation.dms_to_decimal(10, 20, 100, 'NE')
assert helper.isclose(decimal, 10.3611111111)
decimal = geolocation.dms_to_decimal(10, 20, 100, 'ne')
assert helper.isclose(decimal, 10.3611111111)
def test_dms_to_decimal_negative_sign():
decimal = geolocation.dms_to_decimal(10, 20, 100, 'SW')
assert helper.isclose(decimal, -10.3611111111)
decimal = geolocation.dms_to_decimal(10, 20, 100, 'sw')
assert helper.isclose(decimal, -10.3611111111)
def test_dms_string_latitude(): def test_dms_string_latitude():
for x in range(0, 5): for x in range(0, 5):