| # SPDX-License-Identifier: MIT | |
| """ | |
| Tests for `attr._config`. | |
| """ | |
| import pytest | |
| from attr import _config | |
| class TestConfig: | |
| 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() | |
| 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] |