[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] config: Use configuration provided as argument



commit 21ce9b69d7cf4275e5c8c290f2021495beb1e984
Author: juga0 <juga@xxxxxxxxxx>
Date:   Fri Dec 7 17:31:03 2018 +0000

    config: Use configuration provided as argument
    
    Fixes bug #28724. Bugfix v0.7.0.
---
 sbws/util/config.py                |  7 +++++--
 tests/unit/util/data/user_sbws.ini |  3 +++
 tests/unit/util/test_config.py     | 10 +++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 1aaff53..22f7cbd 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -70,11 +70,14 @@ def _get_user_config(args, conf=None):
             # sbws should start with a logger before reading configurations.
             print('Configuration file %s not found, using defaults.' %
                   args.config)
-        return conf
+            return conf
+        print('Using configuration provided as argument %s' % args.config)
+        return _extend_config(conf, args.config)
     user_config_path = _obtain_user_conf_path()
     if os.path.isfile(user_config_path):
+        print('Using configuration file %s' % user_config_path)
         return _extend_config(conf, user_config_path)
-    log.debug('No user config found.')
+    log.debug('No user config found, using defaults.')
     return conf
 
 
diff --git a/tests/unit/util/data/user_sbws.ini b/tests/unit/util/data/user_sbws.ini
new file mode 100644
index 0000000..6dae60c
--- /dev/null
+++ b/tests/unit/util/data/user_sbws.ini
@@ -0,0 +1,3 @@
+[paths]
+
+sbws_home = /tmp/.sbws
\ No newline at end of file
diff --git a/tests/unit/util/test_config.py b/tests/unit/util/test_config.py
index e1ce169..95dde6f 100644
--- a/tests/unit/util/test_config.py
+++ b/tests/unit/util/test_config.py
@@ -237,4 +237,12 @@ def test_nickname():
 
 def test_config_arg_provided_but_no_found(args, conf):
     args.config = 'non_existing_file'
-    con._get_user_config(args, conf=None)
+    user_conf = con._get_user_config(args, conf)
+    # since the user configuration is not found, it is the same as conf
+    assert conf.__dict__.items() == user_conf.__dict__.items()
+
+
+def test_config_arg_provided(args, conf, datadir):
+    args.config = datadir.join('user_sbws.ini')
+    user_conf = con._get_user_config(args, conf)
+    assert user_conf['paths']['sbws_home'] == '/tmp/.sbws'



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits