mcstasscript.tests.test_Instr.TestMcStas_instr

mcstasscript.tests.test_Instr.TestMcStas_instr

class mcstasscript.tests.test_Instr.TestMcStas_instr(methodName='runTest')

Tests of the main class in McStasScript called McStas_instr.

__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.

addClassCleanup(function, /, *args, **kwargs)

Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).

addCleanup(function, /, *args, **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])

Asserts that two iterables have the same elements, the same number of times, without regard to 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()

doClassCleanups()

Execute all class cleanup functions.

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()

run([result])

setUp()

Hook method for setting up the test fixture before exercising it.

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()

Hook method for deconstructing the test fixture after testing it.

tearDownClass()

Hook method for deconstructing the class fixture after running all tests in the class.

test_RELATIVE_error()

Ensure check_for_errors finds impossible relative statement

test_RELATIVE_error_and_checks_false(mock_f)

Ensure check_for_errors finds impossible relative statement

test_add_component_infer_name(mock_stdout)

Testing add_component works when name is left out and inferred from the name of the python variable in the call.

test_add_component_simple(mock_stdout)

Testing add_component in simple case.

test_add_component_simple_after()

Testing add_component with after keyword argument for the method

test_add_component_simple_after_error()

Checks add_component raises a NameError if after keyword specifies a non-existent component

test_add_component_simple_before()

Testing add_component with before keyword argument for the method

test_add_component_simple_before_error()

Checks add_component raises a NameError if before keyword specifies a non-existent component

test_add_component_simple_double_naming_error()

This tests checks that an error occurs when giving a new component a name which has already been used.

test_add_component_simple_keyword(mock_stdout)

Testing add_component with keyword argument for the component

test_available_components_folder(mock_stdout)

Simple test of show components to show components in current work directory.

test_available_components_input_path_custom(...)

Simple test of input_path being recognized and passed to component_reader so PSDlin_monitor is overwritten Here dummy_mcstas and input_path are set using relative paths instead of absolute paths.

test_available_components_input_path_simple(...)

Simple test of input_path being recognized and passed to component_reader so PSDlin_monitor is overwritten

test_available_components_simple(mock_stdout)

Simple test of show components to show component categories

test_complex_initialize()

Tests all keywords work in initialization

test_component_help(mock_stdout)

Simple test of component help

test_copy_component_keywords()

Checks that a component can be copied and that keyword arguments given under copy operation is successfully applied to the new component.

test_copy_component_simple()

Checks that a component can be copied using the name

test_copy_component_simple_fail()

Checks a NameError is raised if trying to copy a component that does not exist

test_copy_component_simple_object()

Checks that a component can be copied using the object

test_create_component_instance_complex(...)

Tests successful use of _create_component_instance while using keyword arguments in creation

test_create_component_instance_simple(...)

Tests successful use of _create_component_instance

test_declare_block_add_user_variable()

Checks a NameError is raised when using user variable of same name as declare variable already defined.

test_declare_var_block_add_parameter()

Checks that adding a parameter with a name already used for a declared variable fails with NameError

test_get_component_simple()

get_component retrieves a component with a given name for easier manipulation.

test_get_component_simple_error()

get_component retrieves a component with a given name for easier manipulation.

test_get_last_component_simple()

Check get_last_component retrieves the last component

test_infer_add_declare_variable()

Check that name can be inferred from python variable when adding a declared variable.

test_infer_copy_component_simple()

Checks that a component can be copied using the name while giving the new instance name as the python variable

test_infer_name_add_parameter()

Test that name can be ommited when defining a parameter and that the python variable name is used in its place.

test_load_config_file()

Test that configuration file is read correctly.

test_load_config_file_x_ray()

Test that configuration file is read correctly.

test_load_libpyvinyl_parameters()

test_move_component()

Ensure a component can be moved

test_parameter_block_add_declare_variable()

Checks a NameError is raised when using declare variable of same name as instrument parameter.

test_parameter_block_add_user_variable()

Checks a NameError is raised when using user variable of same name as parameter already defined.

test_print_component(mock_stdout)

print_component calls the print_long method in the component class.

test_print_component_short(mock_stdout)

print_component_short calls the print_short method in the component class.

test_remove_component()

Ensure a component can be removed

test_run_backengine_basic(mock_sub, mock_stdout)

Test neutron run_full_instrument

test_run_backengine_complex_settings(...)

Test settings are passed to backengine with complex settings

test_run_backengine_existing_folder(mock_stdout)

Test neutron run of backengine fails if using existing folder for output_path and with increment_folder_name disabled.

test_run_full_instrument_complex(mock_sub, ...)

Test neutron run_full_instrument in more complex case

test_run_full_instrument_junk_par_error()

Check run_full_instrument raises a NameError if a unrecognized parameter is provided, here junk.

test_run_full_instrument_overwrite_default(...)

Check that default parameters are overwritten by given parameters in run_full_instrument.

test_run_full_instrument_required_par_error(...)

Tests run_full_instrument raises error when lacking required parameter

test_run_full_instrument_x_ray_basic(...)

Test x-ray run_full_instrument

test_set_run_from_and_run_to()

Ensure it is possible to use run_from and run_to, and that reset work

test_set_run_from_component()

Testing run_from method updates instr state correctly

test_set_run_from_component_fails_if_no_dump()

Ensure run_from fails if there are no dumps at that location

test_set_run_from_component_keywords()

Testing run_to method updates instr state with passed keywords

test_set_run_to_component()

Testing run_to method updates instr state correctly

test_set_run_to_component_keywords()

Testing run_to method updates instr state with passed keywords

test_set_run_to_component_with_ABSOLUTE_in_remaining_fails()

Ensures run_to fails if the remaining instrument refers to absolute

test_set_run_to_component_with_early_ref_in_remaining_fails()

Ensures run_to fails if the remaining instrument refers to absolute

test_set_run_to_nonexistant_component_fails()

Ensures run_to fails if the component doesn't exist

test_show_components_complex(mock_stdout)

Tests show_components for complex case

test_show_components_complex_2lines(mock_stdout)

show_components calls the print_short method in the component class for each component and aligns the data for display

test_show_components_complex_3lines(mock_stdout)

show_components calls the print_short method in the component class for each component and aligns the data for display

test_show_components_simple(mock_stdout)

Tests show_components for simple case

test_show_dump_works()

Ensures show_dump runs and that db can get the stored dump

test_show_dumps_works()

Ensures show_dumps runs

test_show_instrument_basic(mock_sub, mock_stdout)

Test show_instrument methods makes correct system calls

test_show_parameters(mock_stdout)

Testing that parameters are displayed correctly

test_show_parameters_line_break(mock_stdout)

Testing that parameters are displayed correctly

test_simple_add_declare_variable()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

test_simple_add_parameter()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

test_simple_add_user_variable()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

test_simple_append_declare()

Appending to declare adds an object to the declare list, and the allowed types are either strings or DeclareVariable objects.

test_simple_append_declare_var_mix()

Appending to declare adds an object to the declare list, and the allowed types are either strings or DeclareVariable objects.

test_simple_append_finally()

The finally section is held as a string.

test_simple_append_finally_no_new_line()

The finally section is held as a string.

test_simple_append_initialize()

The initialize section is held as a string.

test_simple_append_initialize_no_new_line()

The initialize section is held as a string.

test_simple_append_trace()

The trace section is held as a string.

test_simple_append_trace_no_new_line()

The trace section is held as a string.

test_simple_initialize()

Test basic initialization runs

test_user_var_block_add_declare_variable()

Checks a NameError is raised when using declare variable of same name as declared variable.

test_user_var_block_add_parameter()

Checks that adding a parameter with a name already used for a user variable fails with NameError

test_write_c_files_simple(mock_f)

Write_c_files writes the strings for declare, initialize, and trace to files that are then included in McStas files.

test_write_full_instrument_dependency(mock_f)

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax.

test_write_full_instrument_search(mock_f)

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax.

test_write_full_instrument_simple(mock_f)

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax.

test_x_ray_run_full_instrument_basic(...)

Tests x-ray run_full_instrument

Attributes

longMessage

maxDiff

test_RELATIVE_error()

Ensure check_for_errors finds impossible relative statement

test_RELATIVE_error_and_checks_false(mock_f)

Ensure check_for_errors finds impossible relative statement

test_add_component_infer_name(mock_stdout)

Testing add_component works when name is left out and inferred from the name of the python variable in the call.

test_add_component_simple(mock_stdout)

Testing add_component in simple case.

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location.

test_add_component_simple_after()

Testing add_component with after keyword argument for the method

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location, here after is tested.

test_add_component_simple_after_error()

Checks add_component raises a NameError if after keyword specifies a non-existent component

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location, here before is tested.

test_add_component_simple_before()

Testing add_component with before keyword argument for the method

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location, here before is tested.

test_add_component_simple_before_error()

Checks add_component raises a NameError if before keyword specifies a non-existent component

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location, here after is tested.

test_add_component_simple_double_naming_error()

This tests checks that an error occurs when giving a new component a name which has already been used.

test_add_component_simple_keyword(mock_stdout)

Testing add_component with keyword argument for the component

The add_component method adds a new component object to the instrument and keeps track of its location within the sequence of components. Normally a new component is added to the end of the sequence, but the before and after keywords can be used to select another location. Here keyword passing is tested.

test_available_components_folder(mock_stdout)

Simple test of show components to show components in current work directory.

test_available_components_input_path_custom(mock_stdout)

Simple test of input_path being recognized and passed to component_reader so PSDlin_monitor is overwritten Here dummy_mcstas and input_path are set using relative paths instead of absolute paths.

test_available_components_input_path_simple(mock_stdout)

Simple test of input_path being recognized and passed to component_reader so PSDlin_monitor is overwritten

test_available_components_simple(mock_stdout)

Simple test of show components to show component categories

test_complex_initialize()

Tests all keywords work in initialization

test_component_help(mock_stdout)

Simple test of component help

test_copy_component_keywords()

Checks that a component can be copied and that keyword arguments given under copy operation is successfully applied to the new component. A check is also made to ensure that the original component was not modified.

test_copy_component_simple()

Checks that a component can be copied using the name

test_copy_component_simple_fail()

Checks a NameError is raised if trying to copy a component that does not exist

test_copy_component_simple_object()

Checks that a component can be copied using the object

test_create_component_instance_complex(mock_stdout)

Tests successful use of _create_component_instance while using keyword arguments in creation

_create_component_instance will make a dynamic subclass of component with the information from the component files read from disk. The subclasses is saved in a dict for reuse in case the same component type is requested again.

test_create_component_instance_simple(mock_stdout)

Tests successful use of _create_component_instance

_create_component_instance will make a dynamic subclass of component with the information from the component files read from disk. The subclass is saved in a dict for reuse in case the same component type is requested again.

test_declare_block_add_user_variable()

Checks a NameError is raised when using user variable of same name as declare variable already defined.

test_declare_var_block_add_parameter()

Checks that adding a parameter with a name already used for a declared variable fails with NameError

test_get_component_simple()

get_component retrieves a component with a given name for easier manipulation. Check it works as intended.

test_get_component_simple_error()

get_component retrieves a component with a given name for easier manipulation. Check it fails when the component name doesn’t correspond to a component in the instrument.

test_get_last_component_simple()

Check get_last_component retrieves the last component

test_infer_add_declare_variable()

Check that name can be inferred from python variable when adding a declared variable.

test_infer_copy_component_simple()

Checks that a component can be copied using the name while giving the new instance name as the python variable

test_infer_name_add_parameter()

Test that name can be ommited when defining a parameter and that the python variable name is used in its place.

test_load_config_file()

Test that configuration file is read correctly. In order to have an independent test, the yaml file is read manually instead of using the yaml package.

test_load_config_file_x_ray()

Test that configuration file is read correctly. In order to have an independent test, the yaml file is read manually instead of using the yaml package.

test_move_component()

Ensure a component can be moved

test_parameter_block_add_declare_variable()

Checks a NameError is raised when using declare variable of same name as instrument parameter.

test_parameter_block_add_user_variable()

Checks a NameError is raised when using user variable of same name as parameter already defined.

test_print_component(mock_stdout)

print_component calls the print_long method in the component class.

test_print_component_short(mock_stdout)

print_component_short calls the print_short method in the component class.

test_remove_component()

Ensure a component can be removed

test_run_backengine_basic(mock_sub, mock_stdout)

Test neutron run_full_instrument

Check a simple run performs the correct system call. Here the output_path is set to a name that does not correspond to a existing file so no error is thrown.

test_run_backengine_complex_settings(mock_sub, mock_stdout)

Test settings are passed to backengine with complex settings

Check run performs the correct system call with settings. Here the output_path is set to a name that does not correspond to a existing file so no error is thrown.

test_run_backengine_existing_folder(mock_stdout)

Test neutron run of backengine fails if using existing folder for output_path and with increment_folder_name disabled.

test_run_full_instrument_complex(mock_sub, mock_stdout)

Test neutron run_full_instrument in more complex case

Check a complex run performs the correct system call. Here the output_path is set to a name that does not correspond to a existing file so no error is thrown.

test_run_full_instrument_junk_par_error()

Check run_full_instrument raises a NameError if a unrecognized parameter is provided, here junk.

test_run_full_instrument_overwrite_default(mock_sub, mock_stdout)

Check that default parameters are overwritten by given parameters in run_full_instrument.

test_run_full_instrument_required_par_error(mock_stdout)

Tests run_full_instrument raises error when lacking required parameter

The populated instr has a required parameter, and when not given it should raise an error.

test_run_full_instrument_x_ray_basic(mock_sub, mock_stdout)

Test x-ray run_full_instrument

Check a simple run performs the correct system call. Here the output_path is set to a name that does not correspond to a existing file so no error is thrown.

test_set_run_from_and_run_to()

Ensure it is possible to use run_from and run_to, and that reset work

test_set_run_from_component()

Testing run_from method updates instr state correctly

test_set_run_from_component_fails_if_no_dump()

Ensure run_from fails if there are no dumps at that location

test_set_run_from_component_keywords()

Testing run_to method updates instr state with passed keywords

test_set_run_to_component()

Testing run_to method updates instr state correctly

test_set_run_to_component_keywords()

Testing run_to method updates instr state with passed keywords

test_set_run_to_component_with_ABSOLUTE_in_remaining_fails()

Ensures run_to fails if the remaining instrument refers to absolute

test_set_run_to_component_with_early_ref_in_remaining_fails()

Ensures run_to fails if the remaining instrument refers to absolute

test_set_run_to_nonexistant_component_fails()

Ensures run_to fails if the component doesn’t exist

test_show_components_complex(mock_stdout)

Tests show_components for complex case

show_components calls the print_short method in the component class for each component and aligns the data for display

test_show_components_complex_2lines(mock_stdout)

show_components calls the print_short method in the component class for each component and aligns the data for display

This version of the tests forces two lines of output.

test_show_components_complex_3lines(mock_stdout)

show_components calls the print_short method in the component class for each component and aligns the data for display

This version of the tests forces three lines of output.

test_show_components_simple(mock_stdout)

Tests show_components for simple case

show_components calls the print_short method in the component class for each component and aligns the data for display

test_show_dump_works()

Ensures show_dump runs and that db can get the stored dump

test_show_dumps_works()

Ensures show_dumps runs

test_show_instrument_basic(mock_sub, mock_stdout)

Test show_instrument methods makes correct system calls

test_show_parameters(mock_stdout)

Testing that parameters are displayed correctly

test_show_parameters_line_break(mock_stdout)

Testing that parameters are displayed correctly

Here multiple lines are used for a long comment that was dynamically broken up.

test_simple_add_declare_variable()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

DeclareVariable is tested in test_declare_variable.

test_simple_add_parameter()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

ParameterVariable is tested in test_parameter_variable.

test_simple_add_user_variable()

This is just an interface to a function that is tested elsewhere, so only a basic test is performed here.

DeclareVariable is tested in test_declare_variable.

test_simple_append_declare()

Appending to declare adds an object to the declare list, and the allowed types are either strings or DeclareVariable objects. Here only strings are added.

test_simple_append_declare_var_mix()

Appending to declare adds an object to the declare list, and the allowed types are either strings or DeclareVariable objects. Here a mix of strings and DeclareVariable objects are added.

test_simple_append_finally()

The finally section is held as a string. This method appends that string.

test_simple_append_finally_no_new_line()

The finally section is held as a string. This method appends that string without making a new line.

test_simple_append_initialize()

The initialize section is held as a string. This method appends that string.

test_simple_append_initialize_no_new_line()

The initialize section is held as a string. This method appends that string without making a new line.

test_simple_append_trace()

The trace section is held as a string. This method appends that string. Only used for writing c files, which is not the main way to use McStasScript.

test_simple_append_trace_no_new_line()

The trace section is held as a string. This method appends that string without making a new line. Only used for writing c files, which is not the main way to use McStasScript.

test_simple_initialize()

Test basic initialization runs

test_user_var_block_add_declare_variable()

Checks a NameError is raised when using declare variable of same name as declared variable.

test_user_var_block_add_parameter()

Checks that adding a parameter with a name already used for a user variable fails with NameError

test_write_c_files_simple(mock_f)

Write_c_files writes the strings for declare, initialize, and trace to files that are then included in McStas files. This is an obsolete method, but may be repurposed later so that instrument parts can be created with the modern syntax.

The generated includes file in the test directory is written by this test. It will fail if it does not have rights to create the directory.

test_write_full_instrument_dependency(mock_f)

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax. Here tested with the dependency section enabled.

The test includes a time stamp in the written and expected data that has an accuracy of 1 second. It is unlikely to fail due to this, but it can happen.

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax. Here tested with the search section enabled.

The test includes a time stamp in the written and expected data that has an accuracy of 1 second. It is unlikely to fail due to this, but it can happen.

test_write_full_instrument_simple(mock_f)

The write_full_instrument method write the information contained in the instrument instance to a file with McStas syntax.

The test includes a time stamp in the written and expected data that has an accuracy of 1 second. It is unlikely to fail due to this, but it can happen.

test_x_ray_run_full_instrument_basic(mock_sub, mock_stdout)

Tests x-ray run_full_instrument

Check a simple run performs the correct system call. Here the output_path is set to a name that does not correspond to a existing file so no error is thrown.