Getting Started - Using the Framework

The Quora challenge framework is very easy to use and can do 3 main useful things :

Note

The quorachallenge framework relies heavily on being able to download data and descriptions from the public internet, so you need to ensure you have a working network connection when using the framework.

Note

This documentation regularly uses the name ‘challenge1’ as the name of the challenge being solved and tested. This name is just an example for the sake of the documentation. The challenge name you need to use for any given challenge will be stated clearly on the post on Quora that describes the challenge - so make sure you use the right name. When new challenges are posted there will be no need to install a new version of the framework - just use the new name.

To get the challenge Description

To get a description of the challenge (in this case ‘challenge1’) use the describe function.

>>> import quorachallenge
>>> quorachallenge.describe('challenge1')

This code snippet will open a new web browser tab or window and display the description of the challenge.

Automatically test your function

To test your function which you think solves a given challenge use the AutoTest Decorator.

Imagine we have written function my_func to solve ‘challenge1’

import quorachallenge

@quorachallenge.autotest('challenge1')
def my_func(a, b):
    return a+b

This code will automatically test my_func against all of the test cases defined for this challenge, and report any errors or exceptions that occur during the testing. The displayed messages will identify the test case id that failed and some details of the failure.

The AutoTest Decorator can also be used in a more indirect way as shown in this example

>>> import quorachallenge as qc
        ...
>>> tester = qc.autotest('challenge1', defer_results=True)
>>> passed = tester(func)
>>> passed
False
>>> print('\n'.join(tester.errors))
Test 500 - Incorrect result : Expected (0) != Returned (1)
>>> tester.results('500')
'Test 500 - Incorrect result : Expected (0) != Returned (1)'

The AutoTest Decorator can also be passed a specific test id, so as to repeat just that single test case. This can be very useful in debugging failures.

Display testdata

To display the test data for a given challenge use the testdata function.

>>> import quorachallenge
>>> quorachallenge.testdata('challenge1',test_id='500')
------
Id : 500
Called as : your_function(0,0)
Expected to return : 0

This code snippet will display all the test data that exists for ‘challenge1’. There is an optional 2nd argument to the testdata function that allows you to select the test data for just a single test case :

import quorachallenge

quorachallenge.testdata('challenge1', '1')

This code snippet will display just the test data for the test case with id ‘1’; this will be useful if your code is failing one particular test case.

When looking at the test data as displayed from this function :

Id
The id of this tests case
called as
how the function will be called for this test case
Raises
The Exception that the function should raise under this test case
Returns
The expected return value for this test case

For any given test case, there will be either an expected Return value, or an expected Exception listed but not both.