Settings

htf.Settings is used to store local settings that can be easily used within your test cases or components. The local settings are stored in JSON format.

The local settings file defaults to the environment variable

HTF_SETTINGS

$HOME/settings.txt or ./settings.txt and are searched in the same order.

You can overwrite getSettingsFilenames() to change this behaviour.

HTF_SETTINGS and HOME are environment variables.

You are free to structure you local settings. They are read into a python dictionary and can be used the common way.

htf.Settings is a singleton.

Example settingsfile:

{
    "setting1" : 1,
    "setting2" : "test",
    "setting3" : null,
    "settings4" : {
                    "settings41" : 1,
                    "settings42" : 2
                 }
}

Example usage to access the settings in you code:

>>> from htf import Settings
>>> Settings()["setting1"]
1
>>> s = Settings()
>>> s["setting2"]
"test"
>>> s["settings4"]["settings42"]
2
# you can also access the settings like attributes:
>>> s.setting3
None
>>> s.setting1
1
>>> Settings().setting1
1
>>> s.settings4.settings42
2

Example to write new settings into your local settings file:

>>> from htf import Settings
>>> s = Settings()
>>> s["newSetting"] = "this is my new setting"
>>> s.save()
>>> s.newSetting
"this is my new setting"
>>> s["newSetting"] = None
>>> s.newSetting
None
>>> s["array"] = range(10)
>>> s.array
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
class htf.Settings

Settings can be used to access local settings easily. It is a singleton.

The local settings file is automatically searched looking in HTF_SETTINGS, $HOME/settings.txt or ./settings.txt in this order. If no settings file was found an exception is raised.

Settings are stored in JSON format.

make Settings() a singleton

get_settings_filenames()
Returns:
a list of filenames that are tried to be opened from left to right.
The first file that is opened will be used to read settings from.
Return type:list

You can overwrite this method in your specialized Settings.

save()

Save current settings (useful after modification).