def test_tagClassMethods(self):
        '''
            test_tagClassMethods - test class methods like addClass, removeClass, hasClass
        '''

        tag = AdvancedTag('div')

        ret = tag.removeClass('blah')
        assert ret is None , "Expected to get None from tag.removeClass trying to remove non-existant class. Got: " + repr(ret)

        # Set initial classes
        tag.className = "hello world"

        # Add a class
        tag.addClass("welcome")

        assert 'class="hello world welcome"' in str(tag) , "Expected addClass to add class, but did not change HTML representation. Got: " + str(tag)

        assert tag.className == "hello world welcome" , "Expected addClass to add class, but did not change className property. Got: " + repr(tag.className)

        assert tag.classList == ['hello', 'world', 'welcome'] , "Expected addClass to add class, but did not return expected ordered classList. Got: " + repr(tag.classList)

        assert tag.hasClass("hello") , "Expected hasClass('hello') to return True."
        assert tag.hasClass("world") , "Expected hasClass('world') to return True."
        assert tag.hasClass("welcome") , "Expected hasClass('welcome') to return True."
        assert not tag.hasClass("blah") , "Expected hasClass('blah') to return False."


        # Remove middle class

        tag.removeClass("world")

        assert 'class="hello welcome"' in str(tag) , "Expected removeClass to remove class, but did not change HTML representation. Got: " + str(tag)

        assert tag.className == "hello welcome" , "Expected removeClass to remove class, but did not change className property. Got: " + repr(tag.className)

        assert tag.classList == ["hello", "welcome" ], "Expected removeClass to remove class, but did get expected classList. Got: " + repr(tag.classList)


        # Try to add a duplicate class

        tag.addClass("hello")
        assert 'class="hello welcome"' in str(tag) , "Expected addClass to not add duplicate class, but changed HTML representation. Got: " + str(tag)

        assert tag.className == "hello welcome" , "Expected addClass to not add duplicate class, but changed className property. Got: " + repr(tag.className)

        assert tag.classList == ['hello', 'welcome' ] , "Expected addClass to not add duplicate class, but did not return expected ordered classList. Got: " + repr(tag.classList)
    def test_classNames(self):
        tag = AdvancedTag('div')
        tag.addClass('abc')

        assert tag.hasClass('abc'), 'Failed to add class'
        assert 'abc' in tag.outerHTML , 'Failed to add class in outerHTML'

        tag.addClass('def')

        assert tag.hasClass('abc'), 'Failed to retain class'
        assert 'abc' in tag.outerHTML , ' Failed to retain in outerHTML'

        assert tag.hasClass('def'), 'Failed to add second class'
        assert 'def' in tag.outerHTML , ' Failed to add to outerHTML'

        tag.removeClass('abc')
        assert not tag.hasClass('abc'), 'Failed to remove class'
        assert 'abc' not in tag.outerHTML , 'Failed to remove class from outerHTML'

        assert tag.hasClass('def'), 'Failed to retain class'
        assert 'def' in tag.outerHTML , ' Failed to retain in outerHTML'
Exemple #3
0
    def test_classNames(self):
        tag = AdvancedTag('div')
        tag.addClass('abc')

        assert tag.hasClass('abc'), 'Failed to add class'
        assert 'abc' in tag.outerHTML, 'Failed to add class in outerHTML'

        tag.addClass('def')

        assert tag.hasClass('abc'), 'Failed to retain class'
        assert 'abc' in tag.outerHTML, ' Failed to retain in outerHTML'

        assert tag.hasClass('def'), 'Failed to add second class'
        assert 'def' in tag.outerHTML, ' Failed to add to outerHTML'

        tag.removeClass('abc')
        assert not tag.hasClass('abc'), 'Failed to remove class'
        assert 'abc' not in tag.outerHTML, 'Failed to remove class from outerHTML'

        assert tag.hasClass('def'), 'Failed to retain class'
        assert 'def' in tag.outerHTML, ' Failed to retain in outerHTML'
    def test_tagClassMethods(self):
        '''
            test_tagClassMethods - test class methods like addClass, removeClass, hasClass
        '''

        tag = AdvancedTag('div')

        ret = tag.removeClass('blah')
        assert ret is None, "Expected to get None from tag.removeClass trying to remove non-existant class. Got: " + repr(
            ret)

        # Set initial classes
        tag.className = "hello world"

        # Add a class
        tag.addClass("welcome")

        assert 'class="hello world welcome"' in str(
            tag
        ), "Expected addClass to add class, but did not change HTML representation. Got: " + str(
            tag)

        assert tag.className == "hello world welcome", "Expected addClass to add class, but did not change className property. Got: " + repr(
            tag.className)

        assert tag.classList == [
            'hello', 'world', 'welcome'
        ], "Expected addClass to add class, but did not return expected ordered classList. Got: " + repr(
            tag.classList)

        assert tag.hasClass(
            "hello"), "Expected hasClass('hello') to return True."
        assert tag.hasClass(
            "world"), "Expected hasClass('world') to return True."
        assert tag.hasClass(
            "welcome"), "Expected hasClass('welcome') to return True."
        assert not tag.hasClass(
            "blah"), "Expected hasClass('blah') to return False."

        # Remove middle class

        tag.removeClass("world")

        assert 'class="hello welcome"' in str(
            tag
        ), "Expected removeClass to remove class, but did not change HTML representation. Got: " + str(
            tag)

        assert tag.className == "hello welcome", "Expected removeClass to remove class, but did not change className property. Got: " + repr(
            tag.className)

        assert tag.classList == [
            "hello", "welcome"
        ], "Expected removeClass to remove class, but did get expected classList. Got: " + repr(
            tag.classList)

        # Try to add a duplicate class

        tag.addClass("hello")
        assert 'class="hello welcome"' in str(
            tag
        ), "Expected addClass to not add duplicate class, but changed HTML representation. Got: " + str(
            tag)

        assert tag.className == "hello welcome", "Expected addClass to not add duplicate class, but changed className property. Got: " + repr(
            tag.className)

        assert tag.classList == [
            'hello', 'welcome'
        ], "Expected addClass to not add duplicate class, but did not return expected ordered classList. Got: " + repr(
            tag.classList)