Skip to content
Joe Mazzone edited this page Jul 13, 2023 · 5 revisions

HTML/CSS Grade

Autograder helper Python lib for easy HTML and CSS checks

Example

import htmlcssgrade

learner_css = htmlcssgrade.CSS_Check("css/style.css")
learner_html = htmlcssgrade.HTML_Check("index.html")

print(learner_css.code)
print(learner_css.check_declaration("body", "background-color: #F06543"))
print(learner_css.check_property_used("body", "font-style"))
print(learner_css.check_num_declarations(37))

print(learner_html.code)
print(learner_html.check_element_used("p"))
print(learner_html.check_element_content("a", "Home"))
print(learner_html.check_element_has_class("img", "center"))

Example with Unit Testing

import unittest
import htmlcssgrade

class CodingRoomsUnitTests(unittest.TestCase):

    def test_check_css(self):
        learner_css = htmlcssgrade.CSS_Check("css/style.css")
        self.assertTrue(learner_css.check_declaration("body", "background-color: #F06543"))
    
    def test_check_html(self):
        learner_html = htmlcssgrade.HTML_Check("index.html")
        self.assertTrue(learner_html.check_elements_attribute("img", "src", "img/hello.png"))
Clone this wiki locally