예제 #1
0
 def assertVariableTypes(self, variable_types, tests):
     for test in tests:
         try:
             result = parse_descriptor(test)
         except:
             print "Failed on the test case {}.".format(test)
             raise
         self.assertEqual(len(result), len(variable_types),
                 msg="Descriptor: {}".format(test))
         for k in xrange(len(result)):
             self.assertIsInstance(result[k], variable_types[k],
                     msg="test={} k={} expected={} result={}".format(
                         test, k, variable_types[k], result[k]))
예제 #2
0
    def assertMultipleVariableTypesOrRaises(self, variable_types, tests):
        for test_case in tests:
            descriptor, exception = test_case
            try:
                if exception is not None:
                    self.assertRaises(exception, parse_descriptor, descriptor)
                    continue

                result = parse_descriptor(descriptor)
                self.assertEqual(len(result), len(variable_types),
                        msg="Descriptor: {}".format(descriptor))
                for k in xrange(len(result)):
                    msg="descriptor={} k={} expected={} result={}".format(
                        descriptor, k, variable_types[k], result[k])
                    self.assertIsInstance(result[k], variable_types[k], msg)
            except Exception as e:
                print "Unexpected exception '{}' ({}) for test case {}.".format(
                        e, type(e), test_case)
                raise
예제 #3
0
 def test_parse_descriptor(self):
     """Test |-separation and whitespace trim."""
     self.assertEqual(len(parse_descriptor("1 | 2")), 2)
     self.assertEqual(len(parse_descriptor("1 || 2")), 2)
     self.assertEqual(len(parse_descriptor("|||1 ||")), 1)
     self.assertEqual(len(parse_descriptor("|||||")), 0)