import os import pytest import random import shutil from pathlib import Path from helpers import * from fixtures import * cmd = 'python3 updatescannedpics.py' def test_bad_filename(in_out_dirs, log_file): in_dir, out_dir = in_out_dirs file_name = gen_rand_name(12) + ".jpg" Path(os.path.join(in_dir, file_name)).touch() command = f'{cmd} -i {in_dir} -o {out_dir}' output = run_successfull_cmd(command) expected = f"File name not compatable: {file_name}" assert check_log_string(log_file, expected) def test_bad_jpg_format(in_out_dirs, log_file): 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" Path(os.path.join(in_dir, file_name)).touch() command = f'{cmd} -i {in_dir} -o {out_dir}' output = run_successfull_cmd(command) expected = f"Bad file format for {file_name}" assert check_log_string(log_file, expected) def test_bad_jpg_year(in_out_dirs, log_file): in_dir, out_dir = in_out_dirs year_low = random.randint(1000, 1799) year_high = random.randint(2010, 2100) month = random.randint(1, 12) day = random.randint(1, 28) index = random.randint(0, 99) file_name_high = f"{year_high}{month:02d}{day:02d}_{index:02d}.jpg" file_name_low = f"{year_low}{month:02d}{day:02d}_{index:02d}.jpg" shutil.copyfile("pytest/example_pics/u_001.jpg", f"{in_dir}/{file_name_high}") shutil.copyfile("pytest/example_pics/u_002.jpg", f"{in_dir}/{file_name_low}") command = f'{cmd} -m -i {in_dir} -o {out_dir}' output = run_successfull_cmd(command) expected = [ f"Year too great: {year_high}", f"Year too early: {year_low}" ] for exp in expected: assert check_log_string(log_file, exp)