Git Product home page Git Product logo

Comments (7)

filipsch avatar filipsch commented on September 24, 2024

@hugobowne This is tricky stuff.
test_function() handles arguments and keywords differently: arguments are specified by position, keywords are specified by name.
So if you use open('moby_dick.txt', 'r') in your solution, test_function() will see that there are two positional arguments, with indices 0 and 1. It then looks for those same arguments in the student code; if the student specified the args in the same way, it's all good, if it did so with open('moby_dick.txt', mode = 'r'), the student used a keyword and an argument, and thus fails.

There's no easy fix for this. In R (testwhat), there's the match.call function, that 'standardizes' a function call, so that you don't have to figure this all out yourself. For Python, something like that does not exist, and it is very hard to build something like this.

Your workaround with test_correct() is elegant, but you're right that test_function() by itself should be robust to different ways of calling a function.

from pythonwhat.

hugobowne avatar hugobowne commented on September 24, 2024

@filipsch

there are other issues i just realised. To recap:

This is the solution code: file = open('moby_dick.txt', mode='r') -- I need to write an SCT that accepts it and also accepts file = open('moby_dick.txt', 'r').

We have a workaround mentioned above. However, this workaround also accepts
file = open('moby_dick.txt'), which is not ideal. I tried playing around with test_student_typed but there were issues there, as raised in in this issue.

Do you have any suggestions for this?

Could we use some cool multi-arg tests once we sort out this issue?

I could see us using a test_or on specific arguments to allow both 'r' and mode='r' as 2nd arg, in this case. The problem is this would not scale well with many args.

As you realise, this is an issue that occurs a lot in all courses.

Do you have any thoughts on this?

from pythonwhat.

hugobowne avatar hugobowne commented on September 24, 2024

@filipsch see comment/question above. any suggestions? sorry if this has been answered in another issue. I'll happily also raise this as another issue if you want me to

from pythonwhat.

filipsch avatar filipsch commented on September 24, 2024

There are a lot of question in the message of 9 days ago.

  • The issue with test_student_typed() is resolved, so you could try to use that.
  • You cannot use test_or() because test_function() still looks for corresponding function calls in the solution code; this would mean that you have to list the two ways of opening the file explicitly in the solution code, which is not what you want.
  • The multi-arg custom feedback is working now (although the way of writing is suboptimal), but I'm not sure if it's relevant here.

The big problem is: pythonwhat sees a difference between arguments and keywords, while Python allows you to use both in many cases, and that's a huge pain. I'm working on a test_function_v2 wher e you have to list the arguments expicitly, and where there is robustness against different ways of specifying arguments. As soon as that is there, it'll all be implicit when you simply use test_function_v2.

from pythonwhat.

filipsch avatar filipsch commented on September 24, 2024

@hugobowne A first version of functionality that matches arguments and keywords in a robust way, is now available on staging, soon on master. The function is called test_function_v2. If still have to write documentation for it on the wiki.

from pythonwhat.

filipsch avatar filipsch commented on September 24, 2024

test_function_v2() has been documented here, function will be on production later today.

from pythonwhat.

filipsch avatar filipsch commented on September 24, 2024

It's live. Read about it here

from pythonwhat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.