Skip to content

Commit

Permalink
Merge pull request #276 from fonttools/guideline-default-values
Browse files Browse the repository at this point in the history
Bring guideline invariants up to spec
  • Loading branch information
madig authored May 30, 2023
2 parents 4d8a960 + 2345412 commit d2af40a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
file: coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
fail_ci_if_error: false

deploy:
# only run if the commit is tagged...
Expand Down
16 changes: 4 additions & 12 deletions src/ufoLib2/objects/guideline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Guideline(AttrDictMixin):
data composition restrictions.
"""

x: Optional[float] = None
x: float = 0
"""The origin x coordinate of the guideline."""

y: Optional[float] = None
y: float = 0
"""The origin y coordinate of the guideline."""

angle: Optional[float] = None
angle: float = 0
"""The angle of the guideline."""

name: Optional[str] = None
Expand All @@ -36,13 +36,5 @@ class Guideline(AttrDictMixin):
"""The globally unique identifier of the guideline."""

def __attrs_post_init__(self) -> None:
x, y, angle = self.x, self.y, self.angle
if x is None and y is None:
raise ValueError("x or y must be present")
if x is None or y is None:
if angle is not None:
raise ValueError("if 'x' or 'y' are None, 'angle' must not be present")
if x is not None and y is not None and angle is None:
raise ValueError("if 'x' and 'y' are defined, 'angle' must be defined")
if angle is not None and not (0 <= angle <= 360):
if not (0 <= self.angle <= 360):
raise ValueError("angle must be between 0 and 360")
6 changes: 5 additions & 1 deletion tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@
],
},
),
(Guideline(x=0, name="foo"), {"x": 0, "name": "foo"}),
(Guideline(x=0, name="foo"), {"name": "foo"}),
(
Guideline(x=149, y=1523, identifier="aaa"),
{"x": 149, "y": 1523, "identifier": "aaa"},
),
(Guideline(y=1, name="bar"), {"y": 1, "name": "bar"}),
(
Guideline(
Expand Down

0 comments on commit d2af40a

Please sign in to comment.