File: utils.py

package info (click to toggle)
python-testbook 0.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: python: 1,045; makefile: 11
file content (34 lines) | stat: -rw-r--r-- 840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
import string


def random_varname(length=10):
    """
    Creates a random variable name as string of a given length.
    This is used in testbook to generate temporary variables within the notebook.

    Parameters
    ----------
        length (int)

    Returns:
    --------
        random variable name as string of given length
    """
    return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))


def all_subclasses(klass):
    """
    This is a function that returns a generator.

    Inspects subclasses associated with a given class in a recursive manner
    and yields them, such that subclasses of subclasses will be yielded.

    Parameters:
    -----------
        klass
    """
    for subklass in klass.__subclasses__():
        yield subklass
        yield from all_subclasses(subklass)