pluto.tools.PlutoTestCase¶
- class pluto.tools.PlutoTestCase(methodName='runTest')[source]¶
An all-in-one unittest.TestCase wrapper class that includes a tmpdir, CWLRunner, and other helper functions, to make it easier to create and run unit tests and integration tests for CWL workflows
Note
For usage examples, see https://github.com/mskcc/pluto-cwl/tree/master/tests
Examples
Example usage:
class TestAddImpactCWL(PlutoTestCase): cwl_file = CWLFile('add_af.cwl') def test_add_af(self): '''Test that the af col gets calculated and added to the maf file correctly''' maf_lines = [ ['# comment 1'], ['# comment 2'], ['Hugo_Symbol', 't_depth', 't_alt_count'], ['SUFU', '100', '75'], ['GOT1', '100', '1'], ['SOX9', '100', '0'], ] input_maf = self.write_table(tmpdir = self.tmpdir, filename = 'input.maf', lines = maf_lines) self.input = { "input_file": { "class": "File", "path": input_maf }, "output_filename": 'output.maf', } output_json, output_dir = self.run_cwl() expected_output = { 'output_file': { 'location': 'file://' + os.path.join(output_dir, 'output.maf'), 'basename': 'output.maf', 'class': 'File', 'checksum': 'sha1$39de59ad5d736db692504012ce86d3395685112e', 'size': 109, 'path': os.path.join(output_dir, 'output.maf') } } self.assertDictEqual(output_json, expected_output) comments, mutations = self.load_mutations(output_json['output_file']['path']) expected_comments = ['# comment 1', '# comment 2'] self.assertEqual(comments, expected_comments) expected_mutations = [ {'Hugo_Symbol': 'SUFU', 't_depth': '100', 't_alt_count':'75', 't_af': '0.75'}, {'Hugo_Symbol': 'GOT1', 't_depth': '100', 't_alt_count':'1', 't_af': '0.01'}, {'Hugo_Symbol': 'SOX9', 't_depth': '100', 't_alt_count':'0', 't_af': '0.0'} ] self.assertEqual(mutations, expected_mutations)
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- __init__(methodName='runTest')¶
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
Methods
__init__
([methodName])Create an instance of the class that will use the named test method when executed.
addCleanup
(**kwargs)Add a function, with arguments, to be called when the test is completed.
addTypeEqualityFunc
(typeobj, function)Add a type specific assertEqual style function to compare a type.
assertAlmostEqual
(first, second[, places, …])Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
assertAlmostEquals
(**kwargs)assertCountEqual
(first, second[, msg])An unordered sequence comparison asserting that the same elements, regardless of order.
assertDictContainsSubset
(subset, dictionary)Checks whether dictionary is a superset of subset.
assertDictEqual
(d1, d2[, msg])assertEqual
(first, second[, msg])Fail if the two objects are unequal as determined by the ‘==’ operator.
assertEquals
(**kwargs)assertFalse
(expr[, msg])Check that the expression is false.
assertGreater
(a, b[, msg])Just like self.assertTrue(a > b), but with a nicer default message.
assertGreaterEqual
(a, b[, msg])Just like self.assertTrue(a >= b), but with a nicer default message.
assertIn
(member, container[, msg])Just like self.assertTrue(a in b), but with a nicer default message.
assertIs
(expr1, expr2[, msg])Just like self.assertTrue(a is b), but with a nicer default message.
assertIsInstance
(obj, cls[, msg])Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
assertIsNone
(obj[, msg])Same as self.assertTrue(obj is None), with a nicer default message.
assertIsNot
(expr1, expr2[, msg])Just like self.assertTrue(a is not b), but with a nicer default message.
assertIsNotNone
(obj[, msg])Included for symmetry with assertIsNone.
assertLess
(a, b[, msg])Just like self.assertTrue(a < b), but with a nicer default message.
assertLessEqual
(a, b[, msg])Just like self.assertTrue(a <= b), but with a nicer default message.
assertListEqual
(list1, list2[, msg])A list-specific equality assertion.
assertLogs
([logger, level])Fail unless a log message of level level or higher is emitted on logger_name or its children.
assertMultiLineEqual
(first, second[, msg])Assert that two multi-line strings are equal.
assertNotAlmostEqual
(first, second[, …])Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
assertNotAlmostEquals
(**kwargs)assertNotEqual
(first, second[, msg])Fail if the two objects are equal as determined by the ‘!=’ operator.
assertNotEquals
(**kwargs)assertNotIn
(member, container[, msg])Just like self.assertTrue(a not in b), but with a nicer default message.
assertNotIsInstance
(obj, cls[, msg])Included for symmetry with assertIsInstance.
assertNotRegex
(text, unexpected_regex[, msg])Fail the test if the text matches the regular expression.
assertNotRegexpMatches
(**kwargs)assertRaises
(expected_exception, *args, **kwargs)Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments.
assertRaisesRegex
(expected_exception, …)Asserts that the message in a raised exception matches a regex.
assertRaisesRegexp
(**kwargs)assertRegex
(text, expected_regex[, msg])Fail the test unless the text matches the regular expression.
assertRegexpMatches
(**kwargs)assertSequenceEqual
(seq1, seq2[, msg, seq_type])An equality assertion for ordered sequences (like lists and tuples).
assertSetEqual
(set1, set2[, msg])A set-specific equality assertion.
assertTrue
(expr[, msg])Check that the expression is true.
assertTupleEqual
(tuple1, tuple2[, msg])A tuple-specific equality assertion.
assertWarns
(expected_warning, *args, **kwargs)Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments.
assertWarnsRegex
(expected_warning, …)Asserts that the message in a triggered warning matches a regexp.
assert_
(**kwargs)countTestCases
()debug
()Run the test without collecting errors in a TestResult
defaultTestResult
()dicts2lines
(*args, **kwargs)Wrapper around
dicts2lines()
doCleanups
()Execute all cleanup functions.
fail
([msg])Fail immediately, with the given message.
failIf
(**kwargs)failIfAlmostEqual
(**kwargs)failIfEqual
(**kwargs)failUnless
(**kwargs)failUnlessAlmostEqual
(**kwargs)failUnlessEqual
(**kwargs)failUnlessRaises
(**kwargs)id
()load_mutations
(*args, **kwargs)Wrapper around
load_mutations()
read_table
(input_file)Simple loading of tabular lines in a file
run
([result])run_command
(*args, **kwargs)Run a shell command.
run_cwl
([input, cwl_file])Run the CWL specified for the test case
setUp
()This gets automatically run before each test case
setUpClass
()Hook method for setting up class fixture before running tests in the class.
shortDescription
()Returns a one-line description of the test, or None if no description has been provided.
skipTest
(reason)Skip this test.
subTest
([msg])Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters.
tearDown
()This gets automatically run after each test case
tearDownClass
()Hook method for deconstructing the class fixture after running all tests in the class.
write_table
(*args, **kwargs)Wrapper around
write_table()
Attributes
DATA_SETS
IMPACT_FILE
KNOWN_FUSIONS_FILE
cwl_file
longMessage
maxDiff
runner_args