summaryrefslogtreecommitdiff
path: root/net-dns/avahi/files/avahi-0.7-python3-unittest.patch
blob: 9d735a1780c2b8a4528d128b420b8088e326a052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From 62fe263662b52a462895fd8d21cf29b2fa22fe86 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Fri, 27 Apr 2018 11:10:57 +0100
Subject: [PATCH] avahi-python: Add a unit test for string and bytestring
 conversions

Signed-off-by: Simon McVittie <smcv@debian.org>
---
 .gitignore                     |  1 +
 avahi-python/avahi/.gitignore  |  5 ++
 avahi-python/avahi/Makefile.am |  7 +++
 avahi-python/avahi/test.py     | 85 ++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)
 create mode 100755 avahi-python/avahi/test.py

diff --git a/.gitignore b/.gitignore
index beab8d94..06565f06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ ltmain.sh
 missing
 py-compile
 stamp-h1
+test-driver
diff --git a/avahi-python/avahi/.gitignore b/avahi-python/avahi/.gitignore
index 118a34de..9b0f6e3c 100644
--- a/avahi-python/avahi/.gitignore
+++ b/avahi-python/avahi/.gitignore
@@ -1 +1,6 @@
+*.log
+*.pyc
+*.pyo
+*.trs
 ServiceTypeDatabase.py
+__pycache__/
diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am
index 3eb67d0d..cf527aff 100644
--- a/avahi-python/avahi/Makefile.am
+++ b/avahi-python/avahi/Makefile.am
@@ -16,6 +16,11 @@
 # USA.
 
 EXTRA_DIST = __init__.py ServiceTypeDatabase.py.in
+EXTRA_DIST += test.py
+
+TESTS =
+TEST_EXTENSIONS = .py
+PY_LOG_COMPILER = $(PYTHON)
 
 pkglibdatadir=$(libdir)/avahi
 
@@ -55,6 +60,8 @@ if HAVE_PYTHON_DBUS
 
 avahi_PYTHON += __init__.py
 
+TESTS += test.py
+
 endif
 endif
 
diff --git a/avahi-python/avahi/test.py b/avahi-python/avahi/test.py
new file mode 100755
index 00000000..7afc4809
--- /dev/null
+++ b/avahi-python/avahi/test.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+#
+# Copyright 2018 Simon McVittie
+#
+# This file is part of avahi.
+#
+# avahi is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# avahi is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with avahi; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+import os
+import os.path
+import sys
+import unittest
+from collections import OrderedDict
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
+
+import avahi
+import dbus
+
+class TestUtilityMethods(unittest.TestCase):
+    def test_byte_array_to_string(self):
+        self.assertEqual(
+            avahi.byte_array_to_string([1, 2, 127, 128]),
+            '....')
+        self.assertEqual(
+            avahi.byte_array_to_string([ord('a'), ord(' '), ord('b')]),
+            'a b')
+
+    def test_txt_array_to_string_array(self):
+        self.assertEqual(
+            avahi.txt_array_to_string_array([[1, 2], [ord('a'), ord('b')]]),
+            ['..', 'ab'])
+
+    def test_string_to_byte_array(self):
+        self.assertEqual(
+            avahi.string_to_byte_array('abc'),
+            [dbus.Byte(97), dbus.Byte(98), dbus.Byte(99)])
+        self.assertIsInstance(
+            avahi.string_to_byte_array('abc')[0],
+            dbus.Byte)
+        self.assertEqual(
+            avahi.string_to_byte_array(b'\x01\xff'),
+            [dbus.Byte(0x01), dbus.Byte(0xff)])
+        self.assertEqual(
+            avahi.string_to_byte_array(u'\u00e1'),
+            [dbus.Byte(0xc3), dbus.Byte(0xa1)])
+
+    def test_string_array_to_txt_array(self):
+        self.assertEqual(
+            avahi.string_array_to_txt_array(['abc', b'\x01', u'\u00e1']),
+            [
+                [dbus.Byte(97), dbus.Byte(98), dbus.Byte(99)],
+                [dbus.Byte(0x01)],
+                [dbus.Byte(0xc3), dbus.Byte(0xa1)]])
+        self.assertIsInstance(
+            avahi.string_array_to_txt_array(['abc'])[0][0],
+            dbus.Byte)
+
+    def test_dict_to_txt_array(self):
+        self.assertEqual(
+            avahi.dict_to_txt_array(
+                OrderedDict((('a', 'abc'), ('b', b'\x01'), ('c', u'\u00e1')))),
+            [
+                [dbus.Byte(97), dbus.Byte(ord('=')), dbus.Byte(97), dbus.Byte(98), dbus.Byte(99)],
+                [dbus.Byte(98), dbus.Byte(ord('=')), dbus.Byte(0x01)],
+                [dbus.Byte(99), dbus.Byte(ord('=')), dbus.Byte(0xc3), dbus.Byte(0xa1)]])
+        self.assertIsInstance(
+            avahi.dict_to_txt_array({'a': 'abc'})[0][0],
+            dbus.Byte)
+
+if __name__ == '__main__':
+    unittest.main()