From: Noel Power Date: Fri, 9 Mar 2018 13:38:42 +0000 (+0000) Subject: samba python tests: convert print func to be py2/py3 compatible X-Git-Tag: talloc-2.1.13~276 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=708abbf3065120ffa2b3a9bf4b62912951d8bf0e;p=thirdparty%2Fsamba.git samba python tests: convert print func to be py2/py3 compatible Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/tests/auth_log.py b/python/samba/tests/auth_log.py index 6b032a80edc..9e68c4fa38e 100644 --- a/python/samba/tests/auth_log.py +++ b/python/samba/tests/auth_log.py @@ -15,9 +15,9 @@ # along with this program. If not, see . # +from __future__ import print_function """Tests for the Auth and AuthZ logging. """ - from samba import auth import samba.tests from samba.messaging import Messaging @@ -140,7 +140,7 @@ class AuthLogTests(samba.tests.auth_log_base.AuthLogTestBase): msg = messages[2] self.assertEquals("Authorization", msg["type"]) serviceDescription = "SMB" - print "binding %s" % binding + print("binding %s" % binding) if binding == "[smb2]": serviceDescription = "SMB2" diff --git a/python/samba/tests/auth_log_base.py b/python/samba/tests/auth_log_base.py index aefd57e5516..6c1baea9df7 100644 --- a/python/samba/tests/auth_log_base.py +++ b/python/samba/tests/auth_log_base.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Tests for the Auth and AuthZ logging. """ @@ -40,7 +41,7 @@ class AuthLogTestBase(samba.tests.TestCase): def messageHandler( context, msgType, src, message): # This does not look like sub unit output and it # makes these tests much easier to debug. - print message + print(message) jsonMsg = json.loads(message) context["messages"].append( jsonMsg) diff --git a/python/samba/tests/auth_log_pass_change.py b/python/samba/tests/auth_log_pass_change.py index 77758a4430a..9782389b97e 100644 --- a/python/samba/tests/auth_log_pass_change.py +++ b/python/samba/tests/auth_log_pass_change.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Tests for the Auth and AuthZ logging of password changes. """ @@ -50,10 +51,10 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase): credentials=self.get_credentials(), lp=self.get_loadparm()) - print "ldb %s" % type(self.ldb) + print("ldb %s" % type(self.ldb)) # Gets back the basedn base_dn = self.ldb.domain_dn() - print "base_dn %s" % base_dn + print("base_dn %s" % base_dn) # Gets back the configuration basedn configuration_dn = self.ldb.get_config_basedn().get_linearized() @@ -116,7 +117,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase): messages = self.waitForMessages(isLastExpectedMessage) - print "Received %d messages" % len(messages) + print("Received %d messages" % len(messages)) self.assertEquals(8, len(messages), "Did not receive the expected number of messages") @@ -263,7 +264,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase): ) messages = self.waitForMessages(isLastExpectedMessage) - print "Received %d messages" % len(messages) + print("Received %d messages" % len(messages)) self.assertEquals(4, len(messages), "Did not receive the expected number of messages") @@ -295,7 +296,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase): pass messages = self.waitForMessages(isLastExpectedMessage) - print "Received %d messages" % len(messages) + print("Received %d messages" % len(messages)) self.assertEquals(3, len(messages), "Did not receive the expected number of messages") @@ -326,7 +327,7 @@ class AuthLogPassChangeTests(samba.tests.auth_log_base.AuthLogTestBase): pass messages = self.waitForMessages(isLastExpectedMessage) - print "Received %d messages" % len(messages) + print("Received %d messages" % len(messages)) self.assertEquals(4, len(messages), "Did not receive the expected number of messages") diff --git a/python/samba/tests/blackbox/ndrdump.py b/python/samba/tests/blackbox/ndrdump.py index f0cd5f750ec..86f958d63c3 100644 --- a/python/samba/tests/blackbox/ndrdump.py +++ b/python/samba/tests/blackbox/ndrdump.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Blackbox tests for ndrdump.""" import os @@ -25,7 +26,7 @@ from samba.tests import BlackboxTestCase for p in [ "../../../../../source4/librpc/tests", "../../../../../librpc/tests"]: data_path_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), p)) - print data_path_dir + print(data_path_dir) if os.path.exists(data_path_dir): break diff --git a/python/samba/tests/dcerpc/dnsserver.py b/python/samba/tests/dcerpc/dnsserver.py index 349349428cb..93d4478997c 100644 --- a/python/samba/tests/dcerpc/dnsserver.py +++ b/python/samba/tests/dcerpc/dnsserver.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Tests for samba.dcerpc.dnsserver""" import os @@ -337,7 +338,7 @@ class DnsserverTests(RpcInterfaceTestCase): self.assert_num_records(self.custom_zone, "testrecord", record_type_str, expected_num=0) self.delete_record(self.custom_zone, "testrecord", record_type_str, record_str, assertion=False) except AssertionError as e: - print e + print(e) num_failures = num_failures + 1 # Also try to update valid records to invalid ones, making sure this fails @@ -348,7 +349,7 @@ class DnsserverTests(RpcInterfaceTestCase): try: self.add_record(self.custom_zone, "testrecord", record_type_str, record_str, assertion=False) except AssertionError as e: - print e + print(e) num_failures = num_failures + 1 self.delete_record(self.custom_zone, "testrecord", record_type_str, good_record_str) diff --git a/python/samba/tests/dcerpc/testrpc.py b/python/samba/tests/dcerpc/testrpc.py index fc3abf93395..5aadcf48eed 100644 --- a/python/samba/tests/dcerpc/testrpc.py +++ b/python/samba/tests/dcerpc/testrpc.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +from __future__ import print_function import sys sys.path.insert(0, "bin/python") @@ -35,10 +36,10 @@ class RpcTests(object): nblocks -= self.initial_blocks leaked_blocks = (nblocks - num_expected) if leaked_blocks != 0: - print "Leaked %d blocks" % leaked_blocks + print("Leaked %d blocks" % leaked_blocks) def check_type(self, interface, typename, type): - print "Checking type %s" % typename + print("Checking type %s" % typename) v = type() for n in dir(v): if n[0] == '_': @@ -47,43 +48,43 @@ class RpcTests(object): value = getattr(v, n) except TypeError as errstr: if str(errstr) == "unknown union level": - print "ERROR: Unknown union level in %s.%s" % (typename, n) + print("ERROR: Unknown union level in %s.%s" % (typename, n)) self.errcount += 1 continue - print str(errstr)[1:21] + print(str(errstr)[1:21]) if str(errstr)[0:21] == "Can not convert C Type": - print "ERROR: Unknown C type for %s.%s" % (typename, n) + print("ERROR: Unknown C type for %s.%s" % (typename, n)) self.errcount += 1 continue else: - print "ERROR: Failed to instantiate %s.%s" % (typename, n) + print("ERROR: Failed to instantiate %s.%s" % (typename, n)) self.errcount += 1 continue except Exception: - print "ERROR: Failed to instantiate %s.%s" % (typename, n) + print("ERROR: Failed to instantiate %s.%s" % (typename, n)) self.errcount += 1 continue # now try setting the value back try: - print "Setting %s.%s" % (typename, n) + print("Setting %s.%s" % (typename, n)) setattr(v, n, value) except Exception as e: if isinstance(e, AttributeError) and str(e).endswith("is read-only"): # readonly, ignore continue else: - print "ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e) + print("ERROR: Failed to set %s.%s: %r: %s" % (typename, n, e.__class__, e)) self.errcount += 1 continue # and try a comparison try: if value != getattr(v, n): - print "ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n)) + print("ERROR: Comparison failed for %s.%s: %r != %r" % (typename, n, value, getattr(v, n))) continue except Exception as e: - print "ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e) + print("ERROR: compare exception for %s.%s: %r: %s" % (typename, n, e.__class__, e)) continue def check_interface(self, interface, iname): @@ -105,14 +106,14 @@ class RpcTests(object): self.check_type(interface, n, value) self.check_blocks(None, initial_blocks) except Exception as e: - print "ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e) + print("ERROR: Failed to check_type %s.%s: %r: %s" % (iname, n, e.__class__, e)) self.errcount += 1 elif callable(value): pass # Method else: - print "UNKNOWN: %s=%s" % (n, value) + print("UNKNOWN: %s=%s" % (n, value)) if self.errcount - errcount != 0: - print "Found %d errors in %s" % (self.errcount - errcount, iname) + print("Found %d errors in %s" % (self.errcount - errcount, iname)) def check_all_interfaces(self): for iname in dir(samba.dcerpc): @@ -120,7 +121,7 @@ class RpcTests(object): continue if iname == 'ClientConnection' or iname == 'base': continue - print "Checking interface %s" % iname + print("Checking interface %s" % iname) iface = getattr(samba.dcerpc, iname) initial_blocks = talloc.total_blocks(None) self.check_interface(iface, iname) @@ -137,5 +138,5 @@ errcount = tests.run() if errcount == 0: sys.exit(0) else: - print "%d failures" % errcount + print("%d failures" % errcount) sys.exit(1) diff --git a/python/samba/tests/dns.py b/python/samba/tests/dns.py index 8aecfe3be59..4082b5375d1 100644 --- a/python/samba/tests/dns.py +++ b/python/samba/tests/dns.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # +from __future__ import print_function import os import sys import struct @@ -77,7 +78,7 @@ class TestSimpleQueries(DNSTest): name = "%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -95,7 +96,7 @@ class TestSimpleQueries(DNSTest): name = "%s" % (self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_SOA, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -113,7 +114,7 @@ class TestSimpleQueries(DNSTest): name = "%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -131,7 +132,7 @@ class TestSimpleQueries(DNSTest): name = "%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_MX, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -145,7 +146,7 @@ class TestSimpleQueries(DNSTest): name = "invalid-%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_MX, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -185,7 +186,7 @@ class TestSimpleQueries(DNSTest): name = "%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_ALL, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -685,7 +686,7 @@ class TestComplexQueries(DNSTest): # Check the record name = "cname_test.%s" % self.get_dns_domain() q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -825,7 +826,7 @@ class TestInvalidQueries(DNSTest): name = "%s.%s" % (self.server, self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) @@ -845,7 +846,7 @@ class TestInvalidQueries(DNSTest): name = "%s.%s" % ('fakefakefake', self.get_dns_domain()) q = self.make_name_question(name, dns.DNS_QTYPE_A, dns.DNS_QCLASS_IN) - print "asking for ", q.name + print("asking for ", q.name) questions.append(q) self.finish_name_packet(p, questions) diff --git a/python/samba/tests/dns_base.py b/python/samba/tests/dns_base.py index 2a40d999c36..10c7a0a6af5 100644 --- a/python/samba/tests/dns_base.py +++ b/python/samba/tests/dns_base.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # +from __future__ import print_function from samba.tests import TestCaseInTempDir from samba.dcerpc import dns, dnsp from samba import gensec, tests @@ -119,14 +120,14 @@ class DNSTest(TestCaseInTempDir): try: send_packet = ndr.ndr_pack(packet) if dump: - print self.hexdump(send_packet) + print(self.hexdump(send_packet)) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) s.settimeout(timeout) s.connect((host, 53)) s.sendall(send_packet, 0) recv_packet = s.recv(2048, 0) if dump: - print self.hexdump(recv_packet) + print(self.hexdump(recv_packet)) response = ndr.ndr_unpack(dns.name_packet, recv_packet) return (response, recv_packet) finally: @@ -142,7 +143,7 @@ class DNSTest(TestCaseInTempDir): try: send_packet = ndr.ndr_pack(packet) if dump: - print self.hexdump(send_packet) + print(self.hexdump(send_packet)) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) s.settimeout(timeout) s.connect((host, 53)) @@ -152,7 +153,7 @@ class DNSTest(TestCaseInTempDir): recv_packet = s.recv(0xffff + 2, 0) if dump: - print self.hexdump(recv_packet) + print(self.hexdump(recv_packet)) response = ndr.ndr_unpack(dns.name_packet, recv_packet[2:]) finally: diff --git a/python/samba/tests/dns_forwarder.py b/python/samba/tests/dns_forwarder.py index cf9f537e461..028c308239f 100644 --- a/python/samba/tests/dns_forwarder.py +++ b/python/samba/tests/dns_forwarder.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # +from __future__ import print_function import os import sys import struct @@ -123,14 +124,14 @@ class DNSTest(TestCase): try: send_packet = ndr.ndr_pack(packet) if dump: - print self.hexdump(send_packet) + print(self.hexdump(send_packet)) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) s.settimeout(timeout) s.connect((host, 53)) s.send(send_packet, 0) recv_packet = s.recv(2048, 0) if dump: - print self.hexdump(recv_packet) + print(self.hexdump(recv_packet)) return ndr.ndr_unpack(dns.name_packet, recv_packet) finally: if s is not None: @@ -358,7 +359,7 @@ class TestDnsForwarding(DNSTest): def test_double_forwarder_first_frozen(self): if len(dns_servers) < 2: - print "Ignoring test_double_forwarder_first_frozen" + print("Ignoring test_double_forwarder_first_frozen") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') @@ -388,7 +389,7 @@ class TestDnsForwarding(DNSTest): def test_double_forwarder_first_down(self): if len(dns_servers) < 2: - print "Ignoring test_double_forwarder_first_down" + print("Ignoring test_double_forwarder_first_down") return s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') ad = contact_real_server(server_ip, 53) @@ -416,7 +417,7 @@ class TestDnsForwarding(DNSTest): def test_double_forwarder_both_slow(self): if len(dns_servers) < 2: - print "Ignoring test_double_forwarder_both_slow" + print("Ignoring test_double_forwarder_both_slow") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') @@ -502,7 +503,7 @@ class TestDnsForwarding(DNSTest): def test_cname_forwarding_with_slow_server(self): if len(dns_servers) < 2: - print "Ignoring test_cname_forwarding_with_slow_server" + print("Ignoring test_cname_forwarding_with_slow_server") return s1 = self.start_toy_server(dns_servers[0], 53, 'forwarder1') s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') @@ -535,7 +536,7 @@ class TestDnsForwarding(DNSTest): def test_cname_forwarding_with_server_down(self): if len(dns_servers) < 2: - print "Ignoring test_cname_forwarding_with_server_down" + print("Ignoring test_cname_forwarding_with_server_down") return s2 = self.start_toy_server(dns_servers[1], 53, 'forwarder2') diff --git a/python/samba/tests/dns_forwarder_helpers/server.py b/python/samba/tests/dns_forwarder_helpers/server.py index e302485ea1b..7bd27e53b50 100644 --- a/python/samba/tests/dns_forwarder_helpers/server.py +++ b/python/samba/tests/dns_forwarder_helpers/server.py @@ -17,6 +17,7 @@ # along with this program. If not, see . # # Based on the EchoServer example from python docs +from __future__ import print_function import SocketServer import time import sys @@ -31,7 +32,7 @@ VERBOSE = False def debug(msg): if VERBOSE: sys.stdout.flush() - print "\033[00;36m%s\033[00m" % msg + print("\033[00;36m%s\033[00m" % msg) sys.stdout.flush() timeout = 0 diff --git a/python/samba/tests/samba3sam.py b/python/samba/tests/samba3sam.py index bfc7932689f..2fb4f13cfa6 100644 --- a/python/samba/tests/samba3sam.py +++ b/python/samba/tests/samba3sam.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Tests for the samba3sam LDB module, which maps Samba3 LDAP to AD LDAP.""" import os @@ -41,7 +42,7 @@ def read_datafile(filename): return open(os.path.join(datadir, filename), 'r').read() def ldb_debug(l, text): - print text + print(text) class MapBaseTestCase(TestCaseInTempDir):