Skip to content

Commit 947bc7c

Browse files
author
Filip Schouwenaars
authored
Merge pull request #177 from datacamp/fix-spec-logic
allow test_or and test_correct to use check funcs #176
2 parents a31a1a2 + 8ba429b commit 947bc7c

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

pythonwhat/check_syntax.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def Ex():
9696
# allow test_* functions as chained attributes
9797
for k in TEST_NAMES:
9898
ATTR_SCTS[k] = Probe(tree = None, f = getattr(test_funcs, k), eval_on_call=True)
99+
# original logical test_* functions behave like multi, test_not
100+
# this is necessary to allow them to take check_* funcs as args
101+
# since probe behavior will try to call all SCTs passed (assuming they're also probes)
102+
for k in ['test_or', 'test_correct']:
103+
ATTR_SCTS[k] = multi_dec(getattr(test_funcs, k))
99104

100105
# Prepare check_funcs to be used alone (e.g. test = check_with().check_body())
101106
spec_2_context = {k : state_dec(v) for k, v in scts.items()}

tests/test_test_correct.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def test_Pass2_no_lam(self):
5151
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"])
5252
self.test_Pass2()
5353

54+
def test_Pass2_spec2(self):
55+
self.data["DC_SCT"] = "Ex().test_correct(check_object('test').has_equal_value(), test_function('numpy.sum'))"
56+
self.test_Pass2()
57+
58+
def test_Pass2_spec2_F(self):
59+
self.data["DC_SCT"] = """
60+
test = F().test_correct(check_object('test').has_equal_value(), test_function('numpy.sum'))
61+
Ex().multi(test)
62+
"""
63+
self.test_Pass2()
64+
5465
def test_Fail2_mix_lam(self):
5566
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"], count=1)
5667
self.test_Fail2()

tests/test_test_or.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def test_Pass4_no_lam(self):
4444
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"])
4545
self.test_Pass4()
4646

47+
def test_Pass4_spec2(self):
48+
self.data["DC_SCT"] = "Ex().test_or(test_function('print'), check_object('test'))"
49+
self.test_Pass4()
50+
4751
def test_Fail1_no_lam(self):
4852
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"])
4953
self.test_Fail1()

0 commit comments

Comments
 (0)