File: make_test_stubs.py

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (42 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import print_function

import sys, os
from pymol import cmd

def make_test_stubs(module, out=sys.stdout):
    '''
    Utility function to generate a test class for a PyMOL module,
    filled with skipped stub methods.

    Example:

    PyMOL> run make_test_stubs.py
    PyMOL> make_test_stubs pymol.fitting, /tmp/fitting.py
    '''
    if isinstance(module, str):
        __import__(module)
        module = sys.modules[module]

    if isinstance(out, str):
        out = open(out, 'w')

    print('''
from pymol import cmd, testing, stored

class Test%s(testing.PyMOLTestCase):
''' % (module.__name__.split('.')[-1].capitalize()), file=out)

    type_func = type(cmd.align)
    ns = vars(module)
    for name in sorted(ns):
        value = ns[name]
        if isinstance(value, type_func) and \
                value.__module__ == module.__name__ and \
                value == getattr(cmd, name, None):
            nameCap = name.replace('_', ' ').title().replace(' ', '')
            print('    def test%s(self):' % nameCap, file=out)
            print('        cmd.%s' % value.__name__, file=out)
            print('        self.skipTest("TODO")', file=out)
            print('', file=out)

cmd.extend('make_test_stubs', make_test_stubs)