Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a flaky test by cleaning a polluted state. #42

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions tests/test_assoccomm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Sequence
from copy import copy

import pytest
from cons import cons
Expand All @@ -21,6 +22,21 @@
from kanren.term import arguments, operator, term


@pytest.fixture(autouse=True)
def clear_assoccomm():
old_commutative_index = copy(commutative.index)
old_commutative_facts = copy(commutative.facts)
old_associative_index = copy(associative.index)
old_associative_facts = copy(associative.facts)
try:
yield
finally:
commutative.index = old_commutative_index
commutative.facts = old_commutative_facts
associative.index = old_associative_index
associative.facts = old_associative_facts


class Node(object):
def __init__(self, op, args):
self.op = op
Expand Down Expand Up @@ -83,9 +99,6 @@ def results(g, s=None):
def test_eq_comm():
x, y, z = var(), var(), var()

commutative.facts.clear()
commutative.index.clear()

comm_op = "comm_op"

fact(commutative, comm_op)
Expand Down Expand Up @@ -326,9 +339,6 @@ def test_eq_assoc():

assoc_op = "assoc_op"

associative.index.clear()
associative.facts.clear()

fact(associative, assoc_op)

assert run(0, True, eq_assoc(1, 1)) == (True,)
Expand Down Expand Up @@ -449,9 +459,6 @@ def test_eq_assoccomm():

ac = "commassoc_op"

commutative.index.clear()
commutative.facts.clear()

fact(commutative, ac)
fact(associative, ac)

Expand Down Expand Up @@ -545,11 +552,6 @@ def test_assoccomm_algebra():
add = "add"
mul = "mul"

commutative.index.clear()
commutative.facts.clear()
associative.index.clear()
associative.facts.clear()

fact(commutative, add)
fact(associative, add)
fact(commutative, mul)
Expand All @@ -565,11 +567,6 @@ def test_assoccomm_algebra():

def test_assoccomm_objects():

commutative.index.clear()
commutative.facts.clear()
associative.index.clear()
associative.facts.clear()

fact(commutative, Add)
fact(associative, Add)

Expand Down