forked from mwicat/python2-osc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_osc_bundle_builder.py
More file actions
46 lines (35 loc) · 1.4 KB
/
test_osc_bundle_builder.py
File metadata and controls
46 lines (35 loc) · 1.4 KB
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
import unittest
from pythonosc import osc_bundle_builder
from pythonosc import osc_message_builder
class TestOscBundleBuilder(unittest.TestCase):
def test_empty_bundle(self):
bundle = osc_bundle_builder.OscBundleBuilder(
osc_bundle_builder.IMMEDIATELY).build()
self.assertEqual(0, bundle.num_contents)
def test_raises_on_build(self):
bundle = osc_bundle_builder.OscBundleBuilder(0.0)
bundle.add_content(None)
self.assertRaises(osc_bundle_builder.BuildError, bundle.build)
def test_raises_on_invalid_timestamp(self):
bundle = osc_bundle_builder.OscBundleBuilder("I am not a timestamp")
self.assertRaises(osc_bundle_builder.BuildError, bundle.build)
def test_build_complex_bundle(self):
bundle = osc_bundle_builder.OscBundleBuilder(
osc_bundle_builder.IMMEDIATELY)
msg = osc_message_builder.OscMessageBuilder(address="/SYNC")
msg.add_arg(4.0)
# Add 4 messages in the bundle, each with more arguments.
bundle.add_content(msg.build())
msg.add_arg(2)
bundle.add_content(msg.build())
msg.add_arg("value")
bundle.add_content(msg.build())
msg.add_arg(b"\x01\x02\x03")
bundle.add_content(msg.build())
sub_bundle = bundle.build()
# Now add the same bundle inside itself.
bundle.add_content(sub_bundle)
bundle = bundle.build()
self.assertEqual(5, bundle.num_contents)
if __name__ == "__main__":
unittest.main()