diff options
author | Chris Rose <offline@offby1.net> | 2018-05-16 10:29:46 -0400 |
---|---|---|
committer | Chris Rose <offline@offby1.net> | 2018-05-16 17:18:50 -0400 |
commit | 2bc68629f386e1eb4771cc363d64665e51eebea0 (patch) | |
tree | ad7ced37cfb43d8b084b051c9d802c9f1904f331 /tests | |
parent | 413bf37df7c9bf88d70d2b046935687c072980d4 (diff) |
Add an SSHConfig dict to provide type conversion helpers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_config.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 00000000..9edab3d9 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,45 @@ +# This file is part of Paramiko and subject to the license in /LICENSE in this +# repository + +import pytest +from paramiko import config + + +def test_SSHConfigDict_construct_empty(): + assert not config.SSHConfigDict() + + +def test_SSHConfigDict_construct_from_list(): + assert config.SSHConfigDict([(1, 2)])[1] == 2 + + +def test_SSHConfigDict_construct_from_dict(): + assert config.SSHConfigDict({1: 2})[1] == 2 + + +@pytest.mark.parametrize("true_ish", ("yes", "YES", "Yes", True)) +def test_SSHConfigDict_as_bool_true_ish(true_ish): + assert config.SSHConfigDict({"key": true_ish}).as_bool("key") is True + + +@pytest.mark.parametrize("false_ish", ("no", "NO", "No", False)) +def test_SSHConfigDict_as_bool(false_ish): + assert config.SSHConfigDict({"key": false_ish}).as_bool("key") is False + + +@pytest.mark.parametrize("int_val", ("42", 42)) +def test_SSHConfigDict_as_int(int_val): + assert config.SSHConfigDict({"key": int_val}).as_int("key") == 42 + + +@pytest.mark.parametrize("non_int", ("not an int", None, object())) +def test_SSHConfigDict_as_int_failures(non_int): + conf = config.SSHConfigDict({"key": non_int}) + + try: + int(non_int) + except Exception as e: + exception_type = type(e) + + with pytest.raises(exception_type): + conf.as_int("key") |