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

Testing comprehensions: block beta testing 08/17 #60

Closed hugobowne closed 7 years ago

hugobowne commented 7 years ago

We'll need to test comprehensions (list/dict/set); e.g. for

doctor = ['house', 'cuddy', 'chase', 'thirteen', 'wilson']

we will need an SCT for

x = [doc[0] for doc in doctor]

Also conditional comps such as

x = [doc[0] for doc in doctor if doc[1] == 'h']

and nested comps! ;-)

filipsch commented 7 years ago

Hi @hugobowne I'll look into this this week. Could you be a bit more specific as to what you steps want to test:

hugobowne commented 7 years ago

@filipsch great question. I like to think of comprehensions as being really cool for loops that potentially contain other control flow statements. There is much information condensed in comprehensions so there are many things to test.

I will refer to the following example below:

x = [doc[0] for doc in doctor if doc[1] == 'h']

We need to test the following:

  1. Did they use a comprehension?
  2. Did they use the correct iterable (e.g. doctor above)?
  3. Did they use the correct iterator variable (e.g. doc above)? (we want to test this only sometimes, i.e. when we specify the iterator in the instructions);
  4. Did they use the correct output expression (e.g. doc[0] above)?
  5. Did they use the correct conditional on the iterable (e.g. if doc[1] == h above)?
  6. Did they use the correct conditional on the output expression (e.g. if len(member) >= 7 else '' in the example below)?

As we need to test conditionals, might it make sense to have test_if_else tests embedded in test_comprehension tests? A thought.

Whatever happens, I am pumped for this!!

filipsch commented 7 years ago

@hugobowne Thanks for this detailed step-by-step guide, this is the way to go for future issues!

To embed test_if_else() inside a comprehension, I'll provide a body test, so that you can pass a 'sub-SCT' to check the body of the list comprehension, just like with test_lambda_function() and test_function_definition(). You're free to use any sct functions in there.

As I said, I am currently working on revising the entire internal workings of pythonwhat so that plots are no longer messed up; I'll try to work on this Monday August 15.

filipsch commented 7 years ago

@hugobowne Due to delays in rolling out the new python backend this functionality probably won't be available by the time you want to do beta testing. For the moment, I'd work with 'indirect SCTs', i.e. using for example test_object() to see if the correct object was created with list comprehension. I'll let you know when test_list_comprehension() is implemented and live.

hugobowne commented 7 years ago

@filipsch thanks for the update. I'll think about this. My initial intuition says to wait to until test_list_comp is live to beta test. The reason is that I have an entire chapter on list comps & generators (plus a large portion of the final case study chapter); the point of the chapter is teaching them

[output expression + conditional for iterator variable in iterable + conditional]

I build up these components and need to provide tailored feedback on each component.

What is new ETA on test_list_comp?

filipsch commented 7 years ago

@hugobowne hard to say. Depends on how fast we can roll out the new version of pythonwhat. I'd say end of week at the latest, is that acceptable?

hugobowne commented 7 years ago

@filipsch definitely acceptable! :-D

filipsch commented 7 years ago

@hugobowne functionality has been written, it's under review now and will go live with the big update of pythonwhat, hopefully beginning of next week. You can already read up on it in the wiki: https://github.com/datacamp/pythonwhat/wiki/test_comprehension If I close this issue, this means the feature will be available on production.