This module tests the argparse.ArgumentParser instance returned by standard_parsers.py with a variety of options and choices. These tests use the standard unittest package and extend the unittest.TestCase class.
module_version: | 1.0 |
---|---|
created_on: | 2013-04-08 |
Test the function defined in standard_parsers.py.
A standard argparse.ArgumentParser instance is created from a call to standard_parser and then is tested with different sets of arguments.
Initialize the framework for testing.
Creates a new parser and creates a new system temporary directory with the tempfile package for use as an existing directory. A file called thisfileexists.txt is created in this directory as an existing file. Two new paths that do not exist, one a fake sub-directory in the existing directory and the other a fake file in this fake directory, are constructed.
Remove testing framework.
Deletes the created temporary directory and thisfileexists.txt file.
Test the parser with existing and non-existent infile arguments
Test object | Expectation |
---|---|
Existing file | Stores the filename |
Non-existent file | Raise SystemExit exception |
Test the parser with existing and non-existent -l|–log arguments
Test object | Expectation |
---|---|
Existing file | Stores the filename |
Non-existent file | Creates the path and stores the filename |
Test the parser with existing and non-existent outfile arguments
Test object | Expectation |
---|---|
Existing file | Stores the filename |
Non-existent file | Creates the path and stores the filename |
Test that the standard_parser function returns the correct objects
Test object | Expectation |
---|---|
valid arguments | Returns a argparse.ArgumentParser instance & 2 lists; 1) list of positional arguments & defaults (should be None), 2)list of keyword arguments & defaults. |
Test the parser with existing and non-existent –tmpdir arguments
Test object | Expectation |
---|---|
no –tmpdir | Create & store a system defined temp dir |
–tmpdir | Create & store a system defined temp dir |
–tmpdir <existing path> | Store <path> as the temp dir |
–tmpdir <non-existent path> | Create & store <path> as the temp dir |