-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pytest test cases with real files
- Loading branch information
1 parent
d60f18d
commit 87c6163
Showing
13 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
source = exifread | ||
omit = tests/*, __init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
pythonpath = tests | ||
addopts = --ignore-glob=**/tests/**, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
TEST_FOLDER = '.test_folder' | ||
TEST_IMAGES = os.path.join('tests', 'test_files') | ||
|
||
|
||
def create_file(file): | ||
Path(os.path.join(TEST_FOLDER, file)).touch() | ||
|
||
|
||
def delete_folder(): | ||
shutil.rmtree(TEST_FOLDER, ignore_errors=True) | ||
|
||
|
||
def copy_test_images(file:str): | ||
delete_folder() | ||
os.mkdir(TEST_FOLDER) | ||
if file: | ||
shutil.copy(src=os.path.join(TEST_IMAGES, file), dst=os.path.join(TEST_FOLDER, file)) | ||
else: | ||
shutil.copy(src=os.path.join(TEST_IMAGES, os.path.sep), dst=TEST_FOLDER) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
python3.12 -m pytest \ | ||
--no-header \ | ||
-rfp \ | ||
--cov \ | ||
--cov-report html:tests/coverage \ | ||
--cov-report xml:tests/coverage/coverage.xml \ | ||
--junitxml=tests/coverage/report.xml \ | ||
tests/ | ||
|
||
exit $? |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
import sys | ||
import os | ||
|
||
|
||
sys.path.append('..') | ||
|
||
from exifread import process_file | ||
from helpers.folder_helper import copy_test_images | ||
from helpers.folder_helper import TEST_FOLDER | ||
from helpers.folder_helper import delete_folder | ||
|
||
|
||
class TestMobiles(unittest.TestCase): | ||
def tearDown(self): | ||
delete_folder() | ||
|
||
def test_samsung(self): | ||
copy_test_images(file='samsung_a54_001.jpg') | ||
with open(file=os.path.join(TEST_FOLDER, 'samsung_a54_001.jpg'), mode='rb') as file: exif_tags = process_file(file) | ||
make = next((exif_tags[tag] for tag in exif_tags.keys() if 'Make' in tag), None) | ||
assert str(make) == 'samsung' | ||
|
||
def test_apple(self): | ||
copy_test_images(file='iphone_x_001.jpeg') | ||
with open(file=os.path.join(TEST_FOLDER, 'iphone_x_001.jpeg'), mode='rb') as file: exif_tags = process_file(file) | ||
make = next((exif_tags[tag] for tag in exif_tags.keys() if 'Make' in tag), None) | ||
assert str(make) == 'Apple' | ||
|
||
|
||
class TestCameras(unittest.TestCase): | ||
def tearDown(self): | ||
delete_folder() | ||
|
||
def test_sony_jpg(self): | ||
copy_test_images(file='sony_alpha_a58.JPG') | ||
with open(file=os.path.join(TEST_FOLDER, 'sony_alpha_a58.JPG'), mode='rb') as file: exif_tags = process_file(file) | ||
make = next((exif_tags[tag] for tag in exif_tags.keys() if 'Make' in tag), None) | ||
assert str(make) == 'SONY' | ||
|
||
def test_sony_raw(self): | ||
copy_test_images(file='sony_alpha_a7iii_raw_image.ARW') | ||
with open(file=os.path.join(TEST_FOLDER, 'sony_alpha_a7iii_raw_image.ARW'), mode='rb') as file: exif_tags = process_file(file) | ||
make = next((exif_tags[tag] for tag in exif_tags.keys() if 'Make' in tag), None) | ||
assert str(make) == 'SONY' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
import sys | ||
import os | ||
|
||
|
||
sys.path.append('..') | ||
|
||
from exifread import process_file | ||
from helpers.folder_helper import copy_test_images | ||
from helpers.folder_helper import TEST_FOLDER | ||
from helpers.folder_helper import delete_folder | ||
|
||
|
||
class TestVideos(unittest.TestCase): | ||
def tearDown(self): | ||
delete_folder() | ||
|
||
# TODO: add a mp4 with exif tags | ||
def test_video_mp4(self): | ||
copy_test_images(file='test_video.mp4') | ||
with open(file=os.path.join(TEST_FOLDER, 'test_video.mp4'), mode='rb') as file: exif_tags = process_file(file) | ||
make = next((exif_tags[tag] for tag in exif_tags.keys() if 'Make' in tag), None) | ||
assert make is None | ||
|