Skip to content

Commit c0cc3fb

Browse files
ilaifMidnighter
authored andcommitted
[FIX] color serialization
1 parent 8880089 commit c0cc3fb

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/structurizr/view/element_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from typing import Optional
2020

2121
from pydantic import Field
22-
from .color import Color
2322

2423
from ..abstract_base import AbstractBase
2524
from ..base_model import BaseModel
2625
from .border import Border
26+
from .color import Color
2727
from .shape import Shape
2828

2929

src/structurizr/view/relationship_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from typing import Optional
2020

2121
from pydantic import Field
22-
from .color import Color
2322

2423
from ..abstract_base import AbstractBase
2524
from ..base_model import BaseModel
25+
from .color import Color
2626
from .routing import Routing
2727

2828

tests/test_unit/view/test_color.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2020, Moritz E. Beber.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
"""Ensure the expected behaviour of the code element."""
17+
18+
19+
import pydantic
20+
import pytest
21+
22+
from structurizr.view.color import Color
23+
24+
25+
@pytest.mark.parametrize(
26+
"color",
27+
[
28+
{"value": "#ffffff", "expected": "#ffffff"},
29+
{"value": "#fff", "expected": "#ffffff"},
30+
{"value": "#f0f0f0", "expected": "#f0f0f0"},
31+
{"value": "#000", "expected": "#000000"},
32+
{"value": "#000000", "expected": "#000000"},
33+
{"value": "green", "expected": "#008000"},
34+
{"value": "white", "expected": "#ffffff"},
35+
pytest.param(
36+
{"value": "never-gonna-let-you-down", "expected": None},
37+
marks=pytest.mark.raises(
38+
exception=pydantic.errors.ColorError,
39+
message=(
40+
"value is not a valid color: string not "
41+
"recognised as a valid color"
42+
),
43+
),
44+
),
45+
],
46+
)
47+
def test_code_element_init(color):
48+
"""Expect proper initialization from arguments."""
49+
assert str(Color(color["value"])) == color["expected"]

0 commit comments

Comments
 (0)