Skip to content

Commit

Permalink
Merge pull request #3282 from teunhoevenaars/auto-layout_test_fix
Browse files Browse the repository at this point in the history
Re-enable auto-layout tests
  • Loading branch information
danyeaw committed May 1, 2024
2 parents c2a14b9 + 3ab47dd commit e5db41a
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions tests/test_auto_layouting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import itertools
from typing import Iterable

import pytest
import hypothesis
from hypothesis import settings
from hypothesis.control import assume, cleanup
from hypothesis.errors import UnsatisfiedAssumption
from hypothesis.stateful import (
RuleBasedStateMachine,
initialize,
invariant,
rule,
run_state_machine_as_test,
)
from hypothesis.strategies import data, integers, sampled_from

Expand Down Expand Up @@ -45,14 +44,6 @@
)


@pytest.mark.skip(
reason="This test takes too long since Hypothesis 6.68.1 and should be refactored"
)
@pytest.mark.hypothesis
def test_auto_layouting():
run_state_machine_as_test(AutoLayouting)


def tooldef():
return sampled_from(
list(
Expand All @@ -79,7 +70,19 @@ def tooldef():
)


class AutoLayouting(RuleBasedStateMachine):
def ordered(elements: Iterable[Element]) -> list[Element]:
return sorted(elements, key=lambda e: e.id)


def relations(diagram):
relations = [
p for p in diagram.presentation if isinstance(p, diagramitems.DependencyItem)
]
assume(relations)
return sampled_from(ordered(relations))


class AutoLayOuting(RuleBasedStateMachine):
@property
def model(self) -> ElementFactory:
return self.session.get_service("element_factory") # type: ignore[no-any-return]
Expand All @@ -97,15 +100,6 @@ def select(self, expression=None):
assume(elements)
return sampled_from(elements)

def relations(self, diagram):
relations = [
p
for p in diagram.presentation
if isinstance(p, diagramitems.DependencyItem)
]
assume(relations)
return sampled_from(ordered(relations))

def targets(self, relation, handle):
return self.select(
lambda e: isinstance(e, diagramitems.ClassItem)
Expand Down Expand Up @@ -147,7 +141,7 @@ def try_connect_relation(self, data, item, handle):

@rule(data=data())
def connect_relation(self, data):
relation = data.draw(self.relations(self.diagram))
relation = data.draw(relations(self.diagram))
handle = data.draw(sampled_from([relation.head, relation.tail]))
self._connect_relation(data, relation, handle)

Expand All @@ -168,10 +162,14 @@ def change_owner(self, data):
tx.rollback()
assume(changed)

@invariant()
def check_auto_layout(self):
def teardown(self):
self.auto_layout.layout(self.diagram)


def ordered(elements: Iterable[Element]) -> list[Element]:
return sorted(elements, key=lambda e: e.id)
AutoLayOuting.TestCase.settings = settings(
max_examples=5,
stateful_step_count=30,
deadline=2000,
phases=[hypothesis.Phase.generate],
)
TestAutoLayOuting = AutoLayOuting.TestCase

0 comments on commit e5db41a

Please sign in to comment.