def testOptions(self): old_config = Config(deepcopy(options._config)) with option_context() as local_options: if options.account is None: self.assertEqual(options.account, old_config.account) else: self.assertEqual(options.account.access_id, old_config.account.access_id) self.assertEqual(options.account.secret_access_key, old_config.account.secret_access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.account = AliyunAccount('test', '') self.assertEqual(local_options.account.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator(is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) if options.account is None: self.assertEqual(options.account, old_config.account) else: self.assertEqual(options.account.access_id, old_config.account.access_id) self.assertEqual(options.account.secret_access_key, old_config.account.secret_access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive) def set_notexist(): options.display.val = 3 self.assertRaises(OptionError, set_notexist)
def testDumpAndLoad(self): with option_context() as local_options: local_options.register_option('test.value', 50, validator=any_validator( is_null, is_integer)) d = local_options.dumps() self.assertEqual(d['test.value'], 50) d['test.value'] = 100 local_options.loads(d) self.assertEqual(local_options.test.value, 100)
def testOptions(self): old_config = Config(deepcopy(options._config)) with option_context() as local_options: self.assertEqual(options.access_id, old_config.access_id) self.assertEqual(options.access_key, old_config.access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.access_id = 'test' self.assertEqual(local_options.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator(is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) self.assertEqual(options.access_id, old_config.access_id) self.assertEqual(options.access_key, old_config.access_key) self.assertEqual(options.end_point, old_config.end_point) self.assertEqual(options.default_project, old_config.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive) def set_notexist(): options.display.val = 3 self.assertRaises(OptionError, set_notexist)
def testOptions(self): with option_context() as local_options: self.assertIsNone(local_options.access_id) self.assertIsNone(local_options.access_key) self.assertIsNone(local_options.end_point) self.assertIsNone(local_options.default_project) self.assertIsNotNone(local_options.log_view_host) self.assertIsNone(local_options.tunnel_endpoint) self.assertGreater(local_options.chunk_size, 0) self.assertGreater(local_options.connect_timeout, 0) self.assertGreater(local_options.read_timeout, 0) self.assertIsNone(local_options.console.max_lines) self.assertIsNone(local_options.console.max_width) local_options.access_id = 'test' self.assertEqual(local_options.access_id, 'test') local_options.register_option('nest.inner.value', 50, validator=any_validator( is_null, is_integer)) self.assertEqual(local_options.nest.inner.value, 50) def set(val): local_options.nest.inner.value = val self.assertRaises(ValueError, lambda: set('test')) set(None) self.assertIsNone(local_options.nest.inner.value) set(30) self.assertEqual(local_options.nest.inner.value, 30) local_options.console.max_width = 40 self.assertEqual(local_options.console.max_width, 40) local_options.console.max_lines = 30 self.assertEqual(local_options.console.max_lines, 30) self.assertIsNone(options.access_id) self.assertIsNone(options.access_key) self.assertIsNone(options.end_point) self.assertIsNone(options.default_project) self.assertIsNotNone(options.log_view_host) self.assertIsNone(options.tunnel_endpoint) self.assertGreater(options.chunk_size, 0) self.assertGreater(options.connect_timeout, 0) self.assertGreater(options.read_timeout, 0) self.assertIsNone(options.console.max_lines) self.assertIsNone(options.console.max_width) self.assertRaises(AttributeError, lambda: options.nest.inner.value) self.assertFalse(options.interactive)