Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 30d651c

Browse files
authored
Merge pull request #11 from DirectiveAthena/4.1.0_Proposal
4.1.0 proposal
2 parents f504d4f + 720ef79 commit 30d651c

29 files changed

+2032
-1609
lines changed

Tests/BulkTests.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ----------------------------------------------------------------------------------------------------------------------
2+
# - Package Imports -
3+
# ----------------------------------------------------------------------------------------------------------------------
4+
# General Packages
5+
from __future__ import annotations
6+
import unittest
7+
8+
# Custom Library
9+
10+
# Custom Packages
11+
12+
# ----------------------------------------------------------------------------------------------------------------------
13+
# - Code -
14+
# ----------------------------------------------------------------------------------------------------------------------
15+
class BulkTests(unittest.TestCase):
16+
def Subtest_Equality(self, ObjectType:type, cases):
17+
for value, result, value_printer in cases:
18+
with self.subTest(ObjectType=ObjectType,value=value, result=result, value_printer=value_printer):
19+
self.assertEqual(ObjectType(value), result)
20+
21+
def Subtest_Fail(self, ObjectType:type, cases):
22+
for value, error in cases:
23+
with self.subTest(ObjectType=ObjectType,value=value, error=error):
24+
with self.assertRaises(error):
25+
ObjectType(value)
26+
27+
def Subtest_ObjectOperation(self, ObjectType:type, args:tuple, kwargs:dict, cases):
28+
for operation, oargs, okwargs,result in cases:
29+
with self.subTest(ObjectType=ObjectType, args=args, kwargs=kwargs, oargs=oargs, okwargs=okwargs,result=result, ):
30+
test_object = ObjectType(*args, **kwargs)
31+
self.assertEqual(operation(test_object, *oargs, *okwargs), result)
32+
33+
def Subtest_ObjectOperationBulk(self, ObjectType:type, cases):
34+
for operation, oargs, okwargs, args, kwargs,result in cases:
35+
with self.subTest(ObjectType=ObjectType, args=args, kwargs=kwargs, operation=operation,oargs=oargs, okwargs=okwargs,result=result, ):
36+
test_object = ObjectType(*args, **kwargs)
37+
self.assertEqual(operation(test_object, *oargs, *okwargs), result)

Tests/ColorObjects/test_ColorTupleConversions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# Custom Library
99
from AthenaColor.Objects.Color.ColorTupleConversion import *
10-
from AthenaColor.Objects.Color.ColorTupleConversion import NormalizeRgb
1110

1211
# Custom Packages
1312
# ----------------------------------------------------------------------------------------------------------------------

Tests/ColorObjects/test_Dunders.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# ----------------------------------------------------------------------------------------------------------------------
2+
# - Package Imports -
3+
# ----------------------------------------------------------------------------------------------------------------------
4+
# General Packages
5+
from __future__ import annotations
6+
import copy
7+
import operator
8+
9+
# Custom Library
10+
from AthenaColor import RGB, RGBA, HEX, HEXA, HSL, HSV, CMYK
11+
12+
# Custom Packages
13+
from Tests.BulkTests import BulkTests
14+
15+
# ----------------------------------------------------------------------------------------------------------------------
16+
# - Code -
17+
# ----------------------------------------------------------------------------------------------------------------------
18+
class DunderTesting(BulkTests):
19+
def test_RGB(self):
20+
objectType=RGB
21+
casesOperation=(
22+
#operation oargs okwargs args kwargs result
23+
(str, (), {}, (0,0,0), {}, "0;0;0"),
24+
(repr, (), {}, (0,0,0), {}, "RGB(r=0,g=0,b=0)"),
25+
(round, (), {}, (0,0,0), {}, RGB(0,0,0)), # doesn't really impact the RGB or HEX objects, but exsists nonetheless
26+
(bool, (), {}, (0,0,0), {}, False),
27+
(bool, (), {}, (0,0,1), {}, True),
28+
(divmod, (8,), {}, (127,71,54), {}, (RGB(r=15,g=8,b=6), RGB(r=7,g=7,b=6))),
29+
(divmod, ((8,4,2),), {}, (127,71,54), {}, (RGB(r=15,g=17,b=27), RGB(r=7,g=3,b=0))),
30+
(divmod, (RGB(8,4,2),), {}, (127,71,54), {}, (RGB(r=15,g=17,b=27), RGB(r=7,g=3,b=0))),
31+
(divmod, (HSL(180,.5,.5),), {}, (127,71,54), {}, (RGB(r=1,g=0,b=0), RGB(r=63,g=71,b=54))),
32+
(sum, (), {}, (127,127,127), {}, 381),
33+
(max, (), {}, (52,128,255), {}, 255),
34+
(min, (), {}, (52,128,255), {}, 52),
35+
(copy.copy, (), {}, (52,128,255), {}, RGB(52,128,255)),
36+
(operator.contains,(52,), {}, (52,128,255), {}, True),
37+
(operator.contains,(12,), {}, (52,128,255), {}, False),
38+
)
39+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
40+
41+
def test_HEX(self):
42+
objectType=HEX
43+
casesOperation=(
44+
#operation oargs okwargs args kwargs result
45+
(str, (), {}, ("#000000",), {}, "#000000"),
46+
(repr, (), {}, ("#000000",), {}, 'HEX(hex_value="#000000")'),
47+
(round, (), {}, ("#000000",), {}, HEX("#000000")), # doesn't really impact the RGB or HEX objects, but exsists nonetheless
48+
(bool, (), {}, ("#000000",), {}, False),
49+
(bool, (), {}, ("#000001",), {}, True),
50+
(divmod, (8,), {}, ("#7f4736",), {}, (HEX("#0f0806"), HEX("#070706"))),
51+
52+
)
53+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
54+
55+
def test_RGBA(self):
56+
objectType=RGBA
57+
casesOperation=(
58+
#operation oargs okwargs args kwargs result
59+
(str, (), {}, (0,0,0), {}, "0;0;0;0"),
60+
(repr, (), {}, (0,0,0), {}, "RGBA(r=0,g=0,b=0,a=0)"),
61+
(round, (), {}, (0,0,0), {}, RGBA(0,0,0,0)), # doesn't really impact the RGB or HEX objects, but exsists nonetheless
62+
(bool, (), {}, (0,0,0), {}, False),
63+
(bool, (), {}, (0,0,1), {}, True),
64+
(divmod, (8,), {}, (127,71,54,28), {}, (RGBA(r=15,g=8,b=6,a=3), RGBA(r=7,g=7,b=6,a=4))),
65+
(divmod, ((8,4,2,5),), {}, (127,71,54,28), {}, (RGBA(r=15,g=17,b=27,a=5), RGBA(r=7,g=3,b=0,a=3))),
66+
(divmod, (RGBA(8,4,2,1),), {}, (127,71,54,28), {}, (RGBA(r=15,g=17,b=27,a=28), RGBA(r=7,g=3,b=0,a=0))),
67+
(divmod, (HSL(180,.5,.5),), {}, (127,71,54,28), {}, (RGBA(r=1,g=0,b=0,a=0), RGBA(r=63,g=71,b=54,a=28))),
68+
)
69+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
70+
71+
def test_HEXA(self):
72+
objectType=HEXA
73+
casesOperation=(
74+
#operation oargs okwargs args kwargs result
75+
(str, (), {}, ("#00000000",), {}, "#00000000"),
76+
(repr, (), {}, ("#00000000",), {}, 'HEXA(hex_value="#00000000")'),
77+
(round, (), {}, ("#00000000",), {}, HEXA("#00000000")), # doesn't really impact the RGB or HEX objects, but exsists nonetheless
78+
(bool, (), {}, ("#00000000",), {}, False),
79+
(bool, (), {}, ("#00000100",), {}, True),
80+
(divmod, (8,), {}, ("#7f473612",), {}, (HEXA(hex_value="#0f080602"), HEXA(hex_value="#07070602"))),
81+
(divmod, ((8,4,2,5),), {}, ("#7f473612",), {}, (HEXA(hex_value="#0f111b03"), HEXA(hex_value="#07030003"))),
82+
(divmod, (RGBA(8,4,2,1),), {}, ("#7f473612",), {}, (HEXA(hex_value="#0f111b12"), HEXA(hex_value="#07030000"))),
83+
(divmod, (HEXA("#0f111b12"),),{}, ("#7f473612",), {}, (HEXA(hex_value="#08040201"), HEXA(hex_value="#07030000"))),
84+
(divmod, (HSL(180,.5,.5),), {}, ("#7f473612",), {}, (HEXA(hex_value="#01000000"), HEXA(hex_value="#3f473612"))),
85+
)
86+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
87+
88+
def test_HSV(self):
89+
objectType=HSV
90+
casesOperation=(
91+
#operation oargs okwargs args kwargs result
92+
(str, (), {}, (180,.5,.5), {}, "180;0.5;0.5"),
93+
(repr, (), {}, (180,.5,.5), {}, 'HSV(h=180,s=0.5,v=0.5)'),
94+
(round, (), {}, (180,.5,.5), {}, HSV(180,0,0)),
95+
(round, (5,), {}, (180,.123456,.123456), {}, HSV(180,.12346,.12346)),
96+
(bool, (), {}, (0,0,0), {}, False),
97+
(bool, (), {}, (0,0,1), {}, True),
98+
(divmod, (8,), {}, (180,.5,.5), {}, (HSV(h=22,s=0.0,v=0.0), HSV(h=4,s=0.5,v=0.5))),
99+
(divmod, ((8,.025,.02),), {}, (180,.5,.5), {}, (HSV(h=22,s=1,v=1), HSV(h=4,s=0.024999999999999974,v=0.01999999999999999))),
100+
(divmod, (RGB(8,4,2),), {}, (180,.5,.5), {}, (HSV(h=9,s=0.0,v=1), HSV(h=0,s=0.5,v=0.0040000000000000036))),
101+
(divmod, (HSV(8,.025,.02),), {}, (180,.5,.5), {}, (HSV(h=22,s=1,v=1), HSV(h=4,s=0.024999999999999974,v=0.01999999999999999))),
102+
)
103+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
104+
105+
def test_HSL(self):
106+
objectType=HSL
107+
casesOperation=(
108+
#operation oargs okwargs args kwargs result
109+
(str, (), {}, (180,.5,.5), {}, "180;0.5;0.5"),
110+
(repr, (), {}, (180,.5,.5), {}, 'HSL(h=180,s=0.5,l=0.5)'),
111+
(round, (), {}, (180,.5,.5), {}, HSL(180,0,0)),
112+
(round, (5,), {}, (180,.123456,.123456), {}, HSL(180,.12346,.12346)),
113+
(bool, (), {}, (0,0,0), {}, False),
114+
(bool, (), {}, (0,0,1), {}, True),
115+
(divmod, (8,), {}, (180,.5,.5), {}, (HSL(h=22,s=0.0,l=0.0), HSL(h=4,s=0.5,l=0.5))),
116+
(divmod, ((8,.025,.02),), {}, (180,.5,.5), {}, (HSL(h=22,s=1,l=1), HSL(h=4,s=0.024999999999999974,l=0.01999999999999999))),
117+
(divmod, (RGB(8,4,2),), {}, (180,.5,.5), {}, (HSL(h=9,s=0.0,l=1), HSL(h=0,s=0.5,l=0.01999999999999999))),
118+
(divmod, (HSL(8,.025,.02),), {}, (180,.5,.5), {}, (HSL(h=22,s=1,l=1), HSL(h=4,s=0.024999999999999974,l=0.01999999999999999))),
119+
)
120+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)
121+
122+
def test_CMYK(self):
123+
objectType=CMYK
124+
casesOperation=(
125+
#operation oargs okwargs args kwargs result
126+
(str, (), {}, (.5,.5,.5,.5), {}, "0.5;0.5;0.5;0.5"),
127+
(repr, (), {}, (.5,.5,.5,.5), {}, 'CMYK(c=0.5,m=0.5,y=0.5,k=0.5)'),
128+
(round, (), {}, (.5,.5,.5,.5), {}, CMYK(0,0,0,0)),
129+
(round, (5,), {}, (.123456,.123456,.123456,.123456), {}, CMYK(.12346,.12346,.12346,.12346)),
130+
(divmod, ((8,4,2,5),), {}, (.5,.5,.5,.5), {}, (CMYK(c=0.0,m=0.0,y=0.0,k=0.0), CMYK(c=0.5,m=0.5,y=0.5,k=0.5))),
131+
(divmod, ((.8,.4,.2,.5),), {}, (.5,.5,.5,.5), {}, (CMYK(c=0.0,m=1.0,y=1,k=1.0), CMYK(c=0.5,m=0.09999999999999998,y=0.09999999999999998,k=0.0))),
132+
(bool, (), {}, (0,0,0,0), {}, False),
133+
(bool, (), {}, (0,0,0,1), {}, True),
134+
(divmod, (8,), {}, (.5,.5,.5,.5), {}, (CMYK(c=0.0,m=0.0,y=0.0,k=0.0), CMYK(c=0.5,m=0.5,y=0.5,k=0.5))),
135+
(divmod, ((8,.025,.02, 0.01),), {}, (.5,.5,.5,.5), {}, (CMYK(c=0.0,m=1,y=1,k=1), CMYK(c=0.5,m=0.024999999999999974,y=0.01999999999999999,k=0.00999999999999999))),
136+
(divmod, (CMYK(8,.025,.02, 0.01),), {}, (.5,.5,.5,.5), {}, (CMYK(c=0.0,m=1,y=1,k=1), CMYK(c=0.5,m=0.024999999999999974,y=0.01999999999999999,k=0.00999999999999999))),
137+
)
138+
self.Subtest_ObjectOperationBulk(objectType, casesOperation)

Tests/ColorObjects/test_HEX.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def CreateColor(hex_str = "#204080") -> HEX:
2525
def test_input(self):
2626
with self.assertRaises(TypeError):
2727
HEX(1)
28-
with self.assertRaises(TypeError):
28+
with self.assertRaises(ValueError):
2929
HEX(b"#123456")
3030
with self.assertRaises(ValueError):
3131
HEX("#123456789")
@@ -35,7 +35,7 @@ def test_input(self):
3535
HEX(**{"hex_value":"#123456","a":1})
3636

3737
def test_repr(self):
38-
self.assertEqual(repr(self.CreateColor()),"HEX(r=32,g=64,b=128)")
38+
self.assertEqual(repr(self.CreateColor()),'HEX(hex_value="#204080")')
3939

4040
def test_str(self):
4141
self.assertEqual(str(self.CreateColor()),"#204080")

0 commit comments

Comments
 (0)