samba python tests: convert 'except X, e' to 'except X as e'
[samba.git] / python / samba / tests / docs.py
index fbe783b7fab3b904f6f5975eb89e502f4d10a6c4..3d896d7c7d2bf87097ab3097e6aea1297a7c708d 100644 (file)
@@ -42,7 +42,7 @@ def get_documented_parameters(sourcedir):
         raise Exception("Unable to find parameters.all.xml")
     try:
         p = open(os.path.join(path, "parameters.all.xml"), 'r')
-    except IOError, e:
+    except IOError as e:
         raise Exception("Error opening parameters file")
     out = p.read()
 
@@ -59,94 +59,13 @@ def get_documented_parameters(sourcedir):
     p.close()
 
 
-def get_implementation_parameters(sourcedir):
-    # Reading entries from source code
-    f = open(os.path.join(sourcedir, "lib/param/param_table_static.c"), "r")
-    try:
-        # burn through the preceding lines
-        while True:
-            l = f.readline()
-            if l.startswith("struct parm_struct parm_table"):
-                break
-
-        for l in f.readlines():
-            if re.match("^\s*\}\;\s*$", l):
-                break
-            # pull in the param names only
-            m = re.match("\s*\.label\s*=\s*\"(.*)\".*", l)
-            if not m:
-                continue
-
-            name = m.group(1)
-            yield name
-    finally:
-        f.close()
-
-def get_param_table_full(sourcedir, filename="lib/param/param_table_static.c"):
-    # Reading entries from source code
-    f = open(os.path.join(sourcedir, filename), "r")
-    try:
-        # burn through the preceding lines
-        while True:
-            l = f.readline()
-            if l.startswith("struct parm_struct parm_table"):
-                break
-
-        for l in f.readlines():
-
-            if re.match("^\s*\}\;\s*$", l):
-                # end of the table reached
-                break
-
-            if re.match("^\s*\{\s*$", l):
-                # start a new entry
-                _label = ""
-                _type = ""
-                _class = ""
-                _offset = ""
-                _special = ""
-                _enum_list = ""
-                _flags = ""
-                continue
-
-            if re.match("^\s*\},\s*$", l):
-                # finish the entry
-                yield _label, _type, _class, _offset, _special, _enum_list, _flags
-                continue
-
-            m = re.match("^\s*\.([^\s]+)\s*=\s*(.*),.*", l)
-            if not m:
-                continue
-
-            attrib = m.group(1)
-            value = m.group(2)
-
-            if attrib == "label":
-                _label = value
-            elif attrib == "type":
-                _type = value
-            elif attrib == "p_class":
-                _class = value
-            elif attrib == "offset":
-                _offset = value
-            elif attrib == "special":
-                _special = value
-            elif attrib == "enum_list":
-                _special = value
-            elif attrib == "flags":
-                _flags = value
-
-    finally:
-        f.close()
-
-
 def get_documented_tuples(sourcedir, omit_no_default=True):
     path = os.path.join(sourcedir, "bin", "default", "docs-xml", "smbdotconf")
     if not os.path.exists(os.path.join(path, "parameters.all.xml")):
         raise Exception("Unable to find parameters.all.xml")
     try:
         p = open(os.path.join(path, "parameters.all.xml"), 'r')
-    except IOError, e:
+    except IOError as e:
         raise Exception("Error opening parameters file")
     out = p.read()
 
@@ -180,15 +99,15 @@ def get_documented_tuples(sourcedir, omit_no_default=True):
 class SmbDotConfTests(TestCase):
 
     # defines the cases where the defaults may differ from the documentation
-    special_cases = set(['log level', 'path', 'ldapsam:trusted', 'spoolss: architecture',
-                         'share:fake_fscaps', 'ldapsam:editposix', 'rpc_daemon:DAEMON',
-                         'rpc_server:SERVER', 'panic action', 'homedir map', 'NIS homedir',
+    special_cases = set(['log level', 'path',
+                         'panic action', 'homedir map', 'NIS homedir',
                          'server string', 'netbios name', 'socket options', 'use mmap',
                          'ctdbd socket', 'printing', 'printcap name', 'queueresume command',
                          'queuepause command','lpresume command', 'lppause command',
                          'lprm command', 'lpq command', 'print command', 'template homedir',
-                         'spoolss: os_major', 'spoolss: os_minor', 'spoolss: os_build',
-                         'max open files', 'fss: prune stale', 'fss: sequence timeout'])
+                         'max open files',
+                         'include system krb5 conf', 'rpc server dynamic port range',
+                         'mit kdc command'])
 
     def setUp(self):
         super(SmbDotConfTests, self).setUp()
@@ -217,17 +136,6 @@ class SmbDotConfTests(TestCase):
         except:
             self.fail("Unable to load documented parameters")
 
-        try:
-            self.parameters = set(get_implementation_parameters(self.topdir))
-        except:
-            self.fail("Unable to load implemented parameters")
-
-        try:
-            self.table_static = set(get_param_table_full(self.topdir,
-                                   "lib/param/param_table_static.c"))
-        except:
-            self.fail("Unable to load static parameter table")
-
         try:
             self.defaults = set(get_documented_tuples(self.topdir))
         except:
@@ -244,21 +152,6 @@ class SmbDotConfTests(TestCase):
         os.unlink(self.smbconf)
         os.unlink(self.blankconf)
 
-    def test_unknown(self):
-        # Filter out parametric options, since we can't find them in the parm
-        # table
-        documented = set([p for p in self.documented if not ":" in p])
-        unknown = documented.difference(self.parameters)
-        if len(unknown) > 0:
-            self.fail(self._format_message(unknown,
-                "Parameters that are documented but not in the implementation:"))
-
-    def test_undocumented(self):
-        undocumented = self.parameters.difference(self.documented)
-        if len(undocumented) > 0:
-            self.fail(self._format_message(undocumented,
-                "Parameters that are in the implementation but undocumented:"))
-
     def test_default_s3(self):
         self._test_default(['bin/testparm'])
         self._set_defaults(['bin/testparm'])
@@ -268,14 +161,18 @@ class SmbDotConfTests(TestCase):
             exceptions = ['client lanman auth',
                           'client plaintext auth',
                           'registry shares',
-                          'smb ports'])
+                          'smb ports',
+                          'rpc server dynamic port range',
+                          'name resolve order'])
         self._test_empty(['bin/testparm'])
 
     def test_default_s4(self):
         self._test_default(['bin/samba-tool', 'testparm'])
         self._set_defaults(['bin/samba-tool', 'testparm'])
         self._set_arbitrary(['bin/samba-tool', 'testparm'],
-            exceptions = ['smb ports'])
+            exceptions = ['smb ports',
+                          'rpc server dynamic port range',
+                          'name resolve order'])
         self._test_empty(['bin/samba-tool', 'testparm'])
 
     def _test_default(self, program):
@@ -284,8 +181,12 @@ class SmbDotConfTests(TestCase):
 
         for tuples in self.defaults:
             param, default, context, param_type = tuples
+
             if param in self.special_cases:
                 continue
+            # bad, bad parametric options - we don't have their default values
+            if ':' in param:
+                continue
             section = None
             if context == "G":
                 section = "global"
@@ -312,7 +213,7 @@ class SmbDotConfTests(TestCase):
         for tuples in self.defaults:
             param, default, context, param_type = tuples
 
-            if param in ['printing']:
+            if param in ['printing', 'rpc server dynamic port range']:
                 continue
 
             section = None