ordigi/tests/conftest.py

50 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-08-08 15:33:47 +02:00
""" pytest test configuration """
2021-08-08 21:43:37 +02:00
from configparser import RawConfigParser
2021-08-08 15:33:47 +02:00
import pytest
2021-08-08 21:43:37 +02:00
from pathlib import Path
import shutil
import tempfile
2021-08-08 15:33:47 +02:00
2021-08-14 21:28:40 +02:00
from ordigi import config
from ordigi.exiftool import _ExifToolProc
2021-08-08 15:33:47 +02:00
2021-08-14 21:28:40 +02:00
ORDIGI_PATH = Path(__file__).parent.parent
2021-08-08 15:33:47 +02:00
@pytest.fixture(autouse=True)
def reset_singletons():
""" Need to clean up any ExifTool singletons between tests """
_ExifToolProc.instance = None
2021-08-08 21:43:37 +02:00
def copy_sample_files():
2021-08-14 21:28:40 +02:00
src_path = tempfile.mkdtemp(prefix='ordigi-src')
paths = Path(ORDIGI_PATH, 'samples/test_exif').glob('*')
2021-08-08 21:43:37 +02:00
file_paths = [x for x in paths if x.is_file()]
for file_path in file_paths:
source_path = Path(src_path, file_path.name)
shutil.copyfile(file_path, source_path)
return src_path, file_paths
@pytest.fixture(scope="module")
def conf_path():
2021-08-14 21:28:40 +02:00
tmp_path = tempfile.mkdtemp(prefix='ordigi-')
2021-08-08 21:43:37 +02:00
conf = RawConfigParser()
conf['Path'] = {
'day_begins': '4',
'dirs_path':'%u{%Y-%m}/{city}|{city}-{%Y}/{folders[:1]}/{folder}',
'name':'{%Y-%m-%b-%H-%M-%S}-{basename}.%l{ext}'
}
conf['Geolocation'] = {
'geocoder': 'Nominatium'
}
2021-08-14 21:28:40 +02:00
conf_path = Path(tmp_path, "ordigi.conf")
2021-08-08 21:43:37 +02:00
config.write(conf_path, conf)
yield conf_path
shutil.rmtree(tmp_path)