Example #1
0
 def test_non_lazy_load(self):
     """Test OptionSet with initialised site."""
     options = api.OptionSet(self.get_site(), 'recentchanges', 'show')
     with self.assertRaises(KeyError):
         options.__setitem__('invalid_name', True)
     with self.assertRaises(ValueError):
         options.__setitem__('anon', 'invalid_value')
     options['anon'] = True
     self.assertCountEqual(['anon'], options._enabled)
     self.assertEqual(set(), options._disabled)
     self.assertLength(options, 1)
     self.assertEqual(['anon'], list(options))
     self.assertEqual(['anon'], list(options.api_iter()))
     options['bot'] = False
     self.assertCountEqual(['anon'], options._enabled)
     self.assertCountEqual(['bot'], options._disabled)
     self.assertLength(options, 2)
     self.assertEqual(['anon', 'bot'], list(options))
     self.assertEqual(['anon', '!bot'], list(options.api_iter()))
     options.clear()
     self.assertEqual(set(), options._enabled)
     self.assertEqual(set(), options._disabled)
     self.assertIsEmpty(options)
     self.assertEqual([], list(options))
     self.assertEqual([], list(options.api_iter()))
Example #2
0
 def test_non_lazy_load(self):
     """Test OptionSet with initialised site."""
     options = api.OptionSet(self.get_site(), 'recentchanges', 'show')
     self.assertRaisesRegex(KeyError, 'Invalid name', options.__setitem__,
                            'invalid_name', True)
     self.assertRaisesRegex(ValueError, 'Invalid value',
                            options.__setitem__, 'anon', 'invalid_value')
     options['anon'] = True
     self.assertCountEqual(['anon'], options._enabled)
     self.assertEqual(set(), options._disabled)
     self.assertEqual(1, len(options))
     self.assertEqual(['anon'], list(options))
     self.assertEqual(['anon'], list(options.api_iter()))
     options['bot'] = False
     self.assertCountEqual(['anon'], options._enabled)
     self.assertCountEqual(['bot'], options._disabled)
     self.assertEqual(2, len(options))
     self.assertEqual(['anon', 'bot'], list(options))
     self.assertEqual(['anon', '!bot'], list(options.api_iter()))
     options.clear()
     self.assertEqual(set(), options._enabled)
     self.assertEqual(set(), options._disabled)
     self.assertEqual(0, len(options))
     self.assertEqual([], list(options))
     self.assertEqual([], list(options.api_iter()))
Example #3
0
 def test_mutable_mapping(self):
     """Test keys, values and items from MutableMapping."""
     options = api.OptionSet()
     options['a'] = True
     options['b'] = False
     options['c'] = None
     self.assertCountEqual(['a', 'b'], list(options.keys()))
     self.assertCountEqual([True, False], list(options.values()))
     self.assertEqual(set(), set(options.values()) - set([True, False]))
     self.assertCountEqual([('a', True), ('b', False)], list(options.items()))
Example #4
0
 def test_lazy_load(self):
     """Test OptionSet with delayed site initialisation."""
     options = api.OptionSet()
     options['invalid_name'] = True
     options['anon'] = True
     self.assertIn('invalid_name', options._enabled)
     self.assertEqual(2, len(options))
     self.assertRaises(KeyError, options._set_site, self.get_site(),
                       'recentchanges', 'show')
     self.assertEqual(2, len(options))
     options._set_site(self.get_site(), 'recentchanges', 'show', True)
     self.assertEqual(1, len(options))
     self.assertRaises(TypeError, options._set_site, self.get_site(),
                       'recentchanges', 'show')