Skip to content

Commit 2e858c3

Browse files
committed
Fix tests that are expecting string instead of bytes in Python3
1 parent f1c1404 commit 2e858c3

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

Test/test_commands.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,70 @@ def testXMLEscape(self):
1313
# Basic comment
1414
cmd = Comment("Hello")
1515
print(cmd)
16-
self.assertEqual(ET.tostring(cmd.genXML()), "<comment><text>Hello</text></comment>")
16+
self.assertEqual(ET.tostring(cmd.genXML()), b"<comment><text>Hello</text></comment>")
1717

1818
# Check proper escape of "less than"
1919
cmd = Comment("Check for current < 10")
2020
print(cmd)
21-
self.assertEqual(ET.tostring(cmd.genXML()), "<comment><text>Check for current &lt; 10</text></comment>")
21+
self.assertEqual(ET.tostring(cmd.genXML()), b"<comment><text>Check for current &lt; 10</text></comment>")
2222

2323
def testDelayCommand(self):
2424
# Basic set
2525
cmd = Delay(47.11)
2626
print(cmd)
2727
self.assertEqual(str(cmd), "Delay(47.11)")
28-
self.assertEqual(ET.tostring(cmd.genXML()), "<delay><seconds>47.11</seconds></delay>")
28+
self.assertEqual(ET.tostring(cmd.genXML()), b"<delay><seconds>47.11</seconds></delay>")
2929

3030
def testConfig(self):
3131
# Basic set
3232
cmd = ConfigLog(True)
3333
print(cmd)
3434
self.assertEqual(str(cmd), "ConfigLog(True)")
35-
self.assertEqual(ET.tostring(cmd.genXML()), "<config_log><automatic>true</automatic></config_log>")
35+
self.assertEqual(ET.tostring(cmd.genXML()), b"<config_log><automatic>true</automatic></config_log>")
3636

3737
def testSetCommand(self):
3838
# Basic set
3939
cmd = Set("some_device", 3.14)
4040
print(cmd)
4141
self.assertEqual(str(cmd), "Set('some_device', 3.14)")
42-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>3.14</value><wait>false</wait></set>")
42+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>3.14</value><wait>false</wait></set>")
4343

4444
# Handle numeric as well as string for value
4545
cmd = Set("some_device", "Text")
4646
print(cmd)
4747
self.assertEqual(str(cmd), "Set('some_device', 'Text')")
48-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>\"Text\"</value><wait>false</wait></set>")
48+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>\"Text\"</value><wait>false</wait></set>")
4949

5050
# With completion
5151
cmd = Set("some_device", 3.14, completion=True)
5252
print(cmd)
53-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>false</wait></set>")
53+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>false</wait></set>")
5454

5555
# .. and timeout
5656
cmd = Set("some_device", 3.14, completion=True, timeout=5.0)
5757
print(cmd)
58-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>false</wait><timeout>5.0</timeout></set>")
58+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>false</wait><timeout>5.0</timeout></set>")
5959

6060
# Setting a readback PV (the default one) enables wait-on-readback
6161
cmd = Set("some_device", 3.14, completion=True, readback=True, tolerance=1, timeout=10.0)
6262
print(cmd)
63-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>true</wait><readback>some_device</readback><tolerance>1</tolerance><timeout>10.0</timeout></set>")
63+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>true</wait><readback>some_device</readback><tolerance>1</tolerance><timeout>10.0</timeout></set>")
6464

6565
# Setting a readback PV (a specific one) enables wait-on-readback
6666
cmd = Set("some_device", 3.14, completion=True, readback="some_device.RBV", tolerance=1, timeout=10.0)
6767
print(cmd)
68-
self.assertEqual(ET.tostring(cmd.genXML()), "<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>true</wait><readback>some_device.RBV</readback><tolerance>1</tolerance><timeout>10.0</timeout></set>")
68+
self.assertEqual(ET.tostring(cmd.genXML()), b"<set><device>some_device</device><value>3.14</value><completion>true</completion><wait>true</wait><readback>some_device.RBV</readback><tolerance>1</tolerance><timeout>10.0</timeout></set>")
6969

7070
def testSequence(self):
7171
# Nothing
7272
cmd = Sequence()
7373
print(cmd)
74-
self.assertEqual(ET.tostring(cmd.genXML()), "<sequence />")
74+
self.assertEqual(ET.tostring(cmd.genXML()), b"<sequence />")
7575

7676
# A few
7777
cmd = Sequence(Comment("One"), Comment("Two"))
7878
print(cmd.format())
79-
self.assertEqual(ET.tostring(cmd.genXML()), "<sequence><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></sequence>")
79+
self.assertEqual(ET.tostring(cmd.genXML()), b"<sequence><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></sequence>")
8080

8181
# Sequences are 'flattened'
8282
s1 = Sequence(Comment("One"), Comment("Two"))
@@ -93,113 +93,113 @@ def testParallel(self):
9393
# Nothing
9494
cmd = Parallel()
9595
print(cmd)
96-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel />")
96+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel />")
9797

9898
# A few
9999
cmd = Parallel(Comment("One"), Comment("Two"))
100100
print(cmd)
101-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
101+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
102102

103103
# .. as list
104104
cmds = Comment("One"), Comment("Two")
105105
cmd = Parallel(cmds)
106106
print(cmd)
107-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
107+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
108108

109109
cmd = Parallel(body=cmds)
110110
print(cmd)
111-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
111+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
112112

113113
# With other parameters
114114
cmd = Parallel(cmds, timeout=10)
115115
print(cmd)
116-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><timeout>10</timeout><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
116+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><timeout>10</timeout><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
117117

118118
cmd = Parallel(cmds, errhandler="MyHandler")
119119
print(cmd)
120-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body><error_handler>MyHandler</error_handler></parallel>")
120+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body><error_handler>MyHandler</error_handler></parallel>")
121121

122122
cmd = Parallel()
123123
cmd.append(Comment("One"), Comment("Two"))
124124
print(cmd)
125-
self.assertEqual(ET.tostring(cmd.genXML()), "<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
125+
self.assertEqual(ET.tostring(cmd.genXML()), b"<parallel><body><comment><text>One</text></comment><comment><text>Two</text></comment></body></parallel>")
126126

127127
def testLog(self):
128128
# One device
129129
cmd = Log("pv1")
130130
print(cmd)
131-
self.assertEqual(ET.tostring(cmd.genXML()), "<log><devices><device>pv1</device></devices></log>")
131+
self.assertEqual(ET.tostring(cmd.genXML()), b"<log><devices><device>pv1</device></devices></log>")
132132

133133
# Nothing
134134
cmd = Log()
135135
print(cmd)
136-
self.assertEqual(ET.tostring(cmd.genXML()), "<log />")
136+
self.assertEqual(ET.tostring(cmd.genXML()), b"<log />")
137137

138138
# Several
139139
cmd = Log("pv1", "pv2", "pv3")
140140
print(cmd)
141-
self.assertEqual(ET.tostring(cmd.genXML()), "<log><devices><device>pv1</device><device>pv2</device><device>pv3</device></devices></log>")
141+
self.assertEqual(ET.tostring(cmd.genXML()), b"<log><devices><device>pv1</device><device>pv2</device><device>pv3</device></devices></log>")
142142

143143
# .. provided as list
144144
devices_to_log = [ "pv1", "pv2", "pv3" ]
145145
cmd = Log(devices_to_log)
146146
print(cmd)
147-
self.assertEqual(ET.tostring(cmd.genXML()), "<log><devices><device>pv1</device><device>pv2</device><device>pv3</device></devices></log>")
147+
self.assertEqual(ET.tostring(cmd.genXML()), b"<log><devices><device>pv1</device><device>pv2</device><device>pv3</device></devices></log>")
148148

149149
def testInclude(self):
150150
cmd = Include("start.scn")
151151
print(cmd)
152-
self.assertEqual(ET.tostring(cmd.genXML()), "<include><scan_file>start.scn</scan_file></include>")
152+
self.assertEqual(ET.tostring(cmd.genXML()), b"<include><scan_file>start.scn</scan_file></include>")
153153

154154
cmd = Include("start.scn", "macro=value")
155155
print(cmd)
156-
self.assertEqual(ET.tostring(cmd.genXML()), "<include><scan_file>start.scn</scan_file><macros>macro=value</macros></include>")
156+
self.assertEqual(ET.tostring(cmd.genXML()), b"<include><scan_file>start.scn</scan_file><macros>macro=value</macros></include>")
157157

158158
def testScript(self):
159159
cmd = Script("MyCustomScript")
160160
print(cmd)
161161
self.assertEqual(str(cmd), "Script('MyCustomScript')")
162-
self.assertEqual(ET.tostring(cmd.genXML()), "<script><path>MyCustomScript</path></script>")
162+
self.assertEqual(ET.tostring(cmd.genXML()), b"<script><path>MyCustomScript</path></script>")
163163

164164
cmd = Script("MyCustomCommand", "arg1", 42.3)
165165
print(cmd)
166166
self.assertEqual(str(cmd), "Script('MyCustomCommand', 'arg1', 42.3)")
167-
self.assertEqual(ET.tostring(cmd.genXML()), "<script><path>MyCustomCommand</path><arguments><argument>arg1</argument><argument>42.3</argument></arguments></script>")
167+
self.assertEqual(ET.tostring(cmd.genXML()), b"<script><path>MyCustomCommand</path><arguments><argument>arg1</argument><argument>42.3</argument></arguments></script>")
168168

169169
# Arguments already provided as list
170170
cmd = Script("MyCustomCommand", [ "arg1", 42.3 ])
171171
print(cmd)
172172
self.assertEqual(str(cmd), "Script('MyCustomCommand', 'arg1', 42.3)")
173-
self.assertEqual(ET.tostring(cmd.genXML()), "<script><path>MyCustomCommand</path><arguments><argument>arg1</argument><argument>42.3</argument></arguments></script>")
173+
self.assertEqual(ET.tostring(cmd.genXML()), b"<script><path>MyCustomCommand</path><arguments><argument>arg1</argument><argument>42.3</argument></arguments></script>")
174174

175175
def testWait(self):
176176
cmd = Wait('device', 3.14)
177177
print(cmd)
178178
self.assertEqual(str(cmd), "Wait('device', 3.14)")
179-
self.assertEqual(ET.tostring(cmd.genXML()), "<wait><device>device</device><value>3.14</value><comparison>EQUALS</comparison></wait>")
179+
self.assertEqual(ET.tostring(cmd.genXML()), b"<wait><device>device</device><value>3.14</value><comparison>EQUALS</comparison></wait>")
180180

181181
cmd = Wait('counts', 1000, comparison='increase by', timeout=5.0, errhandler='someHandler')
182182
print(cmd)
183183
self.assertEqual(str(cmd), "Wait('counts', 1000, comparison='increase by', timeout=5, errhandler='someHandler')")
184-
self.assertEqual(ET.tostring(cmd.genXML()), "<wait><device>counts</device><value>1000</value><comparison>INCREASE_BY</comparison><timeout>5.0</timeout><error_handler>someHandler</error_handler></wait>")
184+
self.assertEqual(ET.tostring(cmd.genXML()), b"<wait><device>counts</device><value>1000</value><comparison>INCREASE_BY</comparison><timeout>5.0</timeout><error_handler>someHandler</error_handler></wait>")
185185

186186
def testIf(self):
187187
cmd = If('device', '>', 3.14)
188188
print(cmd)
189189
self.assertEqual(str(cmd), "If('device', '>', 3.14, tolerance=0.1)")
190-
self.assertEqual(ET.tostring(cmd.genXML()), "<if><device>device</device><comparison>ABOVE</comparison><value>3.14</value><tolerance>0.1</tolerance><body /></if>")
190+
self.assertEqual(ET.tostring(cmd.genXML()), b"<if><device>device</device><comparison>ABOVE</comparison><value>3.14</value><tolerance>0.1</tolerance><body /></if>")
191191

192192
cmd = If('device', '>', 3.14, [ Comment('BODY') ])
193193
print(cmd)
194194
self.assertEqual(str(cmd), "If('device', '>', 3.14, [ Comment('BODY') ], tolerance=0.1)")
195-
self.assertEqual(ET.tostring(cmd.genXML()), "<if><device>device</device><comparison>ABOVE</comparison><value>3.14</value><tolerance>0.1</tolerance><body><comment><text>BODY</text></comment></body></if>")
195+
self.assertEqual(ET.tostring(cmd.genXML()), b"<if><device>device</device><comparison>ABOVE</comparison><value>3.14</value><tolerance>0.1</tolerance><body><comment><text>BODY</text></comment></body></if>")
196196

197197

198198
def testLoop(self):
199199
cmd = Loop('pv1', 1, 10, 0.1)
200200
print(cmd)
201201
self.assertEqual(str(cmd), "Loop('pv1', 1, 10, 0.1)")
202-
self.assertEqual(ET.tostring(cmd.genXML()), "<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>false</wait><body /></loop>")
202+
self.assertEqual(ET.tostring(cmd.genXML()), b"<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>false</wait><body /></loop>")
203203

204204
cmd = Loop('pv1', 1, 10, 0.1, Delay(5))
205205
print(cmd)
@@ -210,16 +210,16 @@ def testLoop(self):
210210
cmd = Loop('pv1', 1, 10, 0.1, body= [ Delay(1), Delay(2) ])
211211
print(cmd)
212212
self.assertEqual(str(cmd), "Loop('pv1', 1, 10, 0.1, [ Delay(1), Delay(2) ])")
213-
self.assertEqual(ET.tostring(cmd.genXML()), "<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>false</wait><body><delay><seconds>1</seconds></delay><delay><seconds>2</seconds></delay></body></loop>")
213+
self.assertEqual(ET.tostring(cmd.genXML()), b"<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>false</wait><body><delay><seconds>1</seconds></delay><delay><seconds>2</seconds></delay></body></loop>")
214214

215215
cmd = Loop('pv1', 1, 10, 0.1, Delay(1), Delay(2), readback=True)
216216
print(cmd)
217-
self.assertEqual(ET.tostring(cmd.genXML()), "<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>true</wait><readback>pv1</readback><tolerance>0.01</tolerance><body><delay><seconds>1</seconds></delay><delay><seconds>2</seconds></delay></body></loop>")
217+
self.assertEqual(ET.tostring(cmd.genXML()), b"<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><wait>true</wait><readback>pv1</readback><tolerance>0.01</tolerance><body><delay><seconds>1</seconds></delay><delay><seconds>2</seconds></delay></body></loop>")
218218

219219
cmd = Loop('pv1', 1, 10, 0.1, completion=True, timeout=10)
220220
print(cmd)
221221
self.assertEqual(str(cmd), "Loop('pv1', 1, 10, 0.1, completion=True, timeout=10)")
222-
self.assertEqual(ET.tostring(cmd.genXML()), "<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><completion>true</completion><wait>false</wait><timeout>10</timeout><body /></loop>")
222+
self.assertEqual(ET.tostring(cmd.genXML()), b"<loop><device>pv1</device><start>1</start><end>10</end><step>0.1</step><completion>true</completion><wait>false</wait><timeout>10</timeout><body /></loop>")
223223

224224

225225
def testXMLSequence(self):
@@ -238,8 +238,8 @@ def testXMLSequence(self):
238238
print(cmds)
239239
self.assertEqual(len(cmds), 2)
240240
print(cmds.genSCN())
241-
self.assertEqual("""<commands><comment><text>One</text></comment><comment><text>Two</text></comment></commands>""",
242-
cmds.genSCN().replace("\n", "").replace(" ", ""))
241+
self.assertEqual(b"<commands><comment><text>One</text></comment><comment><text>Two</text></comment></commands>",
242+
cmds.genSCN().replace(b"\n", b"").replace(b" ", b""))
243243

244244

245245
cmds = CommandSequence(Comment('One'))

0 commit comments

Comments
 (0)