File size: 1,832 Bytes
cf8614b | 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 | import unittest
from pyrep.errors import PyRepError
from tests.core import TestCore
from pyrep.misc.distance import Distance
from pyrep.misc.signals import IntegerSignal, FloatSignal
from pyrep.misc.signals import DoubleSignal, StringSignal
# TODO: These tests will be re-enabled once bug has been fixed in CoppeliaSim.
class TestMisc(TestCore):
pass
# def test_get_distance(self):
# Distance('dist_cubes')
# def test_read_distance(self):
# d = Distance('dist_cubes')
# dist = d.read()
# self.assertAlmostEqual(dist, 0.1, places=3)
# def test_read_distance_not_measurable(self):
# d = Distance('dist_cubes_fail')
# with self.assertRaises(PyRepError):
# d.read()
class TestSignal(TestCore):
SIGNALS = [
(IntegerSignal, 99),
(FloatSignal, 55.3),
(DoubleSignal, 22.2),
(StringSignal, 'hello')
]
def test_set_get_clear_signals(self):
for signal_class, test_value in TestSignal.SIGNALS:
with self.subTest(signal=str(signal_class)):
sig = signal_class('my_signal')
sig.set(test_value)
ret_value = sig.get()
if isinstance(test_value, float):
self.assertAlmostEqual(ret_value, test_value, places=3)
else:
self.assertEqual(ret_value, test_value)
clears = sig.clear()
self.assertEqual(clears, 1)
def test_get_signal_fails_when_empty(self):
for signal_class, test_value in TestSignal.SIGNALS:
with self.subTest(signal=str(signal_class)):
sig = signal_class('my_signal')
with self.assertRaises(PyRepError):
sig.get()
if __name__ == '__main__':
unittest.main()
|