datacamp / pythonwhat

Verify Python code submissions and auto-generate meaningful feedback messages.
http://pythonwhat.readthedocs.io/
GNU Affero General Public License v3.0
67 stars 31 forks source link

`test_for_loop()` within this `test_function_definition()`: BLOCK BETA 09/23 #92

Closed hugobowne closed 7 years ago

hugobowne commented 7 years ago

I am trying to write an SCT for the solution code below (see my SCT attempt below it).

I cannot figure out how to test_for_loop() within this test_function_definition(). Probably related to my not understanding test_expression_result() see #91. But also because I am having problems with extra_env and context_vals with **kwargs here (I think!).

# Define report_status
def report_status(**kwargs):
    """Print out the status of a movie character."""

    print("\nBEGIN: REPORT\n")

    # Print a formatted status report
    for key, value in kwargs.items():
        print(key + ": " + value)

    print("\nEND REPORT")

# First call to report_status()
report_status(name="luke", affiliation="jedi", status="missing")

# Second call to report_status()
report_status(name="anakin", affiliation="sith lord", status="deceased")

*\ =sct

# All functions used here are defined in the pythonwhat Python package.
# Documentation can also be found at github.com/datacamp/pythonwhat/wiki

def inner_test():
    #context=[{'name':"luke", 'affiliation':"jedi", 'status':"missing"}]
    test_function("print", index=1)

# Test: report_status() definition
test_function_definition(
    "report_status", body=inner_test,
    outputs = [{'args': [], 'kwargs': {'name':"hugo", 'affiliation':"datacamp"}}]
)
filipsch commented 7 years ago

The problem was that for the for_iter test in test_for_loop(), the context_vals for inside the for loop were already used, i.e. key and value. This was not wanted, because when defining the sequence over which to iterate, you're still in 'another context'.

I've coded a fix, after which the following SCT will work:

def inner_test():
    test_function("print", index=1)

    def iter_test():
        context=[{'name':"luke", 'affiliation':"jedi", 'status':"missing"}]
        test_expression_result(context_vals = context)

    def body_test():
        context=['name', 'luke']
        test_expression_output(context_vals = context)

    test_for_loop(for_iter = iter_test, body = body_test)
    test_function("print", index=2)

# Test: report_status() definition
test_function_definition(
    "report_status", body=inner_test,
    outputs = [{'args': [], 'kwargs': {'name':"hugo", 'affiliation':"datacamp"}}])

I'll close this issue as soon as the fix is deployed (will do asap).

hugobowne commented 7 years ago

thx!

hugobowne commented 7 years ago

ETA? :-D

filipsch commented 7 years ago

before the end of today, @machow is handling it. @machow, can you close as soon as it's live?

filipsch commented 7 years ago

it's live.

hugobowne commented 7 years ago

works! thx @machow & @filipsch