00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 import roslib; roslib.load_manifest('test_rosmaster')
00037
00038 import os
00039 import sys
00040 import struct
00041 import unittest
00042 import time
00043
00044 class TestRosmasterValidators(unittest.TestCase):
00045
00046 def test_ParameterInvalid(self):
00047
00048 from rosmaster.validators import ParameterInvalid
00049 self.assert_(isinstance(ParameterInvalid('param'), Exception))
00050
00051 def test_validators(self):
00052 from rosmaster.validators import ParameterInvalid
00053 from rosmaster.validators import non_empty
00054 contextes = ['', '/', '/foo']
00055 for context in contextes:
00056 valid = ['foo', 1, [1]]
00057 for v in valid:
00058 non_empty('param-name')(v, context)
00059 invalid = ['', 0, []]
00060 for i in invalid:
00061 try:
00062 non_empty('param-name-foo')(i, context)
00063 except ParameterInvalid, e:
00064 self.assert_('param-name-foo' in str(e))
00065
00066 from rosmaster.validators import non_empty_str
00067 valid = ['foo', 'f', u'f']
00068 for v in valid:
00069 non_empty_str('param-name')(v, context)
00070 invalid = ['', 1, ['foo']]
00071 for i in invalid:
00072 try:
00073 non_empty_str('param-name-bar')(i, context)
00074 except ParameterInvalid, e:
00075 self.assert_('param-name-bar' in str(e))
00076
00077 from rosmaster.validators import not_none
00078
00079 valid = ['foo', 'f', 1, False, 0, '']
00080 for v in valid:
00081 not_none('param-name')(v, context)
00082 invalid = [None]
00083 for i in invalid:
00084 try:
00085 not_none('param-name-charlie')(i, context)
00086 except ParameterInvalid, e:
00087 self.assert_('param-name-charlie' in str(e))
00088
00089 if __name__ == '__main__':
00090 import rostest
00091 rostest.unitrun('test_rosmaster', sys.argv[0], TestRosmasterValidators, coverage_packages=['rosmaster.validators'])