/codewars-client

A python script that provides a cli interface to codewars.com. Because noone should have to write code in a browser.

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

codewars

A python script that provides a cli interface to codewars.com. Because noone should have to write code in a browser. Currently focuses only on JavaScript katas.

Requirements

  • Python 3
  • Mocha (optional: for running the tests locally)

Usage

For basic information on how to use the program run:

$ codewars.py -h

Setup

Create a file that contains your personal api key. You can find this key in ‘Account settings’ on codewars. By default, codewars-client looks for a file called api_key.txt in the current directory.

Basic

Basic process comes down to:

  1. Get new kata with: $ codewars.py next
  2. Write code and tests
  3. Attempt solution with: $ codewars.py submit
  4. If it passes, finalize with: $ codewars.py finalize

Tests

One of the nice things about codewars is that it encourages TDD. It does this by providing some tests to start out with (called ‘example fixtures’ by codewars) and by providing the user with an easy way to run them in the browser. Ofcourse we’re not using the browser so that’s a problem. In order to run the tests codewars-cli provides some help to run the tests locally with Mocha. It adds a preamble to the tests and it converts codewars’ Test.* calls to Nodejs Assert.* calls. This translation does not provide perfectly equivalent tests, but it should be good enough for this purpose.

The only other thing that needs to be done is exporting the necessary functions in the solutions file. This can easily be done by appending:

module.exports.some_function = some_function

to the solution file.

Tests can then be run with:

$ mocha tests.js
  removeValue
    ✓ should remove integers
    ✓ should remove all integers
    ✓ should return false when no integer can be removed
    ✓ should remove strings
    ✓ should return false when no string can be removed
    ✓ should not confuse strings with integers
    ✓ should return false when the array is empty


  7 passing (17ms)