def test_creating_strength(): """Test creating strength from constitutent values. """ assert strength.create(0, 0, 1) < strength.create(0, 1, 0) assert strength.create(0, 1, 0) < strength.create(1, 0, 0) assert strength.create(1, 0, 0, 1) < strength.create(1, 0, 0, 4) with pytest.raises(TypeError): strength.create('', '', '')
def test_creating_strength(): """Test creating strength from constitutent values. """ assert strength.create(0, 0, 1) < strength.create(0, 1, 0) assert strength.create(0, 1, 0) < strength.create(1, 0, 0) assert strength.create(1, 0, 0, 1) < strength.create(1, 0, 0, 4) with pytest.raises(TypeError): strength.create('', '', '')
def test_creating_strength(): """Test creating strength from constitutent values. """ assert strength.create(0, 0, 1) < strength.create(0, 1, 0) assert strength.create(0, 1, 0) < strength.create(1, 0, 0) assert strength.create(1, 0, 0, 1) < strength.create(1, 0, 0, 4)
def test_constraint_or_operator(): """Test modifying a constraint strength using the | operator. """ v = Variable('foo') c = Constraint(v + 1, '==') for s in ('weak', 'medium', 'strong', 'required', strength.create(1, 1, 0)): c2 = c | s if isinstance(s, str): assert c2.strength() == getattr(strength, s) else: assert c2.strength() == s
def test_constraint_or_operator(): """Test modifying a constraint strength using the | operator. """ v = Variable('foo') c = Constraint(v + 1, '==') for s in ('weak', 'medium', 'strong', 'required', strength.create(1, 1, 0)): c2 = c | s if isinstance(s, str): assert c2.strength() == getattr(strength, s) else: assert c2.strength() == s
def test_constraint_or_operator(): """Test modifying a constraint strength using the | operator. """ v = Variable('foo') c = Constraint(v + 1, u'==') for s in (u'weak', 'medium', 'strong', u'required', strength.create(1, 1, 0)): c2 = c | s if isinstance(s, (type(''), type(u''))): assert c2.strength() == getattr(strength, s) else: assert c2.strength() == s with pytest.raises(ValueError): c | 'unknown'
def test_constraint_or_operator(): """Test modifying a constraint strength using the | operator. """ v = Variable('foo') c = Constraint(v + 1, u'==') for s in (u'weak', 'medium', 'strong', u'required', strength.create(1, 1, 0)): c2 = c | s if isinstance(s, (type(''), type(u''))): assert c2.strength() == getattr(strength, s) else: assert c2.strength() == s with pytest.raises(ValueError): c | 'unknown'
def strong_constraints(self) -> List[Constraint]: """ Return a list of constraints defining the length of the segment """ constraints: List[Constraint] = [] for segment in self: if isinstance(segment, Segment): constraints.extend(segment.strong_constraints) if self.length: # Very strongly try to stay close to the preferred length if self.preferred_length: constraints.append((self.length == self.preferred_length) | strength.create(10, 0, 0)) else: # Try to stay close to the min length a little more strongly constraints.append((self.length == Segment.MIN_LENGTH) | strength.strong) return constraints
# Copyright (c) 2019, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file LICENSE, distributed with this software. #------------------------------------------------------------------------------ """Time updating an EditVariable in a set of constraints typical of enaml use. """ import perf from kiwisolver import Variable, Solver, strength solver = Solver() # Create custom strength mmedium = strength.create(0, 1, 0, 1.25) smedium = strength.create(0, 100, 0) # Create the variable left = Variable('left') height = Variable('height') top = Variable('top') width = Variable('width') contents_top = Variable('contents_top') contents_bottom = Variable('contents_bottom') contents_left = Variable('contents_left') contents_right = Variable('contents_right') midline = Variable('midline') ctleft = Variable('ctleft') ctheight = Variable('ctheight') cttop = Variable('cttop')