def test_load_configuration(self): Configuration().core_clear() rsp = RsParameters() self.assertEquals("test_rs_paras", rsp.configuration_name()) rsp.max_items_in_list = 5566 rsp.save_configuration_as("realy_not_a_name_for_config") self.assertEquals("realy_not_a_name_for_config", rsp.configuration_name()) rsp = RsParameters(config_name="realy_not_a_name_for_config") self.assertEquals(5566, rsp.max_items_in_list) self.assertTrue("realy_not_a_name_for_config" in Configurations.list_configurations()) Configurations.remove_configuration("realy_not_a_name_for_config") with self.assertRaises(Exception) as context: RsParameters(config_name="realy_not_a_name_for_config") self.assertIsInstance(context.exception, ValueError) Configuration().reset() rsp = RsParameters() self.assertEquals("realy_not_a_name_for_config", rsp.configuration_name())
def test_max_items_in_list(self): # defaults to configuration defaults Configuration().core_clear() rsp = RsParameters() self.assertEquals(50000, rsp.max_items_in_list) rsp = RsParameters(max_items_in_list=1) self.assertEquals(1, rsp.max_items_in_list) # contamination test rsp.max_items_in_list = 12345 rsp2 = RsParameters(**rsp.__dict__) self.assertEquals(12345, rsp2.max_items_in_list) with self.assertRaises(Exception) as context: rsp.max_items_in_list = "foo" #print(context.exception) self.assertEquals( "Invalid value for max_items_in_list: not a number foo", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.max_items_in_list = 0 #print(context.exception) self.assertEquals( "Invalid value for max_items_in_list: value should be between 1 and 50000", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.max_items_in_list = 50001 #print(context.exception) self.assertEquals( "Invalid value for max_items_in_list: value should be between 1 and 50000", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) self.save_configuration_test(rsp)