summaryrefslogtreecommitdiff
path: root/test/test_config.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-10-31 19:15:57 +0100
committermathieui <mathieui@mathieui.net>2014-10-31 19:16:44 +0100
commit1c1ab3cb839e5509db52770e10c7190f844eb2e5 (patch)
treeb331060b3dc42651e61e4ccb2dfe6af5e2e97752 /test/test_config.py
parentcedc5a6ec80a46437f42464415fd1806049c593d (diff)
parentea2b703bfd07d293ba9fdd85ac657275d43da2a7 (diff)
downloadpoezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.gz
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.bz2
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.xz
poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.zip
Merge branch 'master' of git.poez.io:poezio into slix
Conflicts: src/bookmark.py src/config.py src/connection.py src/core/commands.py src/core/core.py src/core/handlers.py src/windows/info_bar.py src/windows/muc.py src/windows/roster_win.py src/windows/text_win.py src/xhtml.py
Diffstat (limited to 'test/test_config.py')
-rw-r--r--test/test_config.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/test_config.py b/test/test_config.py
new file mode 100644
index 00000000..f8d06258
--- /dev/null
+++ b/test/test_config.py
@@ -0,0 +1,114 @@
+"""
+Test the config module
+"""
+
+import tempfile
+import pytest
+import sys
+import os
+
+
+sys.path.append('src')
+
+import config
+
+@pytest.yield_fixture(scope="module")
+def config_obj():
+ file_ = tempfile.NamedTemporaryFile(delete=False)
+ conf = config.Config(file_name=file_.name)
+ yield conf
+ del conf
+ os.unlink(file_.name)
+
+class TestConfigSimple(object):
+ def test_get_set(self, config_obj):
+ config_obj.set_and_save('test', value='coucou')
+ config_obj.set_and_save('test2', value='true')
+ assert config_obj.get('test') == 'coucou'
+ assert config_obj.get('test2') == 'true'
+ assert config_obj.get('toto') == ''
+
+ def test_file_content(self, config_obj):
+ with open(config_obj.file_name, 'r') as fd:
+ data = fd.read()
+ supposed_content = '[Poezio]\ntest = coucou\ntest2 = true\n'
+ assert data == supposed_content
+
+ def test_get_types(self, config_obj):
+
+ config_obj.set_and_save('test_int', '99')
+ config_obj.set_and_save('test_int_neg', '-1')
+ config_obj.set_and_save('test_bool_t', 'true')
+ config_obj.set_and_save('test_bool_f', 'false')
+ config_obj.set_and_save('test_float', '1.5')
+
+ assert config_obj.get('test_int', default=0) == 99
+ assert config_obj.get('test_int_neg', default=0) == -1
+ assert config_obj.get('test_bool_t', default=False) == True
+ assert config_obj.get('test_bool_f', default=True) == False
+ assert config_obj.get('test_float', default=1.0) == 1.5
+
+ def test_remove(self, config_obj):
+ with open(config_obj.file_name, 'r') as fd:
+ data = fd.read()
+
+ supposed_content = ('[Poezio]\ntest = coucou\ntest2 = true\n'
+ 'test_int = 99\ntest_int_neg = -1\ntest_bool_t ='
+ ' true\ntest_bool_f = false\ntest_float = 1.5\n')
+
+ assert data == supposed_content
+
+ config_obj.remove_and_save('test_int')
+ config_obj.remove_and_save('test_int_neg')
+ config_obj.remove_and_save('test_bool_t')
+ config_obj.remove_and_save('test_bool_f')
+ config_obj.remove_and_save('test_float')
+
+ with open(config_obj.file_name, 'r') as fd:
+ data = fd.read()
+
+ supposed_content = '[Poezio]\ntest = coucou\ntest2 = true\n'
+
+ assert data == supposed_content
+
+
+ def test_toggle(self, config_obj):
+ config_obj.set_and_save('test2', value='toggle')
+ assert config_obj.get('test2') == 'false'
+ config_obj.set_and_save('test2', value='toggle')
+ assert config_obj.get('test2') == 'true'
+
+ def test_get_set_default(self, config_obj):
+ assert config_obj.get('doesnotexist', 'toto@tata') == 'toto@tata'
+ assert config_obj.get('doesnotexist2', '1234') == '1234'
+
+class TestConfigSections(object):
+ def test_set_section(self, config_obj):
+ config_obj.set_and_save('option1', 'test', section='NotPoezio')
+ config_obj.set_and_save('option2', 'test2', section='NotPoezio')
+
+ assert config_obj.get('option1', section='NotPoezio') == 'test'
+ assert config_obj.get('option2', section='NotPoezio') == 'test2'
+
+ def test_file_content(self, config_obj):
+ with open(config_obj.file_name, 'r') as fd:
+ data = fd.read()
+ supposed_content = ('[Poezio]\ntest = coucou\ntest2 = true\n'
+ '[NotPoezio]\noption1 = test\noption2 = test2\n')
+ assert data == supposed_content
+
+class TestTabNames(object):
+ def test_get_tabname(self, config_obj):
+ config.post_logging_setup()
+ config_obj.set_and_save('test', value='value.toto@toto.com',
+ section='toto@toto.com')
+ config_obj.set_and_save('test2', value='value2@toto.com',
+ section='@toto.com')
+
+ assert config_obj.get_by_tabname('test', 'toto@toto.com') == 'value.toto@toto.com'
+ assert config_obj.get_by_tabname('test2', 'toto@toto.com') == 'value2@toto.com'
+ assert config_obj.get_by_tabname('test2', 'toto@toto.com', fallback=False) == 'value2@toto.com'
+ assert config_obj.get_by_tabname('test2', 'toto@toto.com', fallback_server=False) == 'true'
+ assert config_obj.get_by_tabname('test_int', 'toto@toto.com', fallback=False) == ''
+
+