From 4144d60017e200d97bcfe0286daee06d4641a9e0 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Mon, 18 Aug 2014 00:52:24 +0200 Subject: cleanup semicolons, whitespace and mutable default arguments --- tests/test_stanza_element.py | 4 +- tests/test_stanza_xep_0323.py | 135 +++++++------- tests/test_stanza_xep_0325.py | 80 ++++---- tests/test_stream_xep_0323.py | 424 +++++++++++++++++++++--------------------- tests/test_stream_xep_0325.py | 110 +++++------ 5 files changed, 374 insertions(+), 379 deletions(-) (limited to 'tests') diff --git a/tests/test_stanza_element.py b/tests/test_stanza_element.py index 2b9676cf..e678b56e 100644 --- a/tests/test_stanza_element.py +++ b/tests/test_stanza_element.py @@ -385,7 +385,7 @@ class TestElementBase(SleekTest): interfaces = set(('bar', 'baz')) def setBar(self, value): - self._set_sub_text("path/to/only/bar", value); + self._set_sub_text("path/to/only/bar", value) def getBar(self): return self._get_sub_text("path/to/only/bar") @@ -394,7 +394,7 @@ class TestElementBase(SleekTest): self._del_sub("path/to/only/bar") def setBaz(self, value): - self._set_sub_text("path/to/just/baz", value); + self._set_sub_text("path/to/just/baz", value) def getBaz(self): return self._get_sub_text("path/to/just/baz") diff --git a/tests/test_stanza_xep_0323.py b/tests/test_stanza_xep_0323.py index 67e0daf0..7b1dfe42 100644 --- a/tests/test_stanza_xep_0323.py +++ b/tests/test_stanza_xep_0323.py @@ -6,7 +6,7 @@ import sleekxmpp.plugins.xep_0323 as xep_0323 namespace='sn' class TestSensorDataStanzas(SleekTest): - + def setUp(self): pass @@ -59,8 +59,8 @@ class TestSensorDataStanzas(SleekTest): iq['req']['momentary'] = 'true' - iq['req'].add_node("Device02", "Source02", "CacheType"); - iq['req'].add_node("Device44"); + iq['req'].add_node("Device02", "Source02", "CacheType") + iq['req'].add_node("Device44") self.check(iq,""" @@ -193,7 +193,7 @@ class TestSensorDataStanzas(SleekTest): iq['rejected']['error'] = 'Access denied.' self.check(iq,""" - @@ -237,12 +237,12 @@ class TestSensorDataStanzas(SleekTest): msg['to'] = 'master@clayster.com/amr' msg['fields']['seqnr'] = '1' - node = msg['fields'].add_node("Device02"); - ts = node.add_timestamp("2013-03-07T16:24:30"); + node = msg['fields'].add_node("Device02") + ts = node.add_timestamp("2013-03-07T16:24:30") - data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K'); - data['momentary'] = 'true'; - data['automaticReadout'] = 'true'; + data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K') + data['momentary'] = 'true' + data['automaticReadout'] = 'true' self.check(msg,""" - + @@ -258,10 +258,9 @@ class TestSensorDataStanzas(SleekTest): """ ) - node = msg['fields'].add_node("EmptyDevice"); - node = msg['fields'].add_node("Device04"); - ts = node.add_timestamp("EmptyTimestamp"); - + node = msg['fields'].add_node("EmptyDevice") + node = msg['fields'].add_node("Device04") + ts = node.add_timestamp("EmptyTimestamp") self.check(msg,""" - + @@ -281,32 +280,32 @@ class TestSensorDataStanzas(SleekTest): """ ) - node = msg['fields'].add_node("Device77"); - ts = node.add_timestamp("2013-05-03T12:00:01"); - data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K'); - data['historicalDay'] = 'true'; - data = ts.add_data(typename="numeric", name="Speed", value="312.42", unit='km/h'); - data['historicalWeek'] = 'false'; - data = ts.add_data(typename="string", name="Temperature name", value="Bottom oil"); - data['historicalMonth'] = 'true'; - data = ts.add_data(typename="string", name="Speed name", value="Top speed"); - data['historicalQuarter'] = 'false'; - data = ts.add_data(typename="dateTime", name="T1", value="1979-01-01T00:00:00"); - data['historicalYear'] = 'true'; - data = ts.add_data(typename="dateTime", name="T2", value="2000-01-01T01:02:03"); - data['historicalOther'] = 'false'; - data = ts.add_data(typename="timeSpan", name="TS1", value="P5Y"); - data['missing'] = 'true'; - data = ts.add_data(typename="timeSpan", name="TS2", value="PT2M1S"); - data['manualEstimate'] = 'false'; - data = ts.add_data(typename="enum", name="top color", value="red", dataType="string"); - data['invoiced'] = 'true'; - data = ts.add_data(typename="enum", name="bottom color", value="black", dataType="string"); - data['powerFailure'] = 'false'; - data = ts.add_data(typename="boolean", name="Temperature real", value="false"); - data['historicalDay'] = 'true'; - data = ts.add_data(typename="boolean", name="Speed real", value="true"); - data['historicalWeek'] = 'false'; + node = msg['fields'].add_node("Device77") + ts = node.add_timestamp("2013-05-03T12:00:01") + data = ts.add_data(typename="numeric", name="Temperature", value="-12.42", unit='K') + data['historicalDay'] = 'true' + data = ts.add_data(typename="numeric", name="Speed", value="312.42", unit='km/h') + data['historicalWeek'] = 'false' + data = ts.add_data(typename="string", name="Temperature name", value="Bottom oil") + data['historicalMonth'] = 'true' + data = ts.add_data(typename="string", name="Speed name", value="Top speed") + data['historicalQuarter'] = 'false' + data = ts.add_data(typename="dateTime", name="T1", value="1979-01-01T00:00:00") + data['historicalYear'] = 'true' + data = ts.add_data(typename="dateTime", name="T2", value="2000-01-01T01:02:03") + data['historicalOther'] = 'false' + data = ts.add_data(typename="timeSpan", name="TS1", value="P5Y") + data['missing'] = 'true' + data = ts.add_data(typename="timeSpan", name="TS2", value="PT2M1S") + data['manualEstimate'] = 'false' + data = ts.add_data(typename="enum", name="top color", value="red", dataType="string") + data['invoiced'] = 'true' + data = ts.add_data(typename="enum", name="bottom color", value="black", dataType="string") + data['powerFailure'] = 'false' + data = ts.add_data(typename="boolean", name="Temperature real", value="false") + data['historicalDay'] = 'true' + data = ts.add_data(typename="boolean", name="Speed real", value="true") + data['historicalWeek'] = 'false' self.check(msg,""" - + @@ -323,18 +322,18 @@ class TestSensorDataStanzas(SleekTest): - - - - - - - - - - - - + + + + + + + + + + + + @@ -342,21 +341,19 @@ class TestSensorDataStanzas(SleekTest): """ ) - + def testTimestamp(self): - msg = self.Message(); + msg = self.Message() msg['from'] = 'device@clayster.com' msg['to'] = 'master@clayster.com/amr' msg['fields']['seqnr'] = '1' - node = msg['fields'].add_node("Device02"); - node = msg['fields'].add_node("Device03"); - - ts = node.add_timestamp("2013-03-07T16:24:30"); - ts = node.add_timestamp("2013-03-07T16:24:31"); - + node = msg['fields'].add_node("Device02") + node = msg['fields'].add_node("Device03") + ts = node.add_timestamp("2013-03-07T16:24:30") + ts = node.add_timestamp("2013-03-07T16:24:31") self.check(msg,""" @@ -111,7 +111,7 @@ class TestControlStanzas(SleekTest): iq['from'] = 'master@clayster.com/amr' iq['to'] = 'device@clayster.com' iq['id'] = '8' - iq['setResponse']['responseCode'] = "OK"; + iq['setResponse']['responseCode'] = "OK" self.check(iq,""" """ ) - + suite = unittest.TestLoader().loadTestsFromTestCase(TestControlStanzas) diff --git a/tests/test_stream_xep_0323.py b/tests/test_stream_xep_0323.py index fd2ad225..94f1d638 100644 --- a/tests/test_stream_xep_0323.py +++ b/tests/test_stream_xep_0323.py @@ -19,7 +19,7 @@ class TestStreamSensorData(SleekTest): pass def _time_now(self): - return datetime.datetime.now().replace(microsecond=0).isoformat(); + return datetime.datetime.now().replace(microsecond=0).isoformat() def tearDown(self): self.stream_close() @@ -29,12 +29,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device22"); - myDevice._add_field(name="Temperature", typename="numeric", unit="°C"); + myDevice = Device("Device22") + myDevice._add_field(name="Temperature", typename="numeric", unit="°C") myDevice._set_momentary_timestamp("2013-03-07T16:24:30") - myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}); + myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}) - self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.recv(""" @@ -60,11 +60,11 @@ class TestStreamSensorData(SleekTest): - + - + """) def testRequestRejectAuth(self): @@ -73,7 +73,7 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - self.xmpp['xep_0323']._set_authenticated("darth@deathstar.com"); + self.xmpp['xep_0323']._set_authenticated("darth@deathstar.com") self.recv(""" @@ -101,8 +101,8 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + myDevice = Device("Device44") + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -118,7 +118,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -142,7 +142,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -157,11 +157,11 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -177,7 +177,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -201,7 +201,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -215,11 +215,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -227,7 +227,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testRequestMultiTimestampSingleField(self): @@ -236,15 +236,15 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field(name='Current', typename="numeric", unit="A"); - myDevice._add_field(name='Height', typename="string"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02"); - myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field(name='Current', typename="numeric", unit="A") + myDevice._add_field(name='Height', typename="string") + myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02") + myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -260,7 +260,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -274,11 +274,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -287,11 +287,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -299,7 +299,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testRequestMultiTimestampAllFields(self): @@ -308,15 +308,15 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field(name='Current', typename="numeric", unit="A"); - myDevice._add_field(name='Height', typename="string"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02"); - myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.4", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field(name='Current', typename="numeric", unit="A") + myDevice._add_field(name='Height', typename="string") + myDevice._add_field_timestamp_data(name="Voltage", value="230.6", timestamp="2000-01-01T01:01:02") + myDevice._add_field_timestamp_data(name="Height", value="115 m", timestamp="2000-01-01T01:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -330,7 +330,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -344,11 +344,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -357,12 +357,12 @@ class TestStreamSensorData(SleekTest): - - + + - + """) self.send(""" @@ -370,7 +370,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testRequestAPI(self): @@ -379,7 +379,7 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", callback=None); + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", callback=None) self.send(""" """) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=None); + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=None) self.send(""" """) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", fields=['Temperature', 'Voltage'], callback=None); + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", fields=['Temperature', 'Voltage'], callback=None) self.send(""" Invalid device Device22 - + """) time.sleep(.1) - self.failUnless(results == ["rejected"], - "Rejected callback was not properly executed"); + self.failUnless(results == ["rejected"], + "Rejected callback was not properly executed") def testRequestAcceptedAPI(self): @@ -466,12 +466,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = []; + results = [] def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result); + results.append(result) - self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback); + self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33', 'Device22'], callback=my_callback) self.send(""" - + """) time.sleep(.1) - self.failUnless(results == ["accepted"], - "Accepted callback was not properly executed"); + self.failUnless(results == ["accepted"], + "Accepted callback was not properly executed") def testRequestFieldsAPI(self): @@ -505,25 +505,25 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = []; - callback_data = {}; + results = [] + callback_data = {} def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result); + results.append(result) if result == "fields": - callback_data["nodeId"] = nodeId; - callback_data["timestamp"] = timestamp; - callback_data["error_msg"] = error_msg; + callback_data["nodeId"] = nodeId + callback_data["timestamp"] = timestamp + callback_data["error_msg"] = error_msg for f in fields: - callback_data["field_" + f['name']] = f; + callback_data["field_" + f['name']] = f t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}); - t1.start(); + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}) + t1.start() #self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); self.send(""" @@ -538,12 +538,12 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - - + """) self.recv(""" @@ -552,42 +552,42 @@ class TestStreamSensorData(SleekTest): - - + + - + """) self.recv(""" - + """) - t1.join(); + t1.join() time.sleep(.5) - self.failUnlessEqual(results, ["accepted","fields","done"]); + self.failUnlessEqual(results, ["accepted","fields","done"]) # self.assertIn("nodeId", callback_data); self.assertTrue("nodeId" in callback_data) - self.failUnlessEqual(callback_data["nodeId"], "Device33"); + self.failUnlessEqual(callback_data["nodeId"], "Device33") # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data); - self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); + self.assertTrue("timestamp" in callback_data) + self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02") #self.assertIn("field_Voltage", callback_data); - self.assertTrue("field_Voltage" in callback_data); - self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); + self.assertTrue("field_Voltage" in callback_data) + self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}) #self.assertIn("field_TestBool", callback_data); - self.assertTrue("field_TestBool" in callback_data); - self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); + self.assertTrue("field_TestBool" in callback_data) + self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }) def testServiceDiscoveryClient(self): self.stream_start(mode='client', plugins=['xep_0030', - 'xep_0323']); + 'xep_0323']) self.recv(""" - - + + """) def testServiceDiscoveryComponent(self): self.stream_start(mode='component', plugins=['xep_0030', - 'xep_0323']); + 'xep_0323']) self.recv(""" - - + + """) def testRequestTimeout(self): @@ -641,23 +641,23 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = []; - callback_data = {}; + results = [] + callback_data = {} def my_callback(from_jid, result, nodeId=None, timestamp=None, error_msg=None): - results.append(result); + results.append(result) if result == "failure": - callback_data["nodeId"] = nodeId; - callback_data["timestamp"] = timestamp; - callback_data["error_msg"] = error_msg; + callback_data["nodeId"] = nodeId + callback_data["timestamp"] = timestamp + callback_data["error_msg"] = error_msg t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}); - t1.start(); + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}) + t1.start() self.send(""" - + """) self.recv(""" @@ -688,31 +688,31 @@ class TestStreamSensorData(SleekTest): """) - t1.join(); + t1.join() time.sleep(.5) - self.failUnlessEqual(results, ["accepted","failure"]); + self.failUnlessEqual(results, ["accepted","failure"]) # self.assertIn("nodeId", callback_data); - self.assertTrue("nodeId" in callback_data); - self.failUnlessEqual(callback_data["nodeId"], "Device33"); + self.assertTrue("nodeId" in callback_data) + self.failUnlessEqual(callback_data["nodeId"], "Device33") # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data); - self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30"); + self.assertTrue("timestamp" in callback_data) + self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30") # self.assertIn("error_msg", callback_data); - self.assertTrue("error_msg" in callback_data); - self.failUnlessEqual(callback_data["error_msg"], "Timeout."); + self.assertTrue("error_msg" in callback_data) + self.failUnlessEqual(callback_data["error_msg"], "Timeout.") def testDelayedRequest(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device22"); - myDevice._add_field(name="Temperature", typename="numeric", unit="°C"); + myDevice = Device("Device22") + myDevice._add_field(name="Temperature", typename="numeric", unit="°C") myDevice._set_momentary_timestamp("2013-03-07T16:24:30") - myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}); + myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}) - self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) dtnow = datetime.datetime.now() ts_2sec = datetime.timedelta(0,2) @@ -729,7 +729,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -743,7 +743,7 @@ class TestStreamSensorData(SleekTest): - + """) self.send(""" @@ -752,11 +752,11 @@ class TestStreamSensorData(SleekTest): - + - + """) def testDelayedRequestFail(self): @@ -764,12 +764,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device22"); - myDevice._add_field(name="Temperature", typename="numeric", unit="°C"); + myDevice = Device("Device22") + myDevice._add_field(name="Temperature", typename="numeric", unit="°C") myDevice._set_momentary_timestamp("2013-03-07T16:24:30") - myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}); + myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}) - self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) dtnow = datetime.datetime.now() ts_2sec = datetime.timedelta(0,2) @@ -792,7 +792,7 @@ class TestStreamSensorData(SleekTest): xml_stanza['rejected']['error'] = error_text self._filtered_stanza_check(""" - @@ -825,13 +825,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -847,7 +847,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -861,11 +861,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -874,11 +874,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -886,7 +886,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testRequestFieldTo(self): @@ -895,13 +895,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -917,7 +917,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -931,11 +931,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -944,11 +944,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -956,7 +956,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testRequestFieldFromTo(self): @@ -965,13 +965,13 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - myDevice = Device("Device44"); - myDevice._add_field(name='Voltage', typename="numeric", unit="V"); - myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}); - myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}); + myDevice = Device("Device44") + myDevice._add_field(name='Voltage', typename="numeric", unit="V") + myDevice._add_field_timestamp_data(name="Voltage", value="230.1", timestamp="2000-01-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.2", timestamp="2000-02-01T00:01:02", flags={"invoiced": "true"}) + myDevice._add_field_timestamp_data(name="Voltage", value="230.3", timestamp="2000-03-01T00:01:02", flags={"invoiced": "true"}) - self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5); + self.xmpp['xep_0323'].register_node('Device44', myDevice, commTimeout=0.5) print("."), @@ -987,7 +987,7 @@ class TestStreamSensorData(SleekTest): """) self.send(""" - @@ -1001,11 +1001,11 @@ class TestStreamSensorData(SleekTest): - + - + """) self.send(""" @@ -1013,7 +1013,7 @@ class TestStreamSensorData(SleekTest): to='master@clayster.com/amr'> - + """) def testDelayedRequestClient(self): @@ -1021,25 +1021,25 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = []; - callback_data = {}; + results = [] + callback_data = {} def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result); + results.append(result) if result == "fields": - callback_data["nodeId"] = nodeId; - callback_data["timestamp"] = timestamp; - callback_data["error_msg"] = error_msg; + callback_data["nodeId"] = nodeId + callback_data["timestamp"] = timestamp + callback_data["error_msg"] = error_msg for f in fields: - callback_data["field_" + f['name']] = f; + callback_data["field_" + f['name']] = f t1= threading.Thread(name="request_data", target=self.xmpp['xep_0323'].request_data, - kwargs={"from_jid": "tester@localhost", - "to_jid": "you@google.com", - "nodeIds": ['Device33'], - "callback": my_callback}); - t1.start(); + kwargs={"from_jid": "tester@localhost", + "to_jid": "you@google.com", + "nodeIds": ['Device33'], + "callback": my_callback}) + t1.start() #self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); self.send(""" @@ -1054,20 +1054,20 @@ class TestStreamSensorData(SleekTest): """) self.recv(""" - - + """) self.recv(""" - - """) + + """) self.recv(""" - - + + - + """) self.recv(""" - + """) - t1.join(); + t1.join() time.sleep(.5) - self.failUnlessEqual(results, ["queued","started","fields","done"]); + self.failUnlessEqual(results, ["queued","started","fields","done"]) # self.assertIn("nodeId", callback_data); - self.assertTrue("nodeId" in callback_data); - self.failUnlessEqual(callback_data["nodeId"], "Device33"); + self.assertTrue("nodeId" in callback_data) + self.failUnlessEqual(callback_data["nodeId"], "Device33") # self.assertIn("timestamp", callback_data); - self.assertTrue("timestamp" in callback_data); - self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); + self.assertTrue("timestamp" in callback_data) + self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02") # self.assertIn("field_Voltage", callback_data); - self.assertTrue("field_Voltage" in callback_data); - self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); + self.assertTrue("field_Voltage" in callback_data) + self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}) # self.assertIn("field_TestBool", callback_data); - self.assertTrue("field_TestBool" in callback_data); - self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); + self.assertTrue("field_TestBool" in callback_data) + self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }) def testRequestFieldsCancelAPI(self): @@ -1114,12 +1114,12 @@ class TestStreamSensorData(SleekTest): plugins=['xep_0030', 'xep_0323']) - results = []; + results = [] def my_callback(from_jid, result, nodeId=None, timestamp=None, fields=None, error_msg=None): - results.append(result); + results.append(result) - session = self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback); + session = self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback) self.send(""" - + """) - self.xmpp['xep_0323'].cancel_request(session=session); + self.xmpp['xep_0323'].cancel_request(session=session) self.send(""" diff --git a/tests/test_stream_xep_0325.py b/tests/test_stream_xep_0325.py index 4b3250fc..2ebdd121 100644 --- a/tests/test_stream_xep_0325.py +++ b/tests/test_stream_xep_0325.py @@ -28,7 +28,7 @@ class TestStreamControl(SleekTest): pass def _time_now(self): - return datetime.datetime.now().replace(microsecond=0).isoformat(); + return datetime.datetime.now().replace(microsecond=0).isoformat() def tearDown(self): self.stream_close() @@ -38,10 +38,10 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device22"); - myDevice._add_control_field(name="Temperature", typename="int", value="15"); + myDevice = Device("Device22") + myDevice._add_control_field(name="Temperature", typename="int", value="15") - self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.recv(""" - + """) - self.assertEqual(myDevice._get_field_value("Temperature"), "17"); + self.assertEqual(myDevice._get_field_value("Temperature"), "17") def testRequestSetMulti(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device22"); - myDevice._add_control_field(name="Temperature", typename="int", value="15"); - myDevice._add_control_field(name="Startup", typename="date", value="2013-01-03"); + myDevice = Device("Device22") + myDevice._add_control_field(name="Temperature", typename="int", value="15") + myDevice._add_control_field(name="Startup", typename="date", value="2013-01-03") - myDevice2 = Device("Device23"); - myDevice2._add_control_field(name="Temperature", typename="int", value="19"); - myDevice2._add_control_field(name="Startup", typename="date", value="2013-01-09"); + myDevice2 = Device("Device23") + myDevice2._add_control_field(name="Temperature", typename="int", value="19") + myDevice2._add_control_field(name="Startup", typename="date", value="2013-01-09") - self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); - self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice2, commTimeout=0.5); + self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) + self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice2, commTimeout=0.5) self.recv(""" - + """) - self.assertEqual(myDevice._get_field_value("Temperature"), "17"); - self.assertEqual(myDevice2._get_field_value("Temperature"), "19"); + self.assertEqual(myDevice._get_field_value("Temperature"), "17") + self.assertEqual(myDevice2._get_field_value("Temperature"), "19") self.recv(""" - + """) - self.assertEqual(myDevice._get_field_value("Temperature"), "20"); - self.assertEqual(myDevice2._get_field_value("Temperature"), "20"); - self.assertEqual(myDevice._get_field_value("Startup"), "2013-02-01"); - self.assertEqual(myDevice2._get_field_value("Startup"), "2013-02-01"); + self.assertEqual(myDevice._get_field_value("Temperature"), "20") + self.assertEqual(myDevice2._get_field_value("Temperature"), "20") + self.assertEqual(myDevice._get_field_value("Startup"), "2013-02-01") + self.assertEqual(myDevice2._get_field_value("Startup"), "2013-02-01") def testRequestSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device23"); - myDevice._add_control_field(name="Temperature", typename="int", value="15"); + myDevice = Device("Device23") + myDevice._add_control_field(name="Temperature", typename="int", value="15") - self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0325'].register_node(nodeId="Device23", device=myDevice, commTimeout=0.5) self.recv(""" Invalid field Voltage - + """) - self.assertEqual(myDevice._get_field_value("Temperature"), "15"); - self.assertFalse(myDevice.has_control_field("Voltage", "int")); + self.assertEqual(myDevice._get_field_value("Temperature"), "15") + self.assertFalse(myDevice.has_control_field("Voltage", "int")) def testDirectSetOk(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device22"); - myDevice._add_control_field(name="Temperature", typename="int", value="15"); + myDevice = Device("Device22") + myDevice._add_control_field(name="Temperature", typename="int", value="15") - self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.recv(""" - @@ -191,20 +191,20 @@ class TestStreamControl(SleekTest): time.sleep(.5) - self.assertEqual(myDevice._get_field_value("Temperature"), "17"); + self.assertEqual(myDevice._get_field_value("Temperature"), "17") def testDirectSetFail(self): self.stream_start(mode='component', plugins=['xep_0030', 'xep_0325']) - myDevice = Device("Device22"); - myDevice._add_control_field(name="Temperature", typename="int", value="15"); + myDevice = Device("Device22") + myDevice._add_control_field(name="Temperature", typename="int", value="15") - self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5); + self.xmpp['xep_0325'].register_node(nodeId="Device22", device=myDevice, commTimeout=0.5) self.recv(""" - @@ -215,8 +215,8 @@ class TestStreamControl(SleekTest): time.sleep(.5) - self.assertEqual(myDevice._get_field_value("Temperature"), "15"); - self.assertFalse(myDevice.has_control_field("Voltage", "int")); + self.assertEqual(myDevice._get_field_value("Temperature"), "15") + self.assertFalse(myDevice.has_control_field("Voltage", "int")) def testRequestSetOkAPI(self): @@ -225,16 +225,16 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - results = []; + results = [] def my_callback(from_jid, result, nodeIds=None, fields=None, error_msg=None): - results.append(result); + results.append(result) fields = [] fields.append(("Temperature", "double", "20.5")) fields.append(("TemperatureAlarmSetting", "string", "High")) - self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback); + self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback) self.send(""" - + """) time.sleep(.5) - self.assertEqual(results, ["OK"]); + self.assertEqual(results, ["OK"]) def testRequestSetErrorAPI(self): @@ -269,16 +269,16 @@ class TestStreamControl(SleekTest): plugins=['xep_0030', 'xep_0325']) - results = []; + results = [] def my_callback(from_jid, result, nodeIds=None, fields=None, error_msg=None): - results.append(result); + results.append(result) fields = [] fields.append(("Temperature", "double", "20.5")) fields.append(("TemperatureAlarmSetting", "string", "High")) - self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback); + self.xmpp['xep_0325'].set_request(from_jid="tester@localhost", to_jid="you@google.com", fields=fields, nodeIds=['Device33', 'Device22'], callback=my_callback) self.send(""" Sensor error - + """) time.sleep(.5) - self.assertEqual(results, ["OtherError"]); + self.assertEqual(results, ["OtherError"]) def testServiceDiscoveryClient(self): self.stream_start(mode='client', plugins=['xep_0030', - 'xep_0325']); + 'xep_0325']) self.recv(""" - - + + """) def testServiceDiscoveryComponent(self): self.stream_start(mode='component', plugins=['xep_0030', - 'xep_0325']); + 'xep_0325']) self.recv(""" - - + + """) -- cgit v1.2.3