Beispiel #1
0
 def get_class_list(cls) -> DOMTokenList:
     """Get class-level class list, including all super class's."""
     cl = []
     cl.append(DOMTokenList(cls, cls.class_))
     if cls.inherit_class:
         for base_cls in cls.__bases__:
             if issubclass(base_cls, WdomElement):
                 cl.append(base_cls.get_class_list())
     # Reverse order so that parent's class comes to front  <- why?
     cl.reverse()
     return DOMTokenList(cls, *cl)
Beispiel #2
0
class TestClassList(TestCase):
    def setUp(self):
        self.cl = DOMTokenList(self)

    def test_addremove(self):
        self.assertIsFalse(bool(self.cl))
        self.assertEqual(len(self.cl), 0)
        self.cl.add('a')
        self.assertIsTrue(bool(self.cl))
        self.assertEqual(len(self.cl), 1)
        self.assertIn('a', self.cl)
        self.assertEqual('a', self.cl.toString())
        self.cl.add('b')
        self.assertIsTrue(bool(self.cl))
        self.assertEqual(len(self.cl), 2)
        self.assertIn('a', self.cl)
        self.assertIn('b', self.cl)
        self.assertEqual('a b', self.cl.toString())
        self.cl.remove('a')
        self.assertIsTrue(bool(self.cl))
        self.assertEqual(len(self.cl), 1)
        self.assertNotIn('a', self.cl)
        self.assertIn('b', self.cl)
        self.assertEqual('b', self.cl.toString())
Beispiel #3
0
 def setUp(self):
     self.tokens = DOMTokenList(self)
Beispiel #4
0
class TestDOMTokenList(TestCase):
    def setUp(self):
        self.tokens = DOMTokenList(self)

    def test_add(self):
        self.assertEqual(self.tokens.length, 0)
        self.assertEqual(self.tokens.toString(), '')

        self.tokens.add('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.add('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.add('b')
        self.assertEqual(self.tokens.length, 2)
        self.assertEqual(self.tokens.toString(), 'a b')

        with self.assertRaises(ValueError):
            self.tokens.add('a c')
        with self.assertRaises(ValueError):
            self.tokens.add('a', 'b c')

    def test_remove(self):
        self.tokens.add('a')
        self.tokens.add('b')
        self.assertEqual(self.tokens.length, 2)

        self.tokens.remove('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        self.tokens.remove('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        self.tokens.remove('b')
        self.assertEqual(self.tokens.length, 0)
        self.assertEqual(self.tokens.toString(), '')

        with self.assertRaises(ValueError):
            self.tokens.remove('a c')

    def test_toggle(self):
        self.tokens.toggle('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.toggle('b')
        self.assertEqual(self.tokens.length, 2)
        self.assertEqual(self.tokens.toString(), 'a b')

        self.tokens.toggle('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        with self.assertRaises(ValueError):
            self.tokens.toggle('a c')

    def test_item(self):
        self.assertIsNone(self.tokens.item(1))
        self.tokens.add('a')
        self.assertIsNone(self.tokens.item(1))
        self.tokens.add('b')
        self.assertEqual(self.tokens.item(1), 'b')

    def test_contains(self):
        self.assertFalse(self.tokens.contains('a'))
        self.tokens.add('a')
        self.assertTrue(self.tokens.contains('a'))

        with self.assertRaises(ValueError):
            self.tokens.contains('a c')

    def test_add_multi(self):
        self.tokens.add('a', 'b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_string(self):
        # used at initialization of Element
        self.tokens._append('a b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_list(self):
        # used at initialization of Element
        self.tokens._append(['a', 'b'])
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_mixed(self):
        # used at initialization of Element
        self.tokens._append(['a', 'b c'])
        self.assertEqual(len(self.tokens), 3)
        self.assertEqual('a b c', self.tokens.toString())
        self.tokens.remove('b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a c', self.tokens.toString())

    def test_remove_multi(self):
        self.tokens.add('a', 'b', 'c')
        self.tokens.remove('a', 'c')
        self.assertEqual(self.tokens.length, 1)
        self.assertNotIn('a', self.tokens)
        self.assertIn('b', self.tokens)
        self.assertNotIn('c', self.tokens)

    def test_add_none(self):
        with self.assertRaises(TypeError):
            self.tokens.add(None)

    def test_add_blank(self):
        self.tokens.add('')
        self.assertEqual(len(self.tokens), 0)
        self.assertFalse(bool(self.tokens))
        self.assertEqual('', self.tokens.toString())

    def test_add_invlalid(self):
        with self.assertRaises(TypeError):
            self.tokens.add(1)
        with self.assertRaises(TypeError):
            self.tokens.add(Element('a'))
        self.assertEqual(len(self.tokens), 0)
        self.assertFalse(bool(self.tokens))
        self.assertEqual('', self.tokens.toString())

    def test_iter(self):
        cls = ['a', 'b', 'c']
        self.tokens.add(*cls)
        for c in self.tokens:
            self.assertIn(c, cls)
            cls.remove(c)
        self.assertEqual(len(cls), 0)
Beispiel #5
0
 def setUp(self):
     self.tokens = DOMTokenList(self)
Beispiel #6
0
class TestDOMTokenList(TestCase):
    def setUp(self):
        self.tokens = DOMTokenList(self)

    def test_add(self):
        self.assertEqual(self.tokens.length, 0)
        self.assertEqual(self.tokens.toString(), '')

        self.tokens.add('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.add('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.add('b')
        self.assertEqual(self.tokens.length, 2)
        self.assertEqual(self.tokens.toString(), 'a b')

        with self.assertRaises(ValueError):
            self.tokens.add('a c')
        with self.assertRaises(ValueError):
            self.tokens.add('a', 'b c')

    def test_remove(self):
        self.tokens.add('a')
        self.tokens.add('b')
        self.assertEqual(self.tokens.length, 2)

        self.tokens.remove('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        self.tokens.remove('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        self.tokens.remove('b')
        self.assertEqual(self.tokens.length, 0)
        self.assertEqual(self.tokens.toString(), '')

        with self.assertRaises(ValueError):
            self.tokens.remove('a c')

    def test_toggle(self):
        self.tokens.toggle('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'a')

        self.tokens.toggle('b')
        self.assertEqual(self.tokens.length, 2)
        self.assertEqual(self.tokens.toString(), 'a b')

        self.tokens.toggle('a')
        self.assertEqual(self.tokens.length, 1)
        self.assertEqual(self.tokens.toString(), 'b')

        with self.assertRaises(ValueError):
            self.tokens.toggle('a c')

    def test_item(self):
        self.assertIsNone(self.tokens.item(1))
        self.tokens.add('a')
        self.assertIsNone(self.tokens.item(1))
        self.tokens.add('b')
        self.assertEqual(self.tokens.item(1), 'b')

    def test_contains(self):
        self.assertFalse(self.tokens.contains('a'))
        self.tokens.add('a')
        self.assertTrue(self.tokens.contains('a'))

        with self.assertRaises(ValueError):
            self.tokens.contains('a c')

    def test_add_multi(self):
        self.tokens.add('a', 'b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_string(self):
        # used at initialization of Element
        self.tokens._append('a b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_list(self):
        # used at initialization of Element
        self.tokens._append(['a', 'b'])
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a b', self.tokens.toString())
        self.tokens.remove('a')
        self.assertEqual(len(self.tokens), 1)
        self.assertEqual('b', self.tokens.toString())

    def test_add_multi_mixed(self):
        # used at initialization of Element
        self.tokens._append(['a', 'b c'])
        self.assertEqual(len(self.tokens), 3)
        self.assertEqual('a b c', self.tokens.toString())
        self.tokens.remove('b')
        self.assertEqual(len(self.tokens), 2)
        self.assertEqual('a c', self.tokens.toString())

    def test_remove_multi(self):
        self.tokens.add('a', 'b', 'c')
        self.tokens.remove('a', 'c')
        self.assertEqual(self.tokens.length, 1)
        self.assertNotIn('a', self.tokens)
        self.assertIn('b', self.tokens)
        self.assertNotIn('c', self.tokens)

    def test_add_none(self):
        with self.assertRaises(TypeError):
            self.tokens.add(None)

    def test_add_blank(self):
        self.tokens.add('')
        self.assertEqual(len(self.tokens), 0)
        self.assertFalse(bool(self.tokens))
        self.assertEqual('', self.tokens.toString())

    def test_add_invlalid(self):
        with self.assertRaises(TypeError):
            self.tokens.add(1)
        with self.assertRaises(TypeError):
            self.tokens.add(Element('a'))
        self.assertEqual(len(self.tokens), 0)
        self.assertFalse(bool(self.tokens))
        self.assertEqual('', self.tokens.toString())

    def test_iter(self):
        cls = ['a', 'b', 'c']
        self.tokens.add(*cls)
        for c in self.tokens:
            self.assertIn(c, cls)
            cls.remove(c)
        self.assertEqual(len(cls), 0)
Beispiel #7
0
 def setUp(self):
     self.cl = DOMTokenList(self)