Unit Testing Package

Unit testing modules are divided between the following tasks:

  • Specifying test structure and cases.
  • Generating and compiling the test directories.
  • Executing the compiled tests.
  • Verifying that the output is correct.
class fortpy.testing.tester.ExecutionResult(folder, exitcode, runtime, tester, case=None)[source]

The result of running the executable on the system, NOT the result of the unit test file comparisons.

Parameters:
  • folder (str) – the folder in which the executable ran.
  • exitcode (int) – the system exit code after the process terminated.
  • runtime (datetime.datetime) – execution run time.
  • tester (OutcomeTester) – instance to test the outcome of this execution.
  • case (str) – the case identifier if this was part of a series of cases run for the same outcome.
test(caseid, uresult)[source]

Tests the outcome of this executable using its tester attribute.

Parameters:
  • caseid (str) – identifier for the specific case to test.
  • uresult (TestResult) – the overall result for the test; modified with the results of outcome testing for caseid.
class fortpy.testing.tester.OutcomeTester(testspec, codefolder, comparer, verbose, compiler)[source]

Performs outcomes tests for a single ‘test’ DocString.

Parameters:
  • testspec – the :class:fortpy.testing.elements.TestSpecification for the <test> tag.
  • codefolder – the path to the folder that has all the modules from which the unit tests were built.
  • comparer – an instance of FileComparer to compare output files to the model ones.
compiler = None

Active compiler for the current test whose outcome is being run.

test(caseid, xresult, uresult)[source]

Checks the output of the execution for the specified test specification.

Parameters:
  • xresult – an ExecutionResult instance that has information about the execution whose outcome is being tested.
  • uresult – the unittest’s TestResult that holds information from all executions that were run for different cases.
class fortpy.testing.tester.TestResult(identifier, testid)[source]

Represents a set of unit test results.

Parameters:
  • identifier – the module.method identifier for this unit test.
  • testid – the identifier of the <test> tag for the specific test that this result represents.
Variables:
  • cases – a dictionary of ExecutionResult objects with detail on how the system execution went for each case. Key is caseId.
  • paths – a dictionary of paths to the folders that were executed for each case. Keys match those in self.cases.
  • outcomes – a dictionary of :py:class:~`fortpy.testing.results.CompareResult` objects with detail on how similar the new output files are to the model ones. Keys are the same caseIds used in self.cases.
  • compiled – specifies whether the executable associated with this identifier compiled successfully.
  • failures – CompareResult or ValueResult instances that failed the tests outlined by the relevant test specification. Keys are the caseIds used by all the other dicts.
  • overtimes – a tuple of (actual runtime, desired runtime range) for tests that were outside of the range for runtime.
clean(case)[source]

Dereferences the test results’ memory to the representations of the output and only retains the percent and common matches etc. for aggregate statistics. Should only be called after the *.compare files have been written out for the test case.

common

Returns the common match percent success.

failure_count

Gets the number of outcomes that failed because of tolerance or misformatted or no output files.

percent

Returns the percent success of the entire unit test.

runtime(caseid)[source]

Gets the absolute amount of time spent running only the executable being unit tested for this result.

target = None

The full path to the directory containing the compiled executable to run.

totaltime

Returns the total amount of time spent running only the unit tested executable for all cases in this result.

class fortpy.testing.tester.UnitTester(libraryroot=None, verbose=False, compare_templates=None, fortpy_templates=None, rerun=None, compiler=None, debug=False, profile=False, quiet=False, strict=False, nprocs=1)[source]

Performs automatic unit testing of individual subroutines and functions based on XML doctags found in the code files.

Parameters:libraryroot – the path to folder in which to stage the tests.
compiler = None

The full path to the compiler to use for the unit tests.

get_fortpy_version(fortpath)[source]

Gets the fortpy version number from the first line of the specified file.

libraryroot(identifier)[source]

Returns the absolute path to the staging directory for the unit tests with the specified testid.

nprocs = None

The number of processors to use for multi-threading test case execution.

quiet = None

Specifies whether the tester should run in quiet mode, which only prints essential information for the unit tests to stdout.

runall(compiler=None)[source]

Compiles and runs each new or modified unit test executable. After the run is complete, the outcomes are checked for consistency.

Parameters:compiler – the name of the compiler in ‘compilers.xml’ to use.
set_compiler(compiler)[source]

Sets the compiler to use for the unit testing of this code parser.

strict = None

Specifies whether to compile files with all warnings enabled.

tests(identifier)[source]

Returns a dictionary of all the tests that need to be run for the specified module.executable identifier.

writeall(codefolder)[source]

Writes all the unit test executables that are new or modified as well as the makefiles for all subroutines in all modules.

writer(identifier)[source]

Returns the underlying executable writer that has a list of ordered method/assignment dependencies.

class fortpy.testing.tester.ValueCompareResult(path, value)[source]

The result of comparing the contents of a file to an explicit value hard-coded in the testing XML tags.

Variables:
  • path (str) – path to the file whose contents will be checked.
  • value (str) – explicit value to compare the file contents to; is passed to eval() before comparison.
  • equal (bool) – True if the file contents are identical to value.
class fortpy.testing.elements.Assignment(element, parent)[source]

Represents an instance value assignment as part of a pre-req chain.

Attr element:the DocElement instance for the <assignment> tag that this assignment object represents.
Attr parent:the MethodFinder instance who owns this assignment.
Attr methods:a list that will never get used; needed for compatibility with method.MethodWriter._order_dependencies recursion.
Attr group:the parent TestingGroup instance, even if the immediate parent is not a testing group.
Attr name:the name of the variable whose value will be set.
Attr conditionals:
 a list of ‘if’ blocks that conditionally set the value of the variable at run-time.
Attr values:a dict of AssignmentValues capable of setting the variable value from a constant, function, file or by calling an embedded method if the variable is an instance of a derived type.
Attr allocate:when true, the variable having its value set will be allocated by this assignment object rather than some other method called previously. Default is True.
allocatable

Returns true if the variable assigned by this object should be allocated.

attributes

Provides one-level-up access to the XML elements attributes collection.

autoclass

Returns True if any of the assignment values in an autoclass.

check_prereqs(finder)[source]

Checks all the values this assignment may use to make sure they reference a valid derived type. If an AssignmentValue specifies to check pre-reqs, they are added to the pre-req chain.

Parameters:finder – the instance of MethodFinder for which the pre-reqs are being checked and added.
code(lines, position, spacer)[source]

Appends the code for this assignment to function correctly at the specified position in the code file.

Parameters:
  • lines – the list of strings that form the code file.
  • position – one of [‘vars’, ‘init’, ‘assign’, ‘before’, ‘after’] corresponding to variable declaration, initialization, assignment and cleanup.
copy(coderoot, testroot, case, compiler, stagedir=None)[source]

Copies the input files needed for this assignment to set a variable.

Parameters:
  • coderoot – the full path to folder with the code files.
  • testroot – the full path the folder where the test is running.
  • case – the case id for multi-case testing.
  • compiler – the name of the compiler used to make the unit test executable.
  • stagedir – the path to the staging directory to use (override).
global_attr(key, default=None)[source]

Retuns the value of attribute with the specified key from the GlobalDeclaration instance for this variable being assigned.

globaldecl

Returns the GlobalDeclaration instance for the current variable, which may have different parameters and modifiers than the actual code element.

parent = None

An instance of TestSpecification or TestingGroup in which this <assignment> was defined.

parser

Returns this Assignment’s parent’s CodeParser instance.

position = None

If a test specification includes assignments local to the test then global <assignments> attached to the testing group are added either before/after the local assignments. This value specifies that position relative to the local ones.

testspec

The currently active test specification for which this Assignment instance is being coded.

variable

Returns the ValueElement instance that this assignment refers to.

writekey = None

Establishes a unique key for the driver writer so that multiple assignments of the same variable don’t interfere with each other.

class fortpy.testing.elements.AssignmentConditional(xmltag, parent)[source]

Represents a series of logical tests to perform, each of which results in a different value being assigned to the variable.

code(lines, position, spacer)[source]

Appends the lines to form the entire conditional code block of variable assignments.

repeats

Returns true if any of the values used by this condition are repeatable. In that case, the entire block needs to be repeated.

values

Returns the list of possible value objects from the parent Assignment object.

class fortpy.testing.elements.AssignmentValue(xmltag, parent)[source]

Represents a value that can be assigned to the variable represented by an Assignment instance.

Attr xml:the xml <value> tag that this object was created from.
Attr parent:the instance of Assignment that owns this value.
Attr identifier:
 the unique identifier of the this value.
Attr folder:the folder path relative to the code folder where the file for setting a variable value is found.
Attr filename:the name of the file in the source folder.
Attr rename:the new name the file should have in the execution folder.
Attr constant:if specified, the constant value that the variable will be set to during the unit test.
Attr embedded:the name of an embedded procedure in a derived type to run. An error is thrown if the variable is not a derived type.
Attr function:exact fortran code for a function call to set the vars value.
Attr repeats:if the variable will have its value set as part of a constant-input mode program, this specifies whether it should keep being set during each iteration of the main method being tested.
Attr prereq:if not None/False, the embedded method on a derived type will be treated along with all its prereqs as part of the execution chain. This value should be the test identifier of the embedded subroutine’s test spec to use.
Attr D:the dimensionality of the data in the file that is setting the variable value.
Attr ragged:when true, the lines in a 2D array file are treated individually with some other (embedded or function) value assignment.
Attr dtype:for ragged array files, the data type of the values in each row.
Attr kind:the kind of each value in the data rows of the ragged array.
D

Returns the dimensionality of the variable having its value changed.

autoclass = None

Specifies whether the value comes from an auto-class structured folder.

check_prereqs(finder)[source]

Checks whether this value element requires an embedded method to be added to the prereq chain of the method writer.

code(lines, position, spacer, slices=None, first=False)[source]

Appends the code lines to initialize the parent variable.

Parameters:
  • lines – the list of strings to append to.
  • position – one of [‘vars’, ‘init’, ‘assign’, ‘before’, ‘after’] indicating where in the fortran program the code will be appended.
  • slices – for array value assignments, the specific indices to assign values to. Tuple of (slice string, [loopvars]).
  • first – if multiple value tags are being executed by the calling parent, this should be true only for the first <value> tag processed in the list.
copy(coderoot, testroot, case, compiler, stagedir=None)[source]

Copies the input files needed for this value to set a variable.

Parameters:
  • coderoot – the full path to folder with the code files.
  • testroot – the full path the folder where the test is running.
  • case – the case id for multi-case testing.
  • compiler – the name of the compiler being used for the unit tests.
  • stagedir – the path to the staging directory to use (override).
iid

Returns the globally unique identifier for this value.

livefile(testroot, case)[source]

Returns the full path to the file that should be created in the specified test directory as part of this assignment. This is only useful for file-based assignments.

member = None

If this value should be assigned to the member of a derived type, then this is the name of that member.

suffix = None

Overrides the default period joined list of loop variables for <part> or ragged assignment from files.

testsource = None

Specifies the module.executable.parameter name whose output from a previous unit test run will be used as input for this value.

xname

Returns the name of the file to use taking renaming into account.

class fortpy.testing.elements.AutoClasser(variable, folder, varfile, cases, coderoot=None, generic=False)[source]

Class for generating read/save calls in Fortran for complex user-derived types. Ragged arrays are not supported.

Parameters:
  • variable – an instance of ValueElement to auto-class.
  • folder – the path to the parent folder that houses the ‘varfile’ folder with the contents of the variable.
  • varfile – the name of the folder to create (relative to ‘folder’) to contain the files for the variable.
  • cases – the TestSpecification instance’s cases that will run.
  • coderoot – the full path to the code folder that houses that executable being unit tested.
abspath(root)[source]

Returns the absolute path to the auto-class folder relative to the root directory specified: 1) code root for reads; 2) test execution directory for writes.

acroot

The folder path to the auto-class target for read/write, relative to 1) code directory for reads; 2) test directory for writes.

code(lines, position, spacer, write=True, first=True)[source]

Appends the code required to save/read the value of this auto-class to file-folder if the specified position is appropriate.

generic = None

When true, instead of outputing the specific variable name for save and read operations, the generic ‘variable’ will be used as the name.

prep_read()[source]

Sets this auto-classer up to handle reading-in from a folder by analyzing the contents of the folder.

set_folder(folder)[source]

Sets the folder for the auto-class relative to the code root.

tree_order = None

The order in which the tree’s dimensionalities will be saved in the .fortpy.analysis file.

xcode(lines, position, spacer, write=True, first=True, testsource=None)[source]

Generates the code to save/read a variable from its auto-class folder. This version uses the auxsave and auxread interfaces from fpy_auxiliary instead of generating all the save and read statements directly.

class fortpy.testing.elements.Condition(xmltag, parent)[source]

Represents a single if, elseif or else block to execute.

code(lines, spacer)[source]

Appends the code for this condition and its variable assignment.

repeats

Returns true if any of the values this conditional references have the repeat attribute set to true.

class fortpy.testing.elements.GlobalDeclaration(element)[source]

Represents a declaration to have a global variable instance available for execution of a unit test.

Attr element:the docstring element representing the <global> tag.
D

Returns the integer number of dimensions that this variable is declared as having.

attributes

Returns a dictionary of attributes for this global variable declaration.

compare(element)[source]

Determines whether the specified element defines the same variable type and name as this one.

The two are considered equal if they have the same:
  • name
  • type
  • dimensionality
  • allocatable/pointer modifiers

.

definition()[source]

Returns the fortran declaration that defines a global variable.

Parameters:altname – specifies an alternative name to use for this variable; all other variable properties remain the same.
dependency

Returns the name of a variable that this variable needs in order to be initialized or assigned a value or “”.

dimension

Returns the dimension specification from the <global> tag.

ignore

Specifies whether this variable should be ignored when passed in to argument lists and for definitions etc.

initialization()[source]

Returns the fortran declaration to initialize the global variable’s value.

kind

Returns the kind of the variable from the <global> tag declaration, if it exists.

position

Returns the position of a <global> declaration in a testing group relative to the test-local <global> definitions.

range_check()[source]

Determines if this variable has a range check specified and writes the fortran code to compute the check.

value_elem(module)[source]

Returns a fortpy.element.ValueElement to represent this GlobalDeclaration.

class fortpy.testing.elements.MethodFinder(identifier, parser, element, testid, fatal_if_missing=True, main=False, basic=False)[source]

Class for recursively finding methods for executing pre-req methods that takes recursive dependencies into account.

Parameters:
  • identifier – the “module.executable” that this method finder represents
  • parser – the code parser instance for inter-module access.
  • element – the DocElement that specified this method as a pre-req.
  • testid – the identifier of the test specification that this method finder is being constructed for.
  • fatal_if_missing – specified whether the framework chokes if it can’t find a method that is referenced as a pre-req.
Attr executable:
 

the code element instance of the executable found from the module that the method belongs to.

Attr main:

when true, this instance is for the main method being unit tested.

Attr basic:

when true, the Finder only initializes the executable attribute for the given identifier, but doesn’t recursively find pre-req and other dependency methods.

add_prereq(identify, tag, chainto)[source]

Adds a MethodFinder instance to the current one for the specified ‘module.executable’ identity.

Parameters:
  • identify – a string of “modulename.executablename”.
  • tag – the DocElement instance that resulted in this prereq being added.
  • chainto – the test identifier specified by the pre-req that should be used for chaining.
attributes

Returns the dictionary of attributes from the underlying xml tag.

code(lines, position, spacer, testid)[source]

Appends the code to execute only this method’s main executable as part of the main program.

Parameters:lines – the list of strings that form the contents of the *.f90 file being created.
module

Returns the module instance for this method.

parser

Returns the CodeParser instance for inter-modular access.

terminate

Specifies whether any pre-reqs chained to this method should be executed or not.

test = None

The TestSpecification instance for the unit test that this method finder is operating under.

timed(testid)[source]

Returns true if this method will produce code to time its execution.

variables

Returns a list of all the global variables declared by the testing group of this method if they exist.

writekey = None

Key to uniquely identify this method finder from any other that exists because of multiple calls to the same pre-requisite methods.

class fortpy.testing.elements.Part(xml, parent)[source]

Represents a part assignment for a <part> tag to set specific dimensions on an array-valued variable.

Attr identifier:
 the unique identifier for the <part>.
Attr start:the index of the array to start on.
Attr value:the value to assign to parts of the array specified by this part.
Attr limits:a comma-separated list of integer indices to assign the value to or a range of min-max integer dimension specifiers. The loop generated by this part tag will run over these values.
Attr parts:a dict of parts nested in this one.
Attr depth:the depth of this part in a nested part specification.
Attr assignment:
 the parent instance of Assignment for this part, even if its immediate parent is another Part instance.
Attr isloop:for a limit specificaton that is a comma-separated list, we don’t use a loop, only a repeated list of assignments.
Attr loopid:the name of the loop variable for this part.
Attr slice_list:
 list of the dimension specifcations for setting the array part that this object is supposed to set.
Attr repeats:when operating in constant mode, should the part assignment happen before each call to the main function being unit tested.
code(lines, position, spacer)[source]

Adds the code to make this part specification (and loop) work.

top_parts

Returns the parent <part> instances from a set of nested <part> tags.

class fortpy.testing.elements.TestInput(xmltag, testspec)[source]

Represents information for a single input source as part of a unit test.

Attr xml:the <input> tag that this object was created from.
Attr folder:the path to the folder that contains the input file relative to the code root.
Attr filename:the name of the file to use as input.
Attr rename:the new name to use for the input file for actual execution.
Attr line:a FileLine instance describing the values that appear in a single line of the input file. Use for constant-input mode.
code_finalize(lines, spacer)[source]

Appends the code to finalize the constant-input operation.

code_init(lines, spacer)[source]

Appends the initialization code required for opening the input file when running in constant-input mode.

code_read(lines, spacer)[source]

Appends the fortran code for reading the values from the file into the global variables for a single iteration.

code_vars(lines, spacer)[source]

Appends the fortran code for declaring any variables need to run the constant-input mode.

constant

Returns true if operating in constant-input mode.

copy(coderoot, testroot, case='', compiler=None, stagedir=None)[source]

Copies the input file from the specified code root directory to the folder where the test is being performed. Alternatively, the file is just symlinked if that is the global setting.

Parameters:
  • coderoot – the full path to the folder that houses all the code files.
  • testroot – the full path to the folder that the parent test is being performed in.
  • case – if a specific case of the same test is being performed, the case identifier to use for string formatting.
  • compiler – the name of the compiler used to make the unit test executable.
  • stagedir – the path to the staging directory to use (override).
fileunit

Returns the name used for the variable that holds the file unit for reading the file in constant-input mode.

iid

Returns the identifier for this input file when running in constant- input mode.

iostat_read

Returns the name of the variable that holds read IOSTAT for the read operations when running in constant-input mode.

repeats

Returns the variable that holds the number of times to repeat the read operation and execute the method.

runfile

Returns the name of the file that will be in the testing folder at run-time.

testsource = None

Specifies the module.executable.parameter name whose output from a previous unit test run will be used as input for this value.

testspec = None

TestSpecification parent instance that has access to code element information for test-source inputs.

class fortpy.testing.elements.TestOutput(xmltag)[source]

Represents an output file compare operation that needs to be performed by the tester.

Attr xml:the XML <output> tag that the object was created from.
Attr identifier:
 the unique identifier for this output specification.
Attr folder:for file-mode, the folder that contains ‘file’.
Attr filename:the name of the model file to compare the output to.
Attr template:the name of the XML file that has template information for comparing the file.
Attr mode:the comparison mode for the FileComparer. Default=’default’.
Attr value:if the output value is a constant, its value.
Attr tolerance:for value comparisons, as long as the values are within this percent, the test still passes. E.g. if tolerance=0.8, then a value of 0.92 is considered equivalent to 1.
abspath(coderoot, caseid='', compiler=None)[source]

Returns the absolute path to the output file referenced by this output comparison specifier.

Parameters:
  • coderoot – the full path to the directory storing the code files.
  • case – if a specific case of the same test is being performed, the case identifier to use for string formatting.
actolerance = None

Specifies the individual tolerance limit for any single file comparison in the auto-class comparision.

autoclass = None

Specifies whether the output is running in auto-class mode where entire arrays of user-defined objects can be compared using a single tag.

filemode

Returns a value indicating whether the output comparison is with a file (as opposed to a hard-coded value).

class fortpy.testing.elements.TestPreReq(tag, parent)[source]

Represents a subroutine or function that must run before the main executable being unit-tested can run.

chainto = None

Specifies the ID of the test specification that should be used when chaining the pre-reqs.

method = None

The ‘module.executable’ identifier for the pre-req method to run.

paramlist = None

Overrides the default behavior of the parameter list.

parent = None

The testing group or test specification instance that owns this tag.

position = None

For pre-reqs specified in a testing group, the user must decide whether the global methods run before/after the local test specification methods.

class fortpy.testing.elements.TestSource(compkey, testspec)[source]

Represents a link between the output of one unit test that is being used as input for another unit test.

cases = None

The list of test cases to use inputs for. One test case will be created for each distinct test source case using either ‘one-to-one’ or ‘cartesian’.

copy(coderoot, testroot, case, compiler=None, stagedir=None)[source]

Copies the test-source file to the specified testing directory.

Parameters:stagedir – the path to the staging directory to use (override).
filename

Returns the name of the local file that will contain the full path to the data to use.

filevar

Returns the code to reference a trimmed, clean version of the contents of the variable containing the full path to the data.

key = None

The ‘module.executable.parameter’ directive.

path(coderoot, case, compiler=None, stagedir=None)[source]

Returns the full path to the source file that this test source is going to use (either directly or with copy).

Parameters:stagedir – the path to the staging directory to use (override).
source = None

The CodeElement instance of the parameter whose output is being used.

target = None

The TestTarget instance for the variable whose output is being used as the test source.

testid = None

The identifier of the test whose output will be used.

testspec = None

The TestSpecification instance of the target whose input is being defined.

varname

Returns the name of the local file variable that will contain the full path to the data to use.

class fortpy.testing.elements.TestSpecification(xmltag, testgroup)[source]

Represents a single test that needs to be performed. Each test compiles a new executable with the same name as the test identifier; however, the tests all use the same base dependencies from other modules.

Attr identifier:
 a unique id for the test; the unit test executable will be created with this name.
Attr description:
 included in the summary of the auto-generated program *.f90 file.
Attr cases:a list of cases to run that use the same test specification except for a slight change in the names of input/model files.
Attr runtime:an integer list [min, max] range for the time this test should take to run.
Attr unit:either ‘m’ or ‘h’; the units for ‘runtime’.
Attr timed:when true, the execution time of the main method being unit tested will be accumulated and saved.
Attr targets:a list of TestTarget instances that specify which variables and files need to be verified after the unit test runs.
Attr inputs:a list of TestInput instances that specify how to initialize the values of the variables or that are required by other methods being run as pre-reqs of the main unit testing method.
Attr output:a dict of TestOutput instances; keys are the output identifiers the values are the object instances. Represent sources for model data to compare the unit tests’ generated output to.
Attr testgroup:the testing group that the specification belongs to.
autoclass

Returns True if any of the assignments in the test specification require auto-class support.

autoclasses = None

A dict of AutoClasser() instances for generating read/write blocks for user-derived type variables that are complex. We only need to write the variable declarations once per test specification, which is why we put them here.

clean(testroot)[source]

Removes all variable target output files so that the test folder is clean for a new run.

code_after(lines, spacer)[source]

Appends the code required to save the value of any targets for this test to their files when their save frequency is set to ‘each’.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
code_before(lines, spacer)[source]

Appends all code required to read the next values from a file into their variables before the main test function is called again.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
code_finalize(lines, spacer)[source]

Appends the code for cleaning up open file handles and saving the final values of the targets to their files.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
code_init(lines, spacer)[source]

Appends all code required to initialize all the constant-mode input file specifications and save starting values of targets.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
code_validate(lines, spacer)[source]

Appends the fortran code to validate the length of the constant-valued input files if there is more than one of them.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
code_vars(lines, spacer)[source]

Appends all the code required by all the input file specifications in order to run the unit test to the list.

Parameters:
  • lines – the list of strings that will form the contents of the *.f90 file being created for the executable.
  • variables – the dictionary of all global variables declared in the program to be used by any methods being run.
constant

Returns a value indicating whether any of the inputs in this test run in constant-input mode.

executable

Returns the instance of Executable code element that this specification will test.

methods = None

A set of local assignments and pre-reqs that apply to this test.

parse()[source]

Parses the child-tags and attributes of this test specification once its parent testing group is finished parsing.

repeats

Returns the name of a variable to use for the do loop when the method execution is repeated for each line in constant-input file.

testable

Returns True if this test specification includes at least one output specification making it testable.

variables = None

A set of local variable declarations for this test.

class fortpy.testing.elements.TestTarget(xmltag, testspec)[source]

Represents a specification to save the state of a variable at the end of the program run or each time the main method being tested is run.

Attr xml:the xml <target> tag that the object was created from.
Attr name:the name of the variable that will be saved.
Attr varfile:if fortpy is handling the save to file, the name of the file that fortpy should save the variable under.
Attr when:specifies how often the variable should be saved. Possible values are [‘begin’, ‘each’, ‘end’] corresponding to the start of the program, each time the method gets run and right before the variables are cleaned up by the program.
Attr generator:the name of a subroutine to call that will save the variable to a file. The only parameter passed to the subroutine is the instance of the variable to save.
Attr compareto:the identifier of an <output> tag that the variable’s values will be compared to after the program has run.
Attr testspec:the parent test specification that this target belongs to.
Attr member:the name of a member in a derived type whose value should be saved.
autoclass = None

Specifies whether the output is running in auto-class mode where entire arrays of user-defined objects can be compared using a single tag.

clean(testroot)[source]

Removes the output file for saving the variable’s value from the testing folder.

code(lines, variables, position, spacer, first=True)[source]

Appends the code required to save the value of this target to file if the specified position is appropriate.

init(testroot)[source]

Creates any directories that this test target needs to function correctly.

class fortpy.testing.elements.TestingGroup(group, element)[source]

Represents a unit testing documentation group with information on how to automate a unit test for a specific executable.

Attr tests:a dict of TestSpecifications for running multiple tests that use the same variables, mappings and other parameters.
Attr mappings:a dict with keys as the parameter names from the method being tested and values being the variable names to pass in.
Attr assignments:
 a dict of assignments for changing the values of the variables.
Attr children:a list of the DocElement instances who belong to this testing group.
Attr methods:a dict of variable assignments and prereq methods for changing variable values or executing pre-req subroutines. The actual assignments are made as part of the executable chaining to make sure that values get changed in the correct order.
Attr finder:the MethodFinder instance that this group belongs to.
assignments = None

A dict of test-group level variable names that have their values changed by a test-group level assignment. Keys are lowered variable names values are dicts of variable attributes.

code(testid, section, lines, spacer)[source]

Appends the relevant code for the specified test and section of the final executable file.

Parameters:
  • testid – the identifier of the test to append code for.
  • section – one of [‘vars’, ‘init’, ‘validate’, ‘before’, ‘after’, ‘final’]. Refers to section of the PROGRAM *.f90 file being created.
  • lines – a list of the strings collected so far for the contents of the *.f90 program file.
coderoot = None

The absolute path to the code folder where the module file resides for the unit test being run.

finder = None

The currently active MethodFinder instance being used by the MethodWriter to create the executable driver for a specific testid.

static global_add(variables, order, name, doc)[source]

Adds a global declaration for the specified DocElement if it isn’t already represented in the list.

inputs = None

A list of input files that need to be copied to the test execution directories for all the test specifications.

method_fullname

Returns the full module.method name of the executable that this group decorates.

name

Returns the name of the underlying DocGroup.

outputs = None

Dict of comparison outputs that should be available for all test specifications in the unit test.

set_finder(finder)[source]

Sets the currently active MethodFinder instance being used by the MethodWriter to create the executable driver for a specific testid.

staging = None

The path of the staging directory relative to the code directory.

targets = None

List of the variables that should have their values saved to file and compared with model output for all the test specifications.

variable_order = None

The order in which the global declarations appear in the group.