GithubHelp home page GithubHelp logo

pymol-testing's Introduction

PyMOL Testing Framework

This is a python unittest based testing framework for PyMOL.

Notice: "gui" tests currently don't work with PyMOL 2.x, tests should be run with "pymol -c ...".

How to Run Tests

From the system command line:

pymol -cq /path/to/pymol-testing/runall.pml

From the pymol command line:

PyMOL> run /path/to/pymol-testing/testing.py
PyMOL> run_testfiles path/to/*.py

How to write Tests

A test is a method of a pymol.testing.PyMOLTestCase subclass and is named
with a "test" prefix. Test files go into subdirectories like "api/" or "performance/". Each test method will start

  • with a clean PyMOL session (does reinitialize)
  • from the directory of its file (does os.chdir)

Decorators

  • @testing.requires(keyword): Takes one or more keywords and skips the test, if the requirement is not met. Valid keywords include: gui, incentive, network, no_run_all, multicore
  • @testing.foreach(args1, args2, ...): Decorates a test method which takes arguments

Context Managers

  • PyMOLTestCase.timing(max=sec): Gives feedback on running time and makes the test fail if it takes longer than max seconds.
  • PyMOLTestCase.mktemp(): Generates a temporary file name and deletes the file at context exit.

Assertion Methods

In addition to the standard assertion methods of the unittest.TestCase class, these assertion methods are currently available:

  • assertImageEqual(img1, img2=None, delta=0): Takes two images (as filenames, PIL objects or numpy arrays). If only one image is given, grab the current PyMOL scene as second imagae
  • assertImageHasColor(color, img=None, delta=0): Takes a color name, RGB or RGBA color tuple and an image (or grab the current scene) and check if it contains the given color
  • assertImageHasNotColor
  • assertImageHasTransparency
  • assertImageHasNoTransparency
  • assertColorEqual
  • assertArrayEqual
  • assertArrayNotEqual

Code Example

from pymol import cmd, testing, stored

class TestSomething(testing.PyMOLTestCase):

    def testFoo(self):
        cmd.fragment('ala')
        cmd.show_as('sticks')
        cmd.orient()
        self.assertImageEqual('ref-foo.png')

    @testing.requires('gui')
    def testBar(self):
        cmd.some_opengl_feature()

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.