Пример #1
0
import pytest
import testdata

from meety import io

casefold_data = testdata.load(["io", "test_casefold.yaml"])


@pytest.mark.parametrize("input_data, expected_data", [
    (c["input"], c["expected"])
    for c in casefold_data
])
def test_casefold(input_data, expected_data):
    output = io.process_recursively(
        input_data,
        io._casefold_keys
    )
    assert output == expected_data
Пример #2
0
from datetime import datetime

import pytest
import testdata

from meety.meetings.preferences import (
    DateInterval,
    DisjunctiveIntervals,
    TimeInterval,
    TimeMatchDescription,
    reset_options,
)

delta_data = testdata.load(["meetings", "test_delta.yaml"])


@pytest.mark.parametrize("spec, config, tests",
                         [(c["spec"], c["config"], c["tests"])
                          for c in delta_data.get("date") or []])
def test_date_delta(spec, config, tests):
    reset_options()
    interval = DisjunctiveIntervals.parse_date(spec)
    DateInterval.set_options(config)
    for test in tests:
        test_date = test["test_date"]
        test_time = test.get("test_time")
        test_date = testdata.str_to_date(test_date)
        expected = test["expected"]
        if test_time:
            test_time = testdata.str_to_time(test_time)
            test_date = datetime.combine(test_date, test_time)
Пример #3
0
import pytest
import testdata

from meety import io

synonym_data = testdata.load(["io", "test_list_of_ranges.yaml"])


@pytest.mark.parametrize("input_data, expected_data", [
    (c["input"], c["expected"])
    for c in synonym_data
])
def test_list_of_ranges(input_data, expected_data):
    testdata.apply_language_configurations("lang_en", "lang_de")
    output = io.datetime.prepare_list_of_ranges(input_data)
    assert output == expected_data
Пример #4
0
import pytest
import testdata

from meety.meetings import preferences
from meety.meetings.preferences import TimePreference

match_config_general = testdata.load(["meetings", "test_match.yaml"])
match_config_en = testdata.load(["meetings", "test_match_en.yaml"])
match_config_de = testdata.load(["meetings", "test_match_de.yaml"])
match_config_fr = testdata.load(["meetings", "test_match_fr.yaml"])


@pytest.mark.parametrize("prefer, tests", [
    (c["prefer"], c["tests"]) for c in match_config_general
])
def test_match_general(prefer, tests):
    preferences.reset_options()
    testdata.apply_language_configurations("lang_en")
    _test_match(prefer, tests)


@pytest.mark.parametrize("prefer, tests", [
    (c["prefer"], c["tests"]) for c in match_config_en
])
def test_match_en(prefer, tests):
    preferences.reset_options()
    testdata.apply_language_configurations("lang_en")
    _test_match(prefer, tests)


@pytest.mark.parametrize("prefer, tests", [
Пример #5
0
import pytest
import testdata

from meety import io

synonym_data = testdata.load(["io", "test_synonym.yaml"])


@pytest.mark.parametrize("input_data, expected_data, target_level",
                         [(c["input"], c["expected"], c.get("level"))
                          for c in synonym_data])
def test_synonym(input_data, expected_data, target_level):
    action = io.actions.SynonymAction("out", ["in1", "in2"])
    if target_level:
        action.set_conditions(target_level)
    output = io.process_recursively(
        input_data, lambda d, current_level: action.apply(d, current_level))
    assert output == expected_data
Пример #6
0
from datetime import datetime

import pytest
import testdata

from meety.meetings.preferences import (
    FALSE_INTERVAL,
    TRUE_INTERVAL,
    DisjunctiveIntervals,
    TimeMatchDescription,
    reset_options,
)

interval_config = testdata.load(["meetings", "test_intervals.yaml"])


def test_empty_disjunctive_interval_is_satisfied():
    interval = DisjunctiveIntervals([])
    assert interval.is_satisfied(datetime.now())


def test_false_interval_does_not_match():
    assert not FALSE_INTERVAL.match(datetime.now())


def test_true_interval_is_satisfied():
    assert TRUE_INTERVAL.match(datetime.now())


@pytest.mark.parametrize(
    "text, tests", [(c["text"], c["tests"])
Пример #7
0
import pytest
import testdata

from meety import io
from meety.loader import Loader
from meety.meetings.rating import (
    RatedMeeting,
    Ratings,
)

test_config = testdata.load(["meetings", "test_rating.yaml"])


@pytest.mark.parametrize("filename, query, query_type, when, pfactor, rated", [
    (
        c["file"],
        c["query"],
        c.get("type", "all-matching"),
        c.get("when"),
        c.get("pfactor", 0),
        c["rated"]
    ) for c in test_config
])
def test_rating(filename, query, query_type, when, pfactor, rated):
    loader = Loader()
    loader.load_from_file(testdata.testpath(["data", filename]))
    io.reset_options()

    r = Ratings(loader.meetings)
    RatedMeeting.PREFER_FACTOR = int(pfactor)
    when = testdata.str_to_datetime(when)
Пример #8
0
import pytest
import testdata

from meety import io

replace_data = testdata.load(["io", "test_replace.yaml"])


@pytest.mark.parametrize("key, expression, substitute, input_data, expected", [
    (
        c["key"],
        c["expression"],
        c["substitute"],
        c["input"],
        c["expected"],
    )
    for c in replace_data
])
def test_replace(key, expression, substitute, input_data, expected):
    action = io.actions.ReplaceAction(key, expression, substitute)
    output = io.process_recursively(
        input_data,
        lambda d, current_level:
        action.apply(d, current_level)
    )
    assert output == expected
Пример #9
0
import pytest
import testdata

from meety import io

infer_data = testdata.load(["io", "test_infer.yaml"])


@pytest.mark.parametrize("name, value, input_data, expected_data",
                         [(c["name"], c["value"], c["input"], c["expected"])
                          for c in infer_data])
def test_infer(name, value, input_data, expected_data):
    action = io.actions.InferAction(name, value)
    output = io.process_recursively(input_data,
                                    lambda d, level: action.apply(d, level))
    assert output == expected_data
Пример #10
0
import pytest
import testdata

from meety import meetings
from meety.config import PartialConfig
from meety.loader import Loader

test_config = testdata.load(["test_loader.yaml"])


@pytest.mark.parametrize("filename, further_filenames, expected, config", [
    (c["file"], c.get("further-files", []), c["expected"], c.get("config", {}))
    for c in test_config
])
def test_loader(filename, further_filenames, expected, config):
    """Compare cleaned dicts of loaded meetings with expected dicts."""
    test_config = PartialConfig("test config", None, None)
    test_config._data = config
    test_config.apply()
    meetings.reset_options()
    meetings.set_options(test_config.meetings, "test_config")

    loader = Loader()
    _load_file(loader, filename)
    for f in further_filenames:
        _load_file(loader, f)
    assert [m.data for m in loader.meetings] == expected


def _load_file(loader, filename):
    loader.load_from_file(testdata.testpath(["data", filename]))