schrodinger.application.msv.test_helpers module

class schrodinger.application.msv.test_helpers.AlignmentInfo(seqs=(), locked_columns=(), potential_reordering=None)

Bases: object

class schrodinger.application.msv.test_helpers.RuleBasedStateMachineMetaClass

Bases: type

A metaclass that makes it easy to create simple rules for a RuleBasedStateMachine.

‘Simple’ in this context means that the rule we want to create
  1. calls a method that takes no argument, and then
  2. doesn’t check any results

The only thing that we’re testing with a rule like this is that calling the method never results in an unhandled exception. Ideally, we would check the results of calling methods, but even the lazy route is surprisingly useful in a state machine test. Advice: begin by adding as many of these simple rules as possible and then gradually replace them with richer rules and checks as the tests develop and experience indicates which checks are most valuable.

Suppose that we are testing self.panel in our state machine and want to call the methods ‘foo’ on self.panel.bar and ‘gar’ on self.panel.mar. We could write this:

class PanelMachine(stateful.RuleBaseStateMachine):
def __init__(self):
super(PanelMachine, self).__init__() self.panel = MyPanel()

@stateful.rule() def foo(self):

self.panel.bar.foo()

@stateful.rule() def gar(self):

self.panel.mar.gar()

But this quickly becomes tedious if we want to test a large number of such methods. Our metaclass will allow us to generate the desired rules for our state machine by adding strings to the SIMPLE_RULES tuple defined on the class:

@six.add_metaclass(RuleBasedStateMachineMetaClass) class PanelMachine(stateful.RuleBaseStateMachine):

SIMPLE_RULES = (‘panel.bar.foo’, ‘panel.bar.gar’)

def __init__(self):
super(PanelMachine, self).__init__() self.panel = MyPanel()
schrodinger.application.msv.test_helpers.alignment_info_strategy()

Returns everything we need to create an alignment

We return an alignment_info instead of an alignment in order to allow tests to create different kinds of alignments and also to pass along additional test data customized to the alignment that the test will create. For example, a potential_reordering will be a reordering that should work with the alignment, etc., etc.

Return type:AlignmentInfo
Returns:A test fixture for alignment tests
schrodinger.application.msv.test_helpers.generated_residues()
Parameters:draw (function) – A function supplied by hypothesis
Return type:schrodinger.protein.residue.Residue
Returns:A residue suitable for testing
schrodinger.application.msv.test_helpers.generated_sequences()
Parameters:draw (function) – A function supplied by hypothesis
Return type:schrodinger.protein.sequence.ProteinSequence
Returns:A protein sequence suitable for testing
schrodinger.application.msv.test_helpers.make_alignment(AlnClass, aln_info, patch=True)

Given an alignment class and information to populate an instance returns an instance of an alignment

Parameters:
  • AlnClass (type) – An alignment class
  • aln_info (AlignmentInfo) – Information to populate the instance
  • patch (bool) – Whether to patch the signals on the alignment instance
Returns:

A ProteinAlignment instance.

schrodinger.application.msv.test_helpers.patch_signals(obj)

Patch all the signals on the given object with MagicMocks.

Parameters:obj (object) – The object whose signals we want to patch
schrodinger.application.msv.test_helpers.qcolor_strategy()
Return type:QtGui.QColor
Returns:A QtColor instance to be used in a test
schrodinger.application.msv.test_helpers.sample_indices(draw, list_length)

Convenience function that returns a subset of indices in a list, given a hypothesis draw function and the length of the list.

Parameters:
  • draw (function) – A function supplied by hypothesis
  • list_length (int) – The length of the list to get a subset of