Commit 9bd776e3 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

Merge branch 'trac3114'

parents ae4a470f 9ad9193e
......@@ -24,6 +24,7 @@ import isc.cc.data
import isc.config.module_spec
import ast
import copy
import sys
class ConfigDataError(Exception): pass
......@@ -62,10 +63,16 @@ def check_type(spec_part, value):
else:
raise isc.cc.data.DataTypeError(str("Incorrect specification part for type checking"))
if data_type == "integer" and type(value) != int:
raise isc.cc.data.DataTypeError(str(value) + " is not an integer")
elif data_type == "real" and type(value) != float:
raise isc.cc.data.DataTypeError(str(value) + " is not a real")
if data_type == "integer":
if type(value) != int:
raise isc.cc.data.DataTypeError(str(value) + " is not an integer")
if value > sys.maxsize:
raise isc.cc.data.DataTypeError(str(value) + " is too large an integer")
elif data_type == "real":
if type(value) != float:
raise isc.cc.data.DataTypeError(str(value) + " is not a real")
if float(value) > sys.float_info.max:
raise isc.cc.data.DataTypeError(str(value) + " is too large a float")
elif data_type == "boolean" and type(value) != bool:
raise isc.cc.data.DataTypeError(str(value) + " is not a boolean")
elif data_type == "string" and type(value) != str:
......
......@@ -47,6 +47,7 @@ class TestConfigData(unittest.TestCase):
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, "a")
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, [ 1, 2 ])
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, { "a": 1 })
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, 10000000000000000000000)
spec_part = find_spec_part(config_spec, "value2")
check_type(spec_part, 1.1)
......@@ -55,6 +56,7 @@ class TestConfigData(unittest.TestCase):
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, "a")
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, [ 1, 2 ])
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, { "a": 1 })
self.assertRaises(isc.cc.data.DataTypeError, check_type, spec_part, 2.0000000e+308)
spec_part = find_spec_part(config_spec, "value3")
check_type(spec_part, True)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment