[PATCHES] unshadow python methods

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Thu Oct 25 09:48:50 UTC 2018


twice in one day.

On 25/10/18 10:38 PM, Douglas Bagnall via samba-technical wrote:
> In Python, if you go:
> 
>     def foo(x):
>         return x * 2
> 
>     def foo(x):
>         return x * 3
> 
> the first definition will be silently ignored.
> 
> We do this in a few places.
> 
> CI: https://gitlab.com/samba-team/devel/samba/pipelines/34239680
> (though if you look closely you will see I have split the first patch
> there in two).
> 
> Douglas
> 

-------------- next part --------------
From 33556cc5d6749cefa8ffcef3482f88c55b13a678 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 13:23:01 +1300
Subject: [PATCH 01/10] python/gp_parse/gp_inf: remove shadowed method

The 'from_xml()' definition is replaced a few lines down

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/gp_parse/gp_inf.py | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/python/samba/gp_parse/gp_inf.py b/python/samba/gp_parse/gp_inf.py
index 4d39cb0f03a..622b7be7e2e 100644
--- a/python/samba/gp_parse/gp_inf.py
+++ b/python/samba/gp_parse/gp_inf.py
@@ -186,15 +186,6 @@ class GptTmplInfParser(GPParser):
             # print line
             self.param_list.append(parameters)
 
-        def from_xml(self, section):
-            for param in section.findall('Parameter'):
-                key = param.find('Key').text
-                value = param.find('Value').text
-                if value is None:
-                    value = ''
-
-                self.param_list.append((key, value))
-
         def write_section(self, header, fp):
             if len(self.param_list) ==  0:
                 return
-- 
2.11.0


From abe8f4c9823b98523870888e5c47e9e051d3b4af Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 25 Oct 2018 22:34:31 +1300
Subject: [PATCH 02/10] python/gp_parse/gp_inf: remove unused variables

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/gp_parse/gp_inf.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/python/samba/gp_parse/gp_inf.py b/python/samba/gp_parse/gp_inf.py
index 622b7be7e2e..e4bed26b2d9 100644
--- a/python/samba/gp_parse/gp_inf.py
+++ b/python/samba/gp_parse/gp_inf.py
@@ -162,7 +162,6 @@ class GptTmplInfParser(GPParser):
         # param_list = [[Name, Mode, ACL],]
         def parse(self, line):
             parameters = [None, None, None]
-            index = 0
             current_arg = 0
 
             while line != '':
@@ -324,7 +323,6 @@ class GptTmplInfParser(GPParser):
                 header_name = match.group(1)
                 if header_name in self.sections:
                     current_param_parser = self.sections[header_name]
-                    current_header_name = header_name
                     # print current_param_parser
                     continue
 
-- 
2.11.0


From e329b57ab7c26fb13ba55f07321fac22327ec8b5 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 13:50:06 +1300
Subject: [PATCH 03/10] python/tests/lsa_string: remove duplicate method

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/lsa_string.py | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/python/samba/tests/lsa_string.py b/python/samba/tests/lsa_string.py
index b8519b6b37f..bcc76b5b0ba 100644
--- a/python/samba/tests/lsa_string.py
+++ b/python/samba/tests/lsa_string.py
@@ -38,15 +38,6 @@ class LsaStringTests(TestCase):
         s = lsa.String(CONTENT)
         self.assertEqual(CONTENT, s.string)
 
-        # These should be zero, are set by ndr_pack and ndr_unpack
-        self.assertEqual(0, s.size)
-        self.assertEqual(0, s.length)
-
-    def test_string_constructor(self):
-        CONTENT = "The content string"
-        s = lsa.String(CONTENT)
-        self.assertEqual(CONTENT, s.string)
-
         # These should be zero
         self.assertEqual(0, s.size)
         self.assertEqual(0, s.length)
-- 
2.11.0


From 48be7d73c4aa1d4f64ce333231de303412fccbb5 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 16:15:43 +1300
Subject: [PATCH 04/10] python/tests/kcc_utils: disambiguate/unshadow a test

Pair-programmed-with: Garming Sam <garming at catalyst.net.nz>
Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/kcc/kcc_utils.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/python/samba/tests/kcc/kcc_utils.py b/python/samba/tests/kcc/kcc_utils.py
index d8c084e9652..ac4f2819e3f 100644
--- a/python/samba/tests/kcc/kcc_utils.py
+++ b/python/samba/tests/kcc/kcc_utils.py
@@ -254,7 +254,8 @@ class SiteCoverageTests(samba.tests.TestCase):
 
         self.assertEqual([], to_cover)
 
-    def test_three_site_links_different_costs(self):
+    def test_three_site_links_duplicate_costs(self):
+        # two of the links have the same cost; the other is higher
         self.samdb.transaction_start()
         site1, name1 = self._add_site(self.prefix + "ABCD")
         site2, name2 = self._add_site(self.prefix + "BCDE")
-- 
2.11.0


From 2b54b2de3535014817dee37023f8a4798fd7d18b Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 16:47:44 +1300
Subject: [PATCH 05/10] ldb/tests/py/api: reveal shadowed casefold test

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 lib/ldb/tests/python/api.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index f9e2fa5f73a..0e16004deed 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -2062,7 +2062,7 @@ class DnTests(TestCase):
         x = ldb.Dn(self.ldb, "dc=foo13,bla=blie")
         self.assertEqual(x.__repr__(), "Dn('dc=foo13,bla=blie')")
 
-    def test_get_casefold(self):
+    def test_get_casefold_2(self):
         x = ldb.Dn(self.ldb, "dc=foo14,bar=bloe")
         self.assertEqual(x.get_casefold(), "DC=FOO14,BAR=bloe")
 
-- 
2.11.0


From 5dfb3f98b0e1eb7ed2cd9943ab3674e688a9a5b6 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 17:00:46 +1300
Subject: [PATCH 06/10] s4/dsdb/pytest/ldap_schema: remove duplicate test

The tests differ in two lines, thus:

     def test_subClassOf(self):
     -        """ Testing usage of custom child schamaClass
     +        """ Testing usage of custom child classSchema

[...]

   -governsId: 1.3.6.1.4.1.7165.4.6.2.6.3.""" + str(random.randint(1, 100000)) + """
   +governsId: 1.3.6.1.4.1.7165.4.6.2.6.7.""" + str(random.randint(1, 100000)) + """

with the governsId OID changed because it was noticed they were colliding.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/ldap_schema.py | 58 --------------------------------
 1 file changed, 58 deletions(-)

diff --git a/source4/dsdb/tests/python/ldap_schema.py b/source4/dsdb/tests/python/ldap_schema.py
index d2465f7ae0e..6153852a59f 100755
--- a/source4/dsdb/tests/python/ldap_schema.py
+++ b/source4/dsdb/tests/python/ldap_schema.py
@@ -1265,64 +1265,6 @@ governsId: """ + governsID + """.1
             (enum, estr) = e24.args
             self.assertEquals(enum, ERR_CONSTRAINT_VIOLATION)
 
-    def test_subClassOf(self):
-        """ Testing usage of custom child classSchema
-        """
-
-        class_name = "my-Class" + time.strftime("%s", time.gmtime())
-        class_ldap_display_name = class_name.replace("-", "")
-
-        ldif = """
-dn: CN=%s,%s""" % (class_name, self.schema_dn) + """
-objectClass: top
-objectClass: classSchema
-adminDescription: """ + class_name + """
-adminDisplayName: """ + class_name + """
-cn: """ + class_name + """
-governsId: 1.3.6.1.4.1.7165.4.6.2.6.7.""" + str(random.randint(1, 100000)) + """
-instanceType: 4
-objectClassCategory: 1
-subClassOf: organizationalUnit
-systemFlags: 16
-systemOnly: FALSE
-"""
-        self.ldb.add_ldif(ldif)
-
-        # Search for created objectclass
-        res = []
-        res = self.ldb.search("cn=%s,%s" % (class_name, self.schema_dn), scope=SCOPE_BASE,
-                              attrs=["lDAPDisplayName", "defaultObjectCategory",
-                                     "schemaIDGUID", "distinguishedName"])
-        self.assertEquals(len(res), 1)
-        self.assertEquals(res[0]["lDAPDisplayName"][0], class_ldap_display_name)
-        self.assertEquals(res[0]["defaultObjectCategory"][0], res[0]["distinguishedName"][0])
-        self.assertTrue("schemaIDGUID" in res[0])
-
-        ldif = """
-dn:
-changetype: modify
-add: schemaUpdateNow
-schemaUpdateNow: 1
-"""
-        self.ldb.modify_ldif(ldif)
-
-        object_name = "org" + time.strftime("%s", time.gmtime())
-
-        ldif = """
-dn: OU=%s,%s""" % (object_name, self.base_dn) + """
-objectClass: """ + class_ldap_display_name + """
-ou: """ + object_name + """
-instanceType: 4
-"""
-        self.ldb.add_ldif(ldif)
-
-        # Search for created object
-        res = []
-        res = self.ldb.search("ou=%s,%s" % (object_name, self.base_dn), scope=SCOPE_BASE, attrs=["dn"])
-        self.assertEquals(len(res), 1)
-        # Delete the object
-        delete_force(self.ldb, "ou=%s,%s" % (object_name, self.base_dn))
-
 
 class SchemaTests_msDS_IntId(samba.tests.TestCase):
 
-- 
2.11.0


From ad8d24c7878475e087430c9f07634d1f8921e78e Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 14:42:40 +1300
Subject: [PATCH 07/10] python/tests/raw_protocol: reveal shadowed test via
 disambiguation

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/dcerpc/raw_protocol.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/samba/tests/dcerpc/raw_protocol.py b/python/samba/tests/dcerpc/raw_protocol.py
index 6c4deea3816..dd1fe99fa18 100755
--- a/python/samba/tests/dcerpc/raw_protocol.py
+++ b/python/samba/tests/dcerpc/raw_protocol.py
@@ -4595,7 +4595,7 @@ class TestDCERPC_BIND(RawDCERPCTest):
                                             request_fault=dcerpc.DCERPC_NCA_S_OP_RNG_ERROR,
                                             response_fault_flags=dcerpc.DCERPC_PFC_FLAG_DID_NOT_EXECUTE)
 
-    def test_spnego_packet_bind_sign(self):
+    def test_spnego_packet_bind_sign_privacy(self):
         # DCERPC_AUTH_LEVEL_PACKET is handled as alias of
         # DCERPC_AUTH_LEVEL_INTEGRITY
         return self._test_spnego_level_bind(auth_level=dcerpc.DCERPC_AUTH_LEVEL_PACKET,
-- 
2.11.0


From 11b2ecaa042529144af9b1c7c909dfd4ead70e11 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 25 Oct 2018 11:40:53 +1300
Subject: [PATCH 08/10] samba-tool tests: fix bytes/str issue in masked test

This test will be revealed to the world in the next commit.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/samba_tool/ou.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/samba/tests/samba_tool/ou.py b/python/samba/tests/samba_tool/ou.py
index 47636d7cddb..92986a4aafb 100644
--- a/python/samba/tests/samba_tool/ou.py
+++ b/python/samba/tests/samba_tool/ou.py
@@ -142,7 +142,7 @@ class OUCmdTestCase(SambaToolCmdTest):
 
         for ouobj in oulist:
             name = ouobj.get("name", idx=0)
-            found = self.assertMatch(out, name,
+            found = self.assertMatch(out, str(name),
                                      "ou '%s' not found" % name)
 
     def test_rename(self):
-- 
2.11.0


From be5a7f9034f3edc22f42c7e1bac68b616dc5f633 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Thu, 11 Oct 2018 14:45:58 +1300
Subject: [PATCH 09/10] python/tests/ou: unshadow a test

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/samba_tool/ou.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/samba/tests/samba_tool/ou.py b/python/samba/tests/samba_tool/ou.py
index 92986a4aafb..d318fd3ff85 100644
--- a/python/samba/tests/samba_tool/ou.py
+++ b/python/samba/tests/samba_tool/ou.py
@@ -224,7 +224,7 @@ class OUCmdTestCase(SambaToolCmdTest):
             found = self.assertMatch(out, str(obj.dn),
                                      "object '%s' not found" % obj.dn)
 
-    def test_list(self):
+    def test_list_full_dn(self):
         (result, out, err) = self.runsubcmd("ou", "list",
                                             "--full-dn")
         self.assertCmdSuccess(result, out, err,
-- 
2.11.0


From 65b2862f9b92bc84518404880c12b9b5a1f9bd00 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Fri, 12 Oct 2018 11:52:49 +1300
Subject: [PATCH 10/10] pytests/samba3sam: unshadow and fix a search_non_mapped
 test

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/samba3sam.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/samba/tests/samba3sam.py b/python/samba/tests/samba3sam.py
index 160031c77dd..0ed268a6032 100644
--- a/python/samba/tests/samba3sam.py
+++ b/python/samba/tests/samba3sam.py
@@ -154,9 +154,9 @@ class Samba3SamTestCase(MapBaseTestCase):
         """Looking up by non-mapped attribute"""
         msg = self.ldb.search(expression="(cn=Administrator)")
         self.assertEquals(len(msg), 1)
-        self.assertEquals(msg[0]["cn"], "Administrator")
+        self.assertEquals(str(msg[0]["cn"]), "Administrator")
 
-    def test_search_non_mapped(self):
+    def test_search_mapped(self):
         """Looking up by mapped attribute"""
         msg = self.ldb.search(expression="(name=Backup Operators)")
         self.assertEquals(len(msg), 1)
-- 
2.11.0



More information about the samba-technical mailing list