Commit e443a325 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[trac929] add unittests for the functions:

 - validate_format
 - check_format
 - validate_format
parent cddcafd7
......@@ -81,6 +81,11 @@ class TestModuleSpec(unittest.TestCase):
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec20.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec21.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec26.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec34.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec35.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec36.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec37.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec38.spec")
def validate_data(self, specfile_name, datafile_name):
dd = self.read_spec_file(specfile_name);
......@@ -123,6 +128,17 @@ class TestModuleSpec(unittest.TestCase):
self.assertEqual(False, self.validate_command_params("spec27.spec", "data22_8.data", 'cmd1'))
self.assertEqual(False, self.validate_command_params("spec27.spec", "data22_8.data", 'cmd2'))
def test_statistics_validation(self):
def _validate_stat(specfile_name, datafile_name):
dd = self.read_spec_file(specfile_name);
data_file = open(self.spec_file(datafile_name))
data_str = data_file.read()
data = isc.cc.data.parse_value_str(data_str)
return dd.validate_statistics(True, data, [])
self.assertFalse(self.read_spec_file("spec1.spec").validate_statistics(True, None, None));
self.assertTrue(_validate_stat("spec33.spec", "data33_1.data"))
self.assertFalse(_validate_stat("spec33.spec", "data33_2.data"))
def test_init(self):
self.assertRaises(ModuleSpecError, ModuleSpec, 1)
module_spec = isc.config.module_spec_from_file(self.spec_file("spec1.spec"), False)
......@@ -269,6 +285,74 @@ class TestModuleSpec(unittest.TestCase):
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_datetime",
'item_type': "string",
'item_optional': False,
'item_default': 1,
'item_format': "date-time"
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_date",
'item_type': "string",
'item_optional': False,
'item_default': 1,
'item_format': "date"
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_time",
'item_type': "string",
'item_optional': False,
'item_default': 1,
'item_format': "time"
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_datetime",
'item_type': "string",
'item_optional': False,
'item_default': "2011-05-27T19:42:57Z",
'item_format': "dummy-format"
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_date",
'item_type': "string",
'item_optional': False,
'item_default': "2011-05-27",
'item_format': "dummy-format"
}
)
self.assertRaises(ModuleSpecError, isc.config.module_spec._check_item_spec,
{ 'item_name': "a_time",
'item_type': "string",
'item_optional': False,
'item_default': "19:42:57Z",
'item_format': "dummy-format"
}
)
def test_check_format(self):
self.assertTrue(isc.config.module_spec._check_format('2011-05-27T19:42:57Z', 'date-time'))
self.assertTrue(isc.config.module_spec._check_format('2011-05-27', 'date'))
self.assertTrue(isc.config.module_spec._check_format('19:42:57', 'time'))
self.assertFalse(isc.config.module_spec._check_format('2011-05-27T19:42:57Z', 'dummy'))
self.assertFalse(isc.config.module_spec._check_format('2011-05-27', 'dummy'))
self.assertFalse(isc.config.module_spec._check_format('19:42:57', 'dummy'))
self.assertFalse(isc.config.module_spec._check_format('2011-13-99T99:99:99Z', 'date-time'))
self.assertFalse(isc.config.module_spec._check_format('2011-13-99', 'date'))
self.assertFalse(isc.config.module_spec._check_format('99:99:99', 'time'))
self.assertFalse(isc.config.module_spec._check_format('', 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, None))
def test_validate_type(self):
errors = []
self.assertEqual(True, isc.config.module_spec._validate_type({ 'item_type': 'integer' }, 1, errors))
......@@ -306,6 +390,25 @@ class TestModuleSpec(unittest.TestCase):
self.assertEqual(False, isc.config.module_spec._validate_type({ 'item_type': 'map' }, 1, errors))
self.assertEqual(['1 should be a map'], errors)
def test_validate_format(self):
errors = []
self.assertEqual(True, isc.config.module_spec._validate_format({ 'item_format': 'date-time' }, "2011-05-27T19:42:57Z", errors))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'date-time' }, "a", None))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'date-time' }, "a", errors))
self.assertEqual(['format type of a should be date-time'], errors)
errors = []
self.assertEqual(True, isc.config.module_spec._validate_format({ 'item_format': 'date' }, "2011-05-27", errors))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'date' }, "a", None))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'date' }, "a", errors))
self.assertEqual(['format type of a should be date'], errors)
errors = []
self.assertEqual(True, isc.config.module_spec._validate_format({ 'item_format': 'time' }, "19:42:57", errors))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'time' }, "a", None))
self.assertEqual(False, isc.config.module_spec._validate_format({ 'item_format': 'time' }, "a", errors))
self.assertEqual(['format type of a should be time'], errors)
def test_validate_spec(self):
spec = { 'item_name': "an_item",
'item_type': "string",
......
Markdown is supported
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