2021-12-27 08:29:09 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2015-02-20 10:30:46 +00:00
|
|
|
"""
|
|
|
|
Tests for `attr._config`.
|
|
|
|
"""
|
|
|
|
|
2015-06-05 18:28:50 +00:00
|
|
|
import pytest
|
|
|
|
|
2015-02-20 10:30:46 +00:00
|
|
|
from attr import _config
|
|
|
|
|
|
|
|
|
2022-03-21 07:47:47 +00:00
|
|
|
class TestConfig:
|
2015-02-20 10:30:46 +00:00
|
|
|
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]
|