cfme.utils package

Module contents

class cfme.utils.FakeObject(**kwargs)[source]

Bases: object

class cfme.utils.InstanceClassMethod(instance_or_class_method)[source]

Bases: object

Decorator-descriptor that enables you to use any method both as class and instance one

Usage:

class SomeClass(object):
    @InstanceClassMethod
    def a_method(self):
        the_instance_variant()

    @a_method.classmethod
    def a_method(cls):
        the_class_variant()

i = SomeClass()
i.a_method()
SomeClass.a_method()
# Both are possible

If you don’t pass classmethod the “instance” method, the one that was passed first will be called for both kinds of invocation.

classmethod(class_method)[source]
class cfme.utils.ParamClassName(instance_attr, class_attr='__name__')[source]

Bases: object

ParamClassName is a Descriptor to help when using classes and instances as parameters

Note: This descriptor is a hack until collections are implemented everywhere

Usage:

class Provider(object):
    _param_name = ParamClassName('name')

    def __init__(self, name):
        self.name = name

When accessing the _param_name on the class object it will return the __name__ of the class by default. When accessing the _param_name on an instance of the class, it will return the attribute that is passed in.

cfme.utils.at_exit(f, *args, **kwargs)[source]

Diaper-protected atexit handler registering. Same syntax as atexit.register()

cfme.utils.attributize_string(text)[source]

Converts a string to a lowercase string containing only letters, digits and underscores.

Usable for eg. generating object key names. The underscore is always one character long if it is present.

cfme.utils.castmap(t, i, *args, **kwargs)[source]

Works like the map() but is made specially to map classes on iterables.

This function only applies the t to the item of i if it is not of that type.

Parameters:
  • t – The class that you want all theitems in the list to be type of.
  • i – Iterable with items to be cast.
Returns:

A list.

cfme.utils.classproperty(f)[source]

Enables properties for whole classes:

Usage:

>>> class Foo(object):
...     @classproperty
...     def bar(cls):
...         return "bar"
...
>>> print(Foo.bar)
baz
cfme.utils.clear_property_cache(obj, *names)[source]

clear a cached property regardess of if it was cached priority

class cfme.utils.deferred_verpick(version_pick)[source]

Bases: object

descriptor that version-picks on Access

Useful for verpicked constants in classes

cfme.utils.fakeobject_or_object(obj, attr, default=None)[source]
cfme.utils.icastmap(t, i, *args, **kwargs)[source]

Works like the map() but is made specially to map classes on iterables. A generator version.

This function only applies the t to the item of i if it is not of that type.

Parameters:
  • t – The class that you want all the yielded items to be type of.
  • i – Iterable with items to be cast.
Returns:

A generator.

cfme.utils.iterate_pairs(iterable)[source]

Iterates over iterable, always taking two items at time.

Eg. [1, 2, 3, 4, 5, 6] will yield (1, 2), then (3, 4) ...

Must have even number of items.

Parameters:iterable – An iterable with even number of items to be iterated over.
cfme.utils.normalize_space(text)[source]

Works in accordance with the XPath’s normalize-space() operator.

Description:

The normalize-space function strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single space, and returns the resulting string.
cfme.utils.normalize_text(text)[source]

Converts a string to a lowercase string containing only letters, digits and spaces.

The space is always one character long if it is present.

cfme.utils.process_pytest_path(path)[source]
cfme.utils.process_shell_output(value)[source]

This function allows you to unify the behaviour when you putput some values to stdout.

You can check the code of the function how exactly does it behave for the particular types of variables. If no output is expected, it returns None.

Parameters:value – Value to be outputted.
Returns:A tuple consisting of returncode and the output to be printed.
cfme.utils.read_env(file)[source]

Given a py.path.Local file name, return a dict of exported shell vars and their values.

Parameters:file – A py.path.Local instance.

Note

This will only include shell variables that are exported from the file being parsed

Returns:A dict of key/value pairs. If the file does not exist or bash could not parse the file, this dict will be empty.
cfme.utils.safe_string(o)[source]

This will make string out of ANYTHING without having to worry about the stupid Unicode errors

This function tries to make str/unicode out of o unless it already is one of those and then it processes it so in the end there is a harmless ascii string.

Parameters:o – Anything.
cfme.utils.tries(num_tries, exceptions, f, *args, **kwargs)[source]

Tries to call the function multiple times if specific exceptions occur.

Parameters:
  • num_tries – How many times to try if exception is raised
  • exceptions – Tuple (or just single one) of exceptions that should be treated as repeat.
  • f – Callable to be called.
  • *args – Arguments to be passed through to the callable
  • **kwargs – Keyword arguments to be passed through to the callable
Returns:

What f returns.

Raises:

What f raises if the try count is exceeded.