Bladeren bron

Add some testing for the config module

oz123 10 jaren geleden
bovenliggende
commit
269c36e96c
2 gewijzigde bestanden met toevoegingen van 17 en 2 verwijderingen
  1. 3 1
      pwman/__init__.py
  2. 14 1
      pwman/tests/db_tests.py

+ 3 - 1
pwman/__init__.py

@@ -108,10 +108,12 @@ def parser_options(formatter_class=argparse.HelpFormatter):
 def get_conf_file(args):
     config_dir = os.path.expanduser("~/.pwman")
 
-    if not os.path.isdir(config_dir):
+    if not os.path.isdir(config_dir):  # pragma: no cover
         os.mkdir(config_dir)
 
     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)
     else:
         config.load(args.cfile)

+ 14 - 1
pwman/tests/db_tests.py

@@ -28,10 +28,11 @@ from pwman import default_config, set_xsel
 from pwman.ui import get_ui_platform
 from pwman.ui.base import get_pass_conf
 from pwman.ui.tools import CMDLoop, CliMenuItem
-from pwman import parser_options, get_conf_options
+from pwman import (parser_options, get_conf_options, get_conf_file)
 from pwman.data.database import __DB_FORMAT__
 from pwman.ui.mac import PwmanCliMacNew
 from pwman.ui.win import PwmanCliWinNew
+from collections import namedtuple
 
 import unittest
 import StringIO
@@ -445,3 +446,15 @@ class ConfigTest(unittest.TestCase):
         set_xsel(config, True)
         if sys.platform == 'linux2':
             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!
+        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