Setup¶
This general object all defining a set of action to happen in the Setup and Cleanup events. Use to define actions that need to happen before the object starts. All actions happen within the sandbox or environment defined for the test. New methods can be added to main Setup object via the AddSetupItem API. The setup object contains a number of sub-objects that act like domain namespaces to help separate commonly name actions that might exist in different areas. For example, different version control tools may have commonly named actions. These items will be listed below in the form of <namespace>.<method> to help clarify grouping.
- Copy.FromDirectory(path)¶
This method copies items from a given directory to test sandbox directory. All paths are relative from the Test.TestRoot directory, unless if the path provided is an absolute path. The same as saying:
Setup.Copy(path, Test.TestRoot)
Use this function to help provide clarity and intent.
- Parameters:
path (str) – Path to copy
Example
Copy all items for directory to be the content of a test.
Setup.Copy.FromDirectory("example/case1")
- Copy.FromTemplate(dir)¶
This method copies data from a directory under the template directory under the Test.TestRoot directory. The same as saying:
Setup.Copy(os.path.join(Test.TestRoot,"templates",dir), Test.TestRoot)
Use this function to help provide clarity and intent.
- Parameters:
path (str) – Path to copy
Example
Copies a directory “case1” under the the test root/templates to be the contents of the sandbox
Setup.Copy.FromTemplate("case1")
- Copy(source, target=None)¶
This method copies a file or directory to a location under the Sandbox location for the test. This is the core function used to by FromTemplate() or FromDirectory(). The optional target argument can be used to rename the item, or to copy the item to a different subdirectory under the sandbox directory.
- Parameters:
source (str) – Path to copy
target (str) – Path to copy
Examples
Copy a contents of directory to be in the root of the sandbox. Using Setup.FromDirectory(“mytestcase”) may be more clear.
Setup.Copy("mytestcase", Test.TestRoot)
Copy the same directory into the sandbox. This create a subdirectory “testit” in the sandbox
Setup.Copy("mytestcase", "testit")
Copy a file “a.txt” in to the sandbox.
Setup.Copy("a.txt")
- CopyAs(source, target=None, name)¶
Will copy the item to the new locations. Differs from Copy as the target argument is always viewed as a directory. Use this function over the copy function to avoid system behaviors where that target maybe be viewed as a file or directory depending on if the existence of the target on disk.
- Parameters:
source (str) – Path to copy
target (str) – Directory to copy to. If set to None will be the sandbox directory
name (str) – name to rename item to under the ToPath
Example
This will copy a file to the root sandbox directory
Setup.CopyAs("a.txt")
This will copy a file to the root sandbox directory and rename the file a1.txt
Setup.CopyAs('a.txt',name='a1.txt')
This will copy a file to the directory sub1/sub2 and rename the file as a1.txt
Setup.CopyAs("a.txt",'sub1/sub2', 'a1.txt')
- MakeDir(path, mode=None)¶
Will create the path provided inside the sandbox.
- Parameters:
path (str) – The directory to create
mode (int) – Optional file mode to set the directory to. Ignored on systems that don’t support this. This is system dependent, however on POSIX based system this defaults to 0777 (octal format)
Example
TBD
- Chown(path, uid, gid, ignore=False)¶
Change owner and group is of the item in provided path.
- Parameters:
path (str) – The path to the item to change
uid (str) – The user id
gid (std) – The group id
ignore (bool) – If the value cannot be change, ignore this as an error.
Example
TBD
- Lambda(func, description)¶
A quick and dirty way to do some custom action during setup
- Parameters:
func (callable) – The function to call. Needs to
description – Text to use in the report to describe to the user what the intent step is.
Example
TBD
- Setup.Svn.CreateRepository(name)¶
Create a repository within a directory with the value of “name”.
- Setup.Svn.ImportDirectory(name, dir_to_add, sub_dir='')¶
Import data to the named SVN repo
- Parameters:
name (str) – The name of the SVN to import to. Should be the same value used by CreateRepository()
dir_to_add (str) – The directory to import into the repository.
sub_dir (str) – A subdirectory under the repository to import data to, for example, “truck”, or “branch”
- Setup.Git.CreateRepository(name)¶
Create a Git repository within a directory with the value of “name”.
- Parameters:
name (str) – The name of the Git repo to create. This will be the name of the directory created under the sandbox directory.
Example
This will create a repo under the sandbox directory called “myrepo”
Setup.CreateRepository("myrepo")
- Setup.Git.ImportDirectory(name, dir_to_add, sub_dir='')¶
Import data to the named Git repo. The repo has to be created first.
- Parameters:
name (str) – The name of the Git repo to import to. Should be the same value used by CreateRepository()
dir_to_add (str) – The directory to import into the repository.
sub_dir (str) – A subdirectory under the repository to import data to
Example
This will import all files in a give directory to the root of the Git repo name “myrepo”
Setup.ImportDirectory("myrepo", "mydir")
This will import all files in a give directory to the subdirectory “truck” of the Git repo name “myrepo”
Setup.ImportDirectory("myrepo", "mydir", "truck")