Initial commit to photo-dater with pytest test
This commit is contained in:
69
pytest/test_proper_copy.py
Normal file
69
pytest/test_proper_copy.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from datetime import datetime
|
||||
|
||||
import os
|
||||
import time
|
||||
import piexif
|
||||
import pytest
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from helpers import *
|
||||
from fixtures import *
|
||||
|
||||
cmd = 'python3 updatescannedpics.py'
|
||||
|
||||
def test_diff_in_out(in_out_dirs):
|
||||
in_dir, out_dir = in_out_dirs
|
||||
|
||||
year = random.randint(1900, 2000)
|
||||
month = random.randint(1, 12)
|
||||
day = random.randint(1, 28)
|
||||
index = random.randint(0, 99)
|
||||
|
||||
file_name = f"{year}{month:02d}{day:02d}_{index:02d}.jpg"
|
||||
in_file = os.path.join(in_dir, file_name)
|
||||
out_file = os.path.join(out_dir, file_name)
|
||||
|
||||
shutil.copyfile("pytest/example_pics/u_001.jpg", in_file)
|
||||
|
||||
command = f"{cmd} -i {in_dir} -o {out_dir}"
|
||||
print(command)
|
||||
output = run_successfull_cmd(command)
|
||||
|
||||
exif_dict = piexif.load(out_file)
|
||||
|
||||
test_date = datetime(year, month, day, 0, 0, 0)
|
||||
test_date_str = test_date.strftime("%Y:%m:%d %H:%M:%S")
|
||||
|
||||
assert test_date_str == exif_dict["0th"][piexif.ImageIFD.DateTime].decode('utf-8')
|
||||
assert test_date_str == exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('utf-8')
|
||||
assert test_date_str == exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('utf-8')
|
||||
|
||||
def test_same_in_out(in_out_dirs):
|
||||
in_dir, out_dir = in_out_dirs
|
||||
out_dir = in_dir
|
||||
|
||||
year = random.randint(1900, 2000)
|
||||
month = random.randint(1, 12)
|
||||
day = random.randint(1, 28)
|
||||
index = random.randint(0, 99)
|
||||
|
||||
file_name = f"{year}{month:02d}{day:02d}_{index:02d}.jpg"
|
||||
in_file = out_file = os.path.join(in_dir, file_name)
|
||||
|
||||
shutil.copyfile("pytest/example_pics/u_001.jpg", in_file)
|
||||
|
||||
command = f"{cmd} -i {in_dir} -o {out_dir}"
|
||||
print(command)
|
||||
output = run_successfull_cmd(command)
|
||||
|
||||
exif_dict = piexif.load(out_file)
|
||||
|
||||
test_date = datetime(year, month, day, 0, 0, 0)
|
||||
test_date_str = test_date.strftime("%Y:%m:%d %H:%M:%S")
|
||||
|
||||
assert test_date_str == exif_dict["0th"][piexif.ImageIFD.DateTime].decode('utf-8')
|
||||
assert test_date_str == exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('utf-8')
|
||||
assert test_date_str == exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('utf-8')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user