Framework Details

Overview

The quorachallenge module is a framework to assist developers to are taking part in the Quora Python challenges which will posted ocassionally in Python Beginners or Python Programming Quora spaces. The challenges will all require the implementation of a Python function which will meet the specific interface and functionality as required.

The framework provides:
  • immediate access to the description of the challenge
  • the ability to automatically test the function written as an entry to the challenge
  • easy to read test data

Functions

quorachallenge.describe(challenge_name: str, webpage: bool = True, _directory: str = None)

Display the Description of this challenge

Parameters:
  • challenge_name (str) – The lower case name for the challenge.
  • webpage (bool) – When True the description is displayed in a tab in the browser. When False the text is returned in a raw form - rst formatted.
  • _directory (str) – The base local directory to search for this challenge in. Implemented to allow testing of challenges before publication. For Contributor use only.

In normal use the test data is downloaded from a remote site, so this function requires an active public internet connection.

quorachallenge.testdata(challenge_name: str, test_id: str = None, _directory: str = None)

Display the test data for the given challenge

Parameters:
  • challenge_name (str) – The lower case name for the challenge.
  • test_id (str) – The test test_id. If left as the default value this function will display the data for all of the test cases. If it is not None, then this function will display the data for the test case with that test_id.
  • _directory (str) – The base local directory to search for this challenge in. Implemented to allow testing of challenges before publication. For Contributor use only.

In normal use the test data is downloaded from a remote site, so this function requires an active public internet connection.

autotest class

class quorachallenge.autotest(challenge_name, test_id: str = None, defer_results: bool = None, _directory: str = None)

A callable class/decorator, which will automatically test the function against the challenge requirements. By default will immediately report any errors and unexpected exceptions that are raised by the function that is decorated.

Parameters:
  • challenge_name (str) – The case insensitive name for the challenge.
  • test_id (str) – A specific test_id to execute.
  • defer_results (bool) – When False the decorator will immediately report test errors and unexpected exceptions upon completion of the automatic testing. When True the function will be automatically tested but test failures and exceptions are recorded but not automatically reported.
  • _directory (str) – The base local directory to search for this challenge in. Implemented to allow testing of challenges before publication. For Contributor use only.

When defer_results is True, the test failures and exceptions are accessed via the errors and exceptions properties. and the passed property provides a simple True/False report on whether the requested tests completed without errors or unexpected exceptions.

In normal use the test data for the challenge is downloaded from a remote site, so using this function requires an active public internet connection.

Examples :

As a decorator:
@quorachallenge.solves('dummy_challenge')
def dummy( a, b):
    return a +b
Using an explicit instance of the class
def dummy( a, b):
    return a +b

solver=quorachallenge.solves('dummy_challenge', defer_results=True)
passed = solver(dummy)

if not passed:
    print(solver.errors)
    print(solver.exceptions)
autotest.results(test_id)

Return the results for this test test_id if executed

Parameters:test_id (str) – The test test_id to be queried

This methods returns a text string which indicates whether the given test test_id passed successfully, resulted in an return value error, or an unexpected exception.

Returns an empty string if this test test_id has not been executed.