| | |
- ConfigFile
- unittest.TestCase(__builtin__.object)
-
- TestConfig
class ConfigFile |
| |
ConfigFile: A class which parses a simple config file.
(Probably every app has one of these classes, so I don't feel bad about
reinventing the wheel for the thousandth time. At least it's short.)
ConfigFile(filename, argmap=None, envprefix='VOLITY_') -- constructor.
The *filename* is parsed for lines of the form
key: value
Blank lines and lines beginning with '#' are ignored. A line without
a colon is considered to have the empty string for a value.
If *filename* is None, you still get a ConfigFile (as if it had parsed
an empty file).
The *argmap*, if supplied, is a set of key-value pairs which override
the config file entries. (You might get these from command-line
arguments.) Note that an *argmap* entry which maps to None is ignored,
but an entry which maps to '' is considered to exist.
The system also checks for environment variables of the form
'VOLITY_KEY'. (The key name is capitalized, and spaces and dashes
are converted to underscores; then *envprefix* is tacked on the
front.)
*argmap* entries override environment variables override config file
lines.
Public methods:
get(key) -- get a config value.
has_key(key) -- check whether a config value exists.
Internal methods:
parse(fl) -- parse the config file.
makeenvname(key) -- convert a key name to a possible environment var name. |
| |
Methods defined here:
- __init__(self, filename, argmap=None, envprefix='VOLITY_')
- get(self, key, default=None)
- get(key, default=None) -> str
Get an entry from the config file (or the command-line arguments,
or an environment variable). If the entry cannot be found by any
means, this returns None. (Unless another default is specified.)
*argmap* entries override environment variables override config file
lines.
- getbool(self, key, default=False)
- getbool(key, default=False) -> bool
Get an entry from the config file (or the command-line arguments,
or an environment variable). If the entry cannot be found by any
means, this returns False. (Unless another default is specified.)
*argmap* entries override environment variables override config file
lines. Boolean values of the form 't', 'true', 'y', 'yes', and '1'
are all recognized.
- has_key(self, key)
- has_key(key) -> bool
Check whether an entry exists in the config file (or the command-line
arguments, or an environment variable).
- makeenvname(self, key)
- makeenvname(key) -- convert a key name to a possible environment
variable name.
- parse(self, fl)
- parse(fl) -- parse the config file.
This is called internally when you create the ConfigFile.
|
class TestConfig(unittest.TestCase) |
| | |
- Method resolution order:
- TestConfig
- unittest.TestCase
- __builtin__.object
Methods defined here:
- test_file(self)
- test_nofile(self)
Methods inherited from unittest.TestCase:
- __call__(self, result=None)
- __init__(self, 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.
- __repr__(self)
- __str__(self)
- assertAlmostEqual = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertAlmostEquals = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertEqual = failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- assertEquals = failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- assertNotAlmostEqual = failIfAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertNotAlmostEquals = failIfAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertNotEqual = failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- assertNotEquals = failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- assertRaises = failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
- Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
- assert_ = failUnless(self, expr, msg=None)
- Fail the test unless the expression is true.
- countTestCases(self)
- debug(self)
- Run the test without collecting errors in a TestResult
- defaultTestResult(self)
- fail(self, msg=None)
- Fail immediately, with the given message.
- failIf(self, expr, msg=None)
- Fail the test if the expression is true.
- failIfAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- failUnless(self, expr, msg=None)
- Fail the test unless the expression is true.
- failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- 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.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
- Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
- id(self)
- run(self, result=None)
- setUp(self)
- Hook method for setting up the test fixture before exercising it.
- shortDescription(self)
- Returns a one-line description of the test, or None if no
description has been provided.
The default implementation of this method returns the first line of
the specified test method's docstring.
- tearDown(self)
- Hook method for deconstructing the test fixture after testing it.
Data and other attributes inherited from unittest.TestCase:
- __dict__ = <dictproxy object at 0x5da2d0>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestCase' objects>
- list of weak references to the object (if defined)
- failureException = <class exceptions.AssertionError at 0x20a80>
- Assertion failed.
| |