<commit_before>import datetime as dt
import os.path

import pytest
from khal.settings import get_config
from khal.settings.exceptions import (CannotParseConfigFileError,
                                      InvalidSettingsError)
from khal.settings.utils import (config_checks, get_all_vdirs,
                                 get_color_from_vdir, get_unique_name,
                                 is_color)
from tzlocal import get_localzone
from validate import VdtValueError

from .utils import LOCALE_BERLIN

PATH = __file__.rsplit('/', 1)[0] + '/configs/'


class TestSettings(object):
    def test_simple_config(self):
        config = get_config(
            PATH + 'simple.conf',
            _get_color_from_vdir=lambda x: None,
            _get_vdir_type=lambda x: 'calendar',
        )
        comp_config = {
            'calendars': {
                'home': {'path': os.path.expanduser('~/.calendars/home/'),
                         'readonly': False, 'color': None, 'type': 'calendar'},
                'work': {'path': os.path.expanduser('~/.calendars/work/'),
                         'readonly': False, 'color': None, 'type': 'calendar'},
            },
            'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
            'locale': LOCALE_BERLIN,
            'default': {
                'default_calendar': None,
                'print_new': 'False',
                'highlight_event_days': False,
                'timedelta': dt.timedelta(days=2),
                'show_all_days': False,
            }
        }
        for key in comp_config:
            assert config[key] == comp_config[key]

    def test_nocalendars(self):
        with pytest.raises(InvalidSettingsError):
            get_config(PATH + 'nocalendars.conf')

    def test_one_level_calendar(self):
        with pytest.raises(InvalidSettingsError):
            get_config(PATH + 'one_level_calendars.conf')

    def test_small(self):
        config = get_config(
            PATH + 'small.conf',
            _get_color_from_vdir=lambda x: None,
            _get_vdir_type=lambda x: 'calendar',
        )
        comp_config = {
            'calendars': {
                'home': {'path': os.path.expanduser('~/.calendars/home/'),
                         'color': 'dark green', 'readonly': False,
                         'type': 'calendar'},
                'work': {'path': os.path.expanduser('~/.calendars/work/'),
                         'readonly': True, 'color': None,
                         'type': 'calendar'}},
            'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
            'locale': {
                'local_timezone': get_localzone(),
                'default_timezone': get_localzone(),
                'timeformat': '%X',
                'dateformat': '%x',
                'longdateformat': '%x',
                'datetimeformat': '%c',
                'longdatetimeformat': '%c',<commit_msg>Add priority to settings_test No additional testing added, just prevents previous tests failing<commit_after>import datetime as dt
import os.path

import pytest
from khal.settings import get_config
from khal.settings.exceptions import (CannotParseConfigFileError,
                                      InvalidSettingsError)
from khal.settings.utils import (config_checks, get_all_vdirs,
                                 get_color_from_vdir, get_unique_name,
                                 is_color)
from tzlocal import get_localzone
from validate import VdtValueError

from .utils import LOCALE_BERLIN

PATH = __file__.rsplit('/', 1)[0] + '/configs/'


class TestSettings(object):
    def test_simple_config(self):
        config = get_config(
            PATH + 'simple.conf',
            _get_color_from_vdir=lambda x: None,
            _get_vdir_type=lambda x: 'calendar',
        )
        comp_config = {
            'calendars': {
                'home': {'path': os.path.expanduser('~/.calendars/home/'),
                         'readonly': False, 'color': None, 'priority': 10, 'type': 'calendar'},
                'work': {'path': os.path.expanduser('~/.calendars/work/'),
                         'readonly': False, 'color': None, 'priority': 10, 'type': 'calendar'},
            },
            'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
            'locale': LOCALE_BERLIN,
            'default': {
                'default_calendar': None,
                'print_new': 'False',
                'highlight_event_days': False,
                'timedelta': dt.timedelta(days=2),
                'show_all_days': False,
            }
        }
        for key in comp_config:
            assert config[key] == comp_config[key]

    def test_nocalendars(self):
        with pytest.raises(InvalidSettingsError):
            get_config(PATH + 'nocalendars.conf')

    def test_one_level_calendar(self):
        with pytest.raises(InvalidSettingsError):
            get_config(PATH + 'one_level_calendars.conf')

    def test_small(self):
        config = get_config(
            PATH + 'small.conf',
            _get_color_from_vdir=lambda x: None,
            _get_vdir_type=lambda x: 'calendar',
        )
        comp_config = {
            'calendars': {
                'home': {'path': os.path.expanduser('~/.calendars/home/'),
                         'color': 'dark green', 'readonly': False, 'priority': 10,
                         'type': 'calendar'},
                'work': {'path': os.path.expanduser('~/.calendars/work/'),
                         'readonly': True, 'color': None, 'priority': 10,
                         'type': 'calendar'}},
            'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
            'locale': {
                'local_timezone': get_localzone(),
                'default_timezone': get_localzone(),
                'timeformat': '%X',
                'dateformat': '%x',
                'longdateformat': '%x',
                'datetimeformat': '%c',
                'longdatetimeformat': '%c',
{'fraction_non_alphanumeric': 0.1322655217965654, 'fraction_numerical': 0.002311756935270806, 'mean_word_length': 1.802869042110134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2095063', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1697, 'n_words': 341}