gh-40 Add tests to increase coverage in geolocation and photo module
This commit is contained in:
		
							parent
							
								
									9e1c92aabf
								
							
						
					
					
						commit
						71b1e9f0ed
					
				@ -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.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user