def test_shortcut_options(self): trace_actions = get_option('cas.trace_actions') index_name = get_option('cas.dataset.index_name') self.assertEqual(get_option('trace_actions'), trace_actions) self.assertEqual(options.trace_actions, trace_actions) options.trace_actions = True self.assertEqual(get_option('cas.trace_actions'), True) self.assertEqual(options.cas.trace_actions, True) self.assertEqual(options.trace_actions, True) self.assertEqual(get_option('index_name'), index_name) self.assertEqual(get_option('dataset.index_name'), index_name) self.assertEqual(options.index_name, index_name) options.index_name = 'Foo' self.assertEqual(get_option('index_name'), 'Foo') self.assertEqual(get_option('dataset.index_name'), 'Foo') self.assertEqual(options.index_name, 'Foo') reset_option('index_name') self.assertEqual(get_option('index_name'), '_Index_') self.assertEqual(get_option('dataset.index_name'), '_Index_') self.assertEqual(options.index_name, '_Index_')
def test_missing_options(self): with self.assertRaises(SWATOptionError): set_option('cas.foo', 10) with self.assertRaises(SWATOptionError): options.cas.foo = 10 with self.assertRaises(SWATOptionError): get_option('cas.foo') with self.assertRaises(SWATOptionError): print(options.cas.foo) # You can not access a midpoint in the hierarchy with (s|g)et_option with self.assertRaises(SWATOptionError): set_option('cas', 10) with self.assertRaises(SWATOptionError): get_option('cas')
def test_basic(self): self.assertEqual(get_option('cas.print_messages'), True) # self.assertEqual(get_option('display.notebook.repr_html'), True) # self.assertEqual(get_option('display.notebook.repr_javascript'), False) set_option('cas.print_messages', False) self.assertEqual(get_option('cas.print_messages'), False) with self.assertRaises(SWATOptionError): options.cas.print_messages = 'foo' options.cas.print_messages = True self.assertEqual(options.cas.print_messages, True) with self.assertRaises(SWATOptionError): options.cas.print_messages = 10 self.assertEqual(options.cas.print_messages, True) self.assertEqual(type(options.cas), type(options)) # This key exists, but it's a level in the hierarchy, not an option # with self.assertRaises(SWATOptionError): # get_option('display.notebook.css') options.cas.print_messages = False reset_option('cas.print_messages') self.assertEqual(options.cas.print_messages, True) with self.assertRaises(SWATOptionError): reset_option('cas.foo') with self.assertRaises(SWATOptionError): reset_option('cas')