Skip to content

Commit

Permalink
Merge pull request #525 from golemfactory/b0.6-fix-constraints
Browse files Browse the repository at this point in the history
Fix join_str_constraints (#524)
  • Loading branch information
shadeofblue authored Jul 6, 2021
2 parents a8a9654 + bdd22c4 commit e877026
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/payload/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ async def test_payload():
assert builder.properties == {"golem.srv.app.foo.port": 1234}
assert (
builder.constraints
== "((&(golem.runtime.name=foo)\n\t(golem.inf.mem.gib>=32)\n\t(golem.inf.storage.gib>=1024)))"
== "(&(golem.runtime.name=foo)\n\t(golem.inf.mem.gib>=32)\n\t(golem.inf.storage.gib>=1024))"
)
6 changes: 3 additions & 3 deletions tests/props/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ def test_constraint_model_serialize():
(
FooToo,
"!",
"(!((baz=21)))",
"(!(baz=21))",
False,
),
(
FooToo,
"&",
"((baz=21))",
"(baz=21)",
False,
),
(
FooToo,
"|",
"((baz=21))",
"(baz=21)",
False,
),
(
Expand Down
2 changes: 1 addition & 1 deletion tests/props/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class Foo(AutodecoratingModel):
demand = DemandBuilder()
await foo.decorate_demand(demand)
assert demand.properties == {"some.bar": "a nice one"}
assert demand.constraints == "(((baz<=50)))"
assert demand.constraints == "(baz<=50)"
4 changes: 2 additions & 2 deletions yapapi/props/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ def join_str_constraints(constraints: List[str], operator: ConstraintGroupOperat
"""
if operator == "!":
if len(constraints) == 1:
return f"({operator}({constraints[0]}))"
return f"({operator}{constraints[0]})"
else:
raise ConstraintException(f"{operator} requires exactly one component.")

if not constraints:
return f"({operator})"

if len(constraints) == 1:
return f"({constraints[0]})"
return f"{constraints[0]}"

rules = "\n\t".join(constraints)
return f"({operator}{rules})"
Expand Down

0 comments on commit e877026

Please sign in to comment.