summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2015-06-25 10:28:31 +0200
committerGünther Deschner <gd@samba.org>2015-07-03 02:00:28 +0200
commit7a07f6a7647b63eab560a0e75b46b047f46d1f7e (patch)
tree15461674ca91901c8d3b62d1a1b8ba6bc1186b48 /python
parent2b163012aa243e682c5ba7bb23f1af265783a940 (diff)
downloadsamba-7a07f6a7647b63eab560a0e75b46b047f46d1f7e.tar.gz
python/samba/tests: move hexdump() from DNSTest to TestCase
This is useful in a lot of test cases. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/__init__.py12
-rw-r--r--python/samba/tests/dns.py14
2 files changed, 12 insertions, 14 deletions
diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py
index 3e7094fe067..984b1bf0660 100644
--- a/python/samba/tests/__init__.py
+++ b/python/samba/tests/__init__.py
@@ -35,6 +35,7 @@ except ImportError:
class SkipTest(Exception):
"""Test skipped."""
+HEXDUMP_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
class TestCase(unittest.TestCase):
"""A Samba test case."""
@@ -54,6 +55,17 @@ class TestCase(unittest.TestCase):
def get_credentials(self):
return cmdline_credentials
+ def hexdump(self, src, length=8):
+ N = 0
+ result = ''
+ while src:
+ s, src = src[:length], src[length:]
+ hexa = ' '.join(["%02X" % ord(x) for x in s])
+ s = s.translate(HEXDUMP_FILTER)
+ result += "%04X %-*s %s\n" % (N, length*3, hexa, s)
+ N += length
+ return result
+
# These functions didn't exist before Python2.7:
if sys.version_info < (2, 7):
import warnings
diff --git a/python/samba/tests/dns.py b/python/samba/tests/dns.py
index 92ac876ff35..04ac3567ed7 100644
--- a/python/samba/tests/dns.py
+++ b/python/samba/tests/dns.py
@@ -25,8 +25,6 @@ from samba import credentials, param
from samba.tests import TestCase
from samba.dcerpc import dnsp, dnsserver
-FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
-
class DNSTest(TestCase):
@@ -125,18 +123,6 @@ class DNSTest(TestCase):
if s is not None:
s.close()
- def hexdump(self, src, length=8):
- N = 0
- result = ''
- while src:
- s, src = src[:length], src[length:]
- hexa = ' '.join(["%02X" % ord(x) for x in s])
- s = s.translate(FILTER)
- result += "%04X %-*s %s\n" % (N, length*3, hexa, s)
- N += length
- return result
-
-
class TestSimpleQueries(DNSTest):
def test_one_a_query(self):