Skip to content

Commit

Permalink
adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
Guinsly Mondesir committed Feb 10, 2016
1 parent 1b9a03a commit 96fc2e0
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 87 deletions.
88 changes: 1 addition & 87 deletions pyexifinfo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,87 +1 @@
import subprocess, json, os


this_file_exist = lambda x: os.path.exists(filename)

####HELPER section

def command_line(cmd):
try:
s = subprocess.check_output(cmd)
return s.strip()
except subprocess.CalledProcessError:
return 0

def information(filename):
"""Returns the file exif"""
result = get_json(filename)
result = result[0]
return result
######################

def ver():
'''Retrieve the current version of exiftool installed on your computer
'''
s = command_line(["exiftool","-ver"])
if s:
return s.split()
else:
return 0

def get_json(filename):
'''Return a json value of the exif
'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-j', '-sort', filename])
if s:
s = s.rstrip('\r\n')
return json.loads(s)
else:
return 0

def get_csv(filename):
'''Return a csv representation of the exif
arg: filename
'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-csv', '-sort', filename])
if s:
return s
else:
return 0

def get_xml(filename):
'''Return a XML representation of the exif
'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-X', '-sort', filename])
if s:
return s
else:
return 0

def fileType(filename):
"""Returns the file extension"""
result = information(filename)
return result.get('File:FileType', 0)

def mimeType(filename):
"""Returns the file extension"""
result = information(filename)
return result.get('File:MIMEType', 0)

def imageSize(filename):
"""Returns the file size"""
result = information(filename)
return result.get('Composite:ImageSize', 0)

def imageWidth(filename):
"""Returns the file width"""
result = information(filename)
return result.get('PNG:ImageWidth', 0)

def imageHeight(filename):
"""Returns the file height"""
result = information(filename)
return result.get('PNG:imageHeight', 0)
from .pyexifinfo import *
87 changes: 87 additions & 0 deletions pyexifinfo/pyexifinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import subprocess, json, os


this_file_exist = lambda x: os.path.exists(filename)

####HELPER section

def command_line(cmd):
"""Handle the command line call
keyword arguments:
cmd = a list
return
0 if error
or a string for the command line output
"""
try:
s = subprocess.check_output(cmd)
return s.strip()
except subprocess.CalledProcessError:
return 0

def information(filename):
"""Returns the file exif"""
result = get_json(filename)
result = result[0]
return result
######################

def ver():
'''Retrieve the current version of exiftool installed on your computer
'''
s = command_line(["exiftool","-ver"])
if s:
return s.split()
else:
return 0

def get_json(filename):
'''Return a json value of the exif
'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-j', '-sort', filename])
if s:
#convert bytes to string
s = s.decode('utf-8').rstrip('\r\n')
return json.loads(s)
else:
return filename

def get_csv(filename):
'''Return a csv representation of the exif
arg: filename
'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-csv', '-sort', filename])
if s:
return s
else:
return 0

def get_xml(filename):
'''Return a XML representation of the exif'''
filename = os.path.abspath(filename)
s = command_line(['exiftool', '-G', '-X', '-sort', filename])
if s:
return s
else:
return 0

def fileType(filename):
"""Returns the file extension"""
result = information(filename)
return result.get('File:FileType', 0)

def mimeType(filename):
"""Returns the file extension"""
result = information(filename)
return result.get('File:MIMEType', 0)

def imageSize(filename):
"""Returns the file size"""
result = information(filename)
return result.get('Composite:ImageSize', 0)

Empty file added tests/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions tests/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pyexifinfo import *
import pyexifinfo as p
import os

# content of test_sample.py
image = 'python-logo-master-v3-TM.png'
def test_version_is_greater_than_8():
""" test the version is greater than 8 """
a = p.ver()
#transforming bytes to string
a = a[0].decode('utf-8')
#transform string to float
a = float(a)
assert a >= 8

def test_get_json():
a = p.get_json(image)
print('hello')
assert len("sss") == 3
38 changes: 38 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pyexifinfo as p
import os


# content of test_sample.py
image = 'python-logo-master-v3-TM.png'
def test_version_is_greater_than_8():
""" test the version is greater than 8 """
a = p.ver()
#transforming bytes to string
a = a[0].decode('utf-8')
#transform string to float
a = float(a)
assert a >= 8

def test_get_json():
a = p.get_json("tests/"+image)
assert len(a[0]) == 25

def test_get_fileType():
a = p.fileType("tests/"+image)
assert a.lower() == 'png'

def test_get_mimeType():
a = p.mimeType("tests/"+image)
assert a.lower() == 'image/png'

def test_get_imageSize():
a = p.imageSize("tests/"+image)
assert a.lower() == '601x203'

def test_get_imageWidh():
a = p.imageWidth("tests/"+image)
assert a == 601

def test_get_imageHeight():
a = p.imageHeight("tests/"+image)
assert a == 203

0 comments on commit 96fc2e0

Please sign in to comment.