Giter Site home page Giter Site logo

mockbrython's Introduction

mockbrython

Mock brython functions for local testing and debugging.

Brython is designed to enable python as a scripting language for the Web. Python scripts are uploaded to a web browser and interpreted by the Brython interpreter that is uploaded along with the python scripts. There are a number of Brython modules that provide web-specific functions to create the web page which are implemented by the interpreter.

When developing applications it is useful to test for syntax errors and debug logic before loading web pages. This small collection of files enables this. They provide a set of dummy modules that mirror the Brython modules, but blank off all the Brython-specific calls to enable the python interpreter to syntax scan the scripts and enable a debugger to exercise the logic. Obviously it doesn't do much for the web-specific part of your design, but it means that the logic is fairly sound when the pages are loaded. Also, an IDE source assistant can use the definitions to prompt for function parameters etc.

At first sight, this is fairly trivial, but it took some effort to get right, so I felt it worth publishing.

The library is installable using pip from PyPI and wont interfere with the Brython interpreter when the pages are uploaded ie

$ pip install mockbrython

This is the recommended method, but if you prefer you can clone this directory to a directory OUTSIDE the script you are developing and add the directory to PYTHONPATH eg

$ export PYTHONPATH=${PYTHONPATH}:${HOME}/mockbrython

then running a script containing brython calls will catch syntax errors without hitting unresolved Brython calls

$ python devel_script.py

The script can also be debugged using idle, our your IDE of choice.

There is a simple example in the examples directory. The script sample.py can be run from examples/index.html, or from the command line as

$ cd ${HOME}/mockbrython/examples ; python test.py

This includes a simulated event (a button click).

The script test/test_mockbrython.py contains all the sample scripts in the section "Brython-specific built-in modules" from the documentation part of the Brython website as a set of test functions. They can be run locally with pytest and can be inspected with a debugger.

mockbrython's People

Contributors

wapringle avatar

Watchers

James Cloos avatar

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.