Przeglądaj źródła

Add more testing for config

oz123 10 lat temu
rodzic
commit
57a3a78b38
4 zmienionych plików z 20 dodań i 11 usunięć
  1. 2 1
      pwman/__init__.py
  2. 2 2
      pwman/tests/db_tests.py
  3. 9 3
      pwman/util/config.py
  4. 7 5
      scripts/pwman3

+ 2 - 1
pwman/__init__.py

@@ -114,7 +114,8 @@ def get_conf_file(args):
     if not os.path.exists(args.cfile):
         # instead of setting the defaults, the defaults should
         # be read ! This should be fixed !
-        config.set_defaults(default_config)
+        # config.set_defaults(default_config)
+        config.set_config(default_config)
     else:
         config.load(args.cfile)
 

+ 2 - 2
pwman/tests/db_tests.py

@@ -448,13 +448,13 @@ class ConfigTest(unittest.TestCase):
             self.assertEqual(None, config._conf['Global']['xsel'])
 
     def test_get_conf_file(self):
-
         Args = namedtuple('args', 'cfile')
         args = Args(cfile='nosuchfile')
         # setting the default
         # in case the user specifies cfile as command line option
         # and that file does not exist!
+        foo = config._conf.copy()
         get_conf_file(args)
         # args.cfile does not exist, hence the config values
         # should be the same as in the defaults
-        # Fix this issue, see comment LN155 in config.py
+        config.set_config(foo)

+ 9 - 3
pwman/util/config.py

@@ -29,7 +29,8 @@ class ConfigException(Exception):
         self.message = message
 
     def __str__(self):
-        return "%s: %s" % (self.__class__.__name__, self.message)  # pragma: no cover
+        return "{}: {}".format(self.__class__.__name__,
+                               self.message)  # pragma: no cover
 
 
 class ConfigNoConfigException(ConfigException):
@@ -58,14 +59,14 @@ def get_value(section, name):
     global _conf, _defaults
     try:
         return _conf[section][name]
-    except KeyError as e:
+    except KeyError:
         pass
 
     try:
         value = _defaults[section][name]
         set_value(section, name, value)
         return value
-    except KeyError as e:
+    except KeyError:
         pass
 
     return ''
@@ -114,6 +115,11 @@ def load(filename):
             set_value(section, option, parser.get(section, option))
 
 
+def set_config(config_dict):
+    global _conf
+    _conf = config_dict
+
+
 def save(filename=None):
     """Save the configuration to 'filename'."""
     global _conf, _file

+ 7 - 5
scripts/pwman3

@@ -38,7 +38,8 @@ def auto_convert():
         # This step is done already in get_db_version
         dbconvertor = PwmanConvertDB(args, config)
 
-        #2) copy the old database : cp ~/.pwman3/pwman.db ~/.pwman3/pwman.backup-2013-11-23-23:15.db
+        #2) copy the old database :
+        # cp ~/.pwman3/pwman.db  ~/.pwman3/pwman.backup-2013-11-23-23:15.db
         #3) Display a message about the backup file path
         # These steps are done by PwmanConvertDB.backup_old_db()
         dbconvertor.backup_old_db()
@@ -57,7 +58,8 @@ def auto_convert():
         # add message here ...
         #5b) close connection
         dbconvertor.db.close()
-        print("Your datbase %s was successfully converted " % dbconvertor.dbname)
+        print("Your datbase %s was successfully converted " %
+              dbconvertor.dbname)
         #5c) rename the newly created db to the old name!
         shutil.move(dbconvertor.newdb_name, dbconvertor.dbname)
         #6) Start the pwman3 normally if all went ok
@@ -70,7 +72,7 @@ def main(args):
     PwmanCliNew, OSX = get_ui_platform(sys.platform)
     xselpath, dbtype = get_conf_options(args, OSX)
     dbver = get_db_version(config, dbtype, args)
-    enc = CryptoEngine.get(dbver)
+    CryptoEngine.get(dbver)
 
     if args.dbconvert:
         dbconvertor = PwmanConvertDB(args, config)
@@ -78,8 +80,8 @@ def main(args):
         sys.exit(0)
 
     if dbver < 0.4:
-        ans = raw_input("Would you like to proceed with the conversion of the database"
-                        " before starting pwman3 [y/N]?")
+        ans = raw_input("Would you like to proceed with the conversion of the "
+                        "database before starting pwman3 [y/N]?")
         if ans.lower() != "y":
             sys.exit(1)