todoist-taskwarrior/tests/test_validation.py

34 lines
853 B
Python
Raw Normal View History

2019-03-30 18:34:29 +01:00
""" Validation Tests
Test argument/option validations
"""
import click
import pytest
from todoist_taskwarrior import utils
def validate(fn, value):
"""Calls the validation with None for `ctx` and `param`.
Note: This could definitely be an issue for validations that
use either param, but at the moment it's a simplification
which works.
"""
return fn(None, None, value)
def test_validate_map():
2019-03-30 18:34:29 +01:00
# Simple
assert validate(utils.validate_map, ('HELLO=WORLD',)) == {'HELLO': 'WORLD'}
2019-03-30 18:34:29 +01:00
# Missing DST
assert validate(utils.validate_map, ('HELLO=',)) == {'HELLO': None}
2019-03-30 18:34:29 +01:00
# Multiple
assert validate(utils.validate_map, ('FOO=BAR', 'BAR=BAZZ')) == {'FOO': 'BAR', 'BAR': 'BAZZ'}
2019-03-30 18:34:29 +01:00
# Invalid, no '='
with pytest.raises(click.BadParameter):
assert validate(utils.validate_map, ('FOO',)) == None
2019-03-30 18:34:29 +01:00