1
|
|
|
from __future__ import absolute_import |
2
|
|
|
# Project imports |
3
|
|
|
|
4
|
|
|
import os |
5
|
|
|
import sys |
6
|
|
|
import unittest |
7
|
|
|
|
8
|
|
|
try: |
9
|
|
|
reload # Python 2.7 |
|
|
|
|
10
|
|
|
except NameError: |
11
|
|
|
try: |
12
|
|
|
from importlib import reload # Python 3.4+ |
13
|
|
|
except ImportError: |
14
|
|
|
from imp import reload # Python 3.0 - 3.3 |
15
|
|
|
|
16
|
|
|
from mock import patch |
17
|
|
|
|
18
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) |
19
|
|
|
|
20
|
|
|
from elodie import constants |
21
|
|
|
|
22
|
|
|
BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
23
|
|
|
|
24
|
|
|
def test_debug(): |
25
|
|
|
assert constants.debug == False, constants.debug |
26
|
|
|
|
27
|
|
|
def test_application_directory_default(): |
28
|
|
|
reload(constants) |
|
|
|
|
29
|
|
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
30
|
|
|
assert constants.application_directory == expected_path, constants.application_directory |
31
|
|
|
|
32
|
|
|
def test_application_directory_override_invalid(): |
33
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar' |
34
|
|
|
reload(constants) |
|
|
|
|
35
|
|
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
36
|
|
|
assert constants.application_directory == expected_path, constants.application_directory |
37
|
|
|
|
38
|
|
|
def test_application_directory_override_valid(): |
39
|
|
|
cwd = os.getcwd() |
40
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd |
41
|
|
|
reload(constants) |
|
|
|
|
42
|
|
|
|
43
|
|
|
assert constants.application_directory == cwd, constants.application_directory |
44
|
|
|
assert cwd in constants.hash_db, constants.hash_db |
45
|
|
|
|
46
|
|
|
# must come after test_application_directory_override_valid due to env var reset |
47
|
|
|
def test_hash_db(): |
48
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '' |
49
|
|
|
reload(constants) |
|
|
|
|
50
|
|
|
assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db |
51
|
|
|
|
52
|
|
|
def test_location_db(): |
53
|
|
|
assert constants.location_db == '{}/location.json'.format(constants.application_directory), constants.location_db |
54
|
|
|
|
55
|
|
|
def test_script_directory(): |
56
|
|
|
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
57
|
|
|
assert path == constants.script_directory, constants.script_directory |
58
|
|
|
|
59
|
|
|
def test_exiftool_config(): |
60
|
|
|
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
61
|
|
|
assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config |
62
|
|
|
|
63
|
|
|
def test_accepted_language(): |
64
|
|
|
assert constants.accepted_language == 'en', constants.accepted_language |
65
|
|
|
|
66
|
|
|
def test_python_version(): |
67
|
|
|
assert constants.python_version == sys.version_info.major, constants.python_version |
68
|
|
|
|