schrodinger.application.matsci.mstest module

Unit test related functions/classes.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.matsci.mstest.assert_same_struct(struct1, struct2, target_rmsd=0.0, decimal=1, msg=None)

Assert that two structures are almost same.

Parameters
  • struct1 (structure.Structure) – First structure

  • struct2 (structure.Structure) – Second structure

  • target_rmsd (float) – Target RMSD for two structures

  • decimal (int) – The number of decimal places used for comparing the two RMSD floats. In unittest needs to be set fairly loosely so that the tests pass on different OSs

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – when the two struct are not equal within given tolerance

schrodinger.application.matsci.mstest.mmexception_side_effect()

Get an MmException object that can be used as a side effect

Return type

mm.MmException

Returns

returns an mm.MmException object that can be used as a side effect for Mocks

class schrodinger.application.matsci.mstest.MSTestCase(*args, **kwargs)

Bases: unittest.case.TestCase

__init__(*args, **kwargs)

See parent for documentation. When using addTypeEqualityFunc for a new object, always add it to assertAlmostEqual.

numpy_equal(actual, desired, msg=None)

Call numpy equal

assertStructEqual(struct1, struct2, msg=None)

Assert that two structures are equivalent.

Parameters
Raises

AssertionError – when the two structures are not same.

assertStructAlmostEqual(struct1, struct2, target_rmsd=0.0, decimal=1, msg=None)

Assert that two structures are almost same.

Parameters
  • struct1 (structure.Structure) – First structure

  • struct2 (structure.Structure) – Second structure

  • target_rmsd (float) – Target RMSD for two structures

  • decimal (int) – The number of decimal places used for comparing the two RMSD floats. In unittest needs to be set fairly loosely so that the tests pass on different OSs

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – when the two struct are not equal within given tolerance

assertAlmostEqual(actual, desired, decimal=6, msg=None, places=None)

Override assertAlmostEqual with numpy testing assert_almost_equal. Add functionality to test structure and dictionaries as well.

Parameters
  • actual (array_like or dict or structure.Structure) – the object to check

  • desired (array_like or dict or structure.Structure) – the expected object

  • msg (str or None) – message shown if failure occurs

  • decimal (int) – desired precision

  • places (int) – Provided for compatibility with unittest API, which uses the places keyword rather than decimal. If given, will override the decimal value

typeTest(obj_type, actual, desired, msg)

Check if actual and desired are of given type.

Parameters
  • obj_type (any class) – Object type to check actual and desired is of

  • actual (any class) – the actual object to check the type of

  • desired (any class) – the desired object to check the type of

Return bool

True if type of actual and desired is obj_type else False

getCallResult(mocked_function, index=None, key=None, call_number=None, msg=None)

Get the value for the passed argument for the mocked function

Parameters
  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – 0-based index of the argument to compare.

  • argument (str) – Name of the keyword argument

  • call_number (int) – Index of the call made to the function. None means the most recent call, calls are indexed starting at 1.

  • msg (str or None) – message shown if failure occurs

Return list or tuple or dict or set or frozenset or str

value for the passed argument for the mocked function

Raises

AssertionError – the mocked fuction was not called with input index or argument.

assertCallEqual(actual, mocked_function, index=None, argument=None, call_number=None, msg=None)

Check if the actual value is equal to value that the mocked fuction was called with.

Parameters
  • actual – actual value of the mock call to compare to

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – index of the argument to compare

  • argument (str) – name of the keyword argument

  • call_number (int or None) – Number of the call made to the function. If none the last call will be taken and 1 will be oldest (first) call

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – If actual value is not equal to value that the mocked fuction was called with or the fuction was not called with input index/argument.

assertCallNotEqual(actual, mocked_function, index=None, argument=None, call_number=None, msg=None)

Check if the actual value is not equal to value that the mocked fuction was called with.

Parameters
  • actual – actual value of the mock call to compare to

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – Index of the argument to compare

  • argument (str) – Name of the keyword argument

  • call_number (int or None) – Number of the call made to the function. If none the last call will be taken and 1 will be oldest (first) call

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – If actual value is equal to value that the mocked fuction was called with or the fuction was not called with input index/argument.

assertCallIn(actual, mocked_function, index=None, argument=None, call_number=None, msg=None)

Check if the actual value is in the container that the mocked fuction was called with.

Parameters
  • actual – value to check if it was in the call argument

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – Index of the argument to compare

  • argument (str) – Name of the keyword argument

  • call_number (int or None) – Number of the call made to the function. If none the last call will be taken and 1 will be oldest (first) call

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – If actual value is not in to value that the mocked fuction was called with or the fuction was not called with input index/argument.

assertCallNotIn(actual, mocked_function, index=None, argument=None, call_number=None, msg=None)

Check if the actual value is not in the container that the mocked fuction was called with.

Parameters
  • actual – value to check if it was not in the call argument

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – Index of the argument to compare

  • argument (str) – Name of the keyword argument

  • call_number (int or None) – Number of the call made to the function. If none the last call will be taken and 1 will be oldest (first) call

Raises

AssertionError – If actual value is not in to value that the mocked fuction was called with or the fuction was not called with input index/argument.

assertCallAlmostEqual(actual, mocked_function, index=None, argument=None, call_number=None, msg=None, decimal=6)

Check if the actual value is equal to value that the mocked fuction was called with.

Parameters
  • actual (list or tuple or dict or set or frozenset or str) – actual value of the mock call to compare to

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • index (int) – Index of the argument to compare

  • argument (str) – Name of the keyword argument

  • call_number (int or None) – Number of the call made to the function. If none the last call will be taken and 1 will be oldest (first) call

  • msg (str or None) – message shown if failure occurs

  • decimal (int) – desired precision

Raises

AssertionError – If actual value is not equal (within the decimal places) to value that the mocked fuction was called with or the fuction was not called with input index/argument.

assertCalledTimes(times, mocked_function, msg=None)

Check if the mocked fuction was called passed number of times

Parameters
  • times (int) – number of times mocked_function was called

  • mocked_function (unittest.mock.MagicMock) – mocked function which was called

  • msg (str or None) – message shown if failure occurs

Raises

AssertionError – If the mocked fuction was not called the passed amount of time

assertFlag(cmd, flag, value=None, is_in=True)

Check that an expected flag is in (or not in) the command line list and also check the value of that flag. Note that the language used here is for the command line, but this function works for any sequence where one might want to simultaneously check the ith and i+1th values together.

Examples:

self.assertFlag(cmd, ‘-gpu’) self.assertFlag(cmd, ‘-HOST’, value=’bolt_personal:5’) self.assertFlag(cmd, ‘-nosystem’, is_in=False)

Parameters
  • cmd (list) – The list to check

  • flag – The item to check if it is in cmd (may be any type)

  • value – If given, the item following flag will be checked to see if it is equal to value.

  • is_in (bool) – If true, checks if flag is in cmd. If False, checks that flag is not in cmd, and value is ignored.

Raises

AssertionError – If flag violates the is_in setting, or if value is given and does not match the item after flag.

assertTableContentsEqual(table, expected_contents, expected_column_headers=None)

Assert that the actual table contents match the expected ones. Optionally checks table headers too.

Parameters
  • table (QtWidgets.QTableWidget) – The table to get actual contents from

  • expected_contents (list) – List of lists containing the desired data in the table. Each inner list has the contents of a row.

  • expected_column_headers (list) – If not None, the column headers in the table will be compared with this list

Raises

AssertionError – If the contents are not equal

assertStageEqual(stage1, stage2)

Assert that the two desmond stages are equal.

Parameters
Raises

AssertionError – If the contents are not equal

schrodinger.application.matsci.mstest.matsci_scripts_testfile(path)

Get the full path to the test file at mmshare/python/test/matsci/path

Parameters

path (str) – Relative path of file

Return type

str

Returns

Full path to file

schrodinger.application.matsci.mstest.matsci_application_testfile(path)

Get the full path to the test file at mmshare/python/test/application/matsci/path

Parameters

path (str) – Relative path of file

Return type

str

Returns

Full path to file

schrodinger.application.matsci.mstest.load_structure(filename)

Load the first structure from the given file in the testfile directory where structures are stored

Parameters

filename (str) – The name of the structure file

Return type

structure.Structure

Returns

The first structure in filename

schrodinger.application.matsci.mstest.mock_json_load_from_fh(module, contents_dict)

Context manager to mock json.load on a file handle in the given module and return the given contents dictionary.

Parameters
  • module (module) – the module using open and json

  • contents_dict (dict) – the contents dictionary

schrodinger.application.matsci.mstest.set_wa_dont_show_on_screen(widget)

Sets WA_DontShowOnScreen attribute to True for the given widget

Parameters

widget (QWidget) – The widget whose WA_DontShowOnScreen attribute is to be set.

schrodinger.application.matsci.mstest.set_feature_flag(flag, state)

Set feature flag to a requested state and yield.

Parameters
  • flag (str or int) – mmutil constant for the feature flag or name

  • state (bool) – Whether feature flag should be enabled or disabled

schrodinger.application.matsci.mstest.ms_use_rdkit_ff_helper(state)

Yield with MS_USE_RDKIT feature flag set to state.

Parameters

state (bool) – Whether feature flag should be enabled or disabled

schrodinger.application.matsci.mstest.cycle_feature_flag(flag)

Loop over a feature flag being turned on and off (On first, Off second)

Parameters

flag (int or str) – mmutil constant for the feature flag (int) or name (str)

Ytype

bool

Yields

The current flag state