2015-02-20 10:30:46 +00:00
|
|
|
"""
|
|
|
|
Tests for `attr._config`.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
2015-06-05 18:28:50 +00:00
|
|
|
import pytest
|
|
|
|
|
2015-02-20 10:30:46 +00:00
|
|
|
from attr import _config
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfig(object):
|
|
|
|
def test_default(self):
|
|
|
|
"""
|
|
|
|
Run validators by default.
|
|
|
|
"""
|
|
|
|
assert True is _config._run_validators
|
|
|
|
|
|
|
|
def test_set_run_validators(self):
|
|
|
|
"""
|
|
|
|
Sets `_run_validators`.
|
|
|
|
"""
|
|
|
|
_config.set_run_validators(False)
|
|
|
|
assert False is _config._run_validators
|
|
|
|
_config.set_run_validators(True)
|
|
|
|
assert True is _config._run_validators
|
|
|
|
|
|
|
|
def test_get_run_validators(self):
|
|
|
|
"""
|
|
|
|
Returns `_run_validators`.
|
|
|
|
"""
|
|
|
|
_config._run_validators = False
|
|
|
|
assert _config._run_validators is _config.get_run_validators()
|
|
|
|
_config._run_validators = True
|
|
|
|
assert _config._run_validators is _config.get_run_validators()
|
2015-06-05 18:28:50 +00:00
|
|
|
|
|
|
|
def test_wrong_type(self):
|
|
|
|
"""
|
|
|
|
Passing anything else than a boolean raises TypeError.
|
|
|
|
"""
|
|
|
|
with pytest.raises(TypeError) as e:
|
|
|
|
_config.set_run_validators("False")
|
|
|
|
assert "'run' must be bool." == e.value.args[0]
|