Skip to content

Commit

Permalink
Merge pull request #193 from dodona-edu/colour
Browse files Browse the repository at this point in the history
added color conversions + tests
  • Loading branch information
QuintenVervynck authored Nov 16, 2021
2 parents 212a74d + 9d7f320 commit 05b4e34
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 445 deletions.
2 changes: 0 additions & 2 deletions exceptions/double_char_exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from dodona.translator import Translator
from exceptions.utils import DelayedExceptions, FeedbackException

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cssselect==1.1.0
lxml==4.6.4
tinycss2==1.1.0
py-emmet==1.1.10
html-similarity==0.3.3
colour==0.1.5
html-similarity==0.3.3
27 changes: 27 additions & 0 deletions tests/test_utils/test_color_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from utils.color_converter import Color


class TestColorConverter(unittest.TestCase):

def test_conversion_red(self):
correct = Color("red")

# All possibilities to make the color "red"
self.assertEqual(correct, Color("red"), "test name")

self.assertEqual(correct, Color("#ff0000"), "test hex")
self.assertEqual(correct, Color("#ff0000ff"), "test hex")
self.assertEqual(correct, Color("#f00"), "test hex")
self.assertEqual(correct, Color("#f00f"), "test hex")

self.assertEqual(correct, Color("rgb(255,0,0)"), "test rgb")
self.assertEqual(correct, Color("rgb(100%,0,0)"), "test rgb")

self.assertEqual(correct, Color("rgba(255,0,0,1)"), "test rgba")
self.assertEqual(correct, Color("rgba(100%,0%,0%,1)"), "test rgba")

self.assertEqual(correct, Color("hsl(0, 100%, 50%)"), "test hsl")

self.assertEqual(correct, Color("hsla(0, 100%, 50%,1)"), "test hsla")

10 changes: 7 additions & 3 deletions tests/test_validators/test_css_validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from bs4 import BeautifulSoup

from utils.color_converter import Color
from validators.css_validator import CssValidator

html = """<!DOCTYPE html>
Expand Down Expand Up @@ -34,7 +35,7 @@
.test_most_precise,
.test_order
{color: green;margin:2px;}
.test_color_1 {color:#008000;margin:2px}
</style>
</head>
Expand Down Expand Up @@ -107,6 +108,8 @@
<div class="test_important"></div>
<div class="test_color_1"></div>
</body>
</html>
"""
Expand Down Expand Up @@ -142,7 +145,8 @@ def test_green_tests(self):
"test_element_with_attribute_contains_substring_value",
"test_most_precise", # this is already checked implicitly hence everything is color: red
"test_order",
"test_important"
"test_important",
"test_color_1"
]

# Change amount of times this is run to benchmark
Expand All @@ -152,7 +156,7 @@ def test_green_tests(self):
for _ in range(num_tests):
for green_class in test_classes:
sol_el = self.bs.find("div", attrs={"class": green_class})
self.assertEqual("green", self.validator.find(sol_el, "color").value_str, green_class)
self.assertEqual(Color("green"), self.validator.find(sol_el, "color").color, green_class)
for _ in range(num_tests):
for green_class in test_classes:
sol_el = self.bs.find("div", attrs={"class": green_class})
Expand Down
Loading

0 comments on commit 05b4e34

Please sign in to comment.