예제 #1
0
def new_child(options, inherit=None):
    """
    Return a new child.
    """
    if options is None:
        return None
    if inherit is None:
        inherit = dict()
    unify_keys(options)
    try:
        tmp_type = options.pop("type")
    except KeyError:
        raise SimplevisorError(
            "type not specified for entry: %s" % (options, ))
    tmp_expected = inherit.get("expected", DEFAULT_EXPECTED)
    if tmp_expected != "none":
        options["expected"] = tmp_expected
    if tmp_type == "service":
        try:
            child = Service(**options)
        except TypeError:
            error = sys.exc_info()[1]
            raise SimplevisorError(
                "Service entry not valid:\n%s\n%s" % (options, error))
    elif tmp_type == "supervisor":
        try:
            child = Supervisor(**options)
        except TypeError:
            error = sys.exc_info()[1]
            raise SimplevisorError(
                "Supervisor entry not valid:\n%s\n%s" % (options, error))
    else:
        raise SimplevisorError(
            "entry type non supported: %s" % (tmp_type,))
    return child
예제 #2
0
 def test_unicode_keywords_function(self):
     """ Test unicode keywords function. """
     error = None
     unicode_dict = {u_('hello'): 'world'}
     try:
         some_function(**unicode_dict)
     except Exception:
         error = sys.exc_info()[1]
     if type(error) is TypeError:
         unify_keys(unicode_dict)
         some_function(**unicode_dict)
예제 #3
0
 def test_unify_keys(self, error, given, result):
     """ Test unify keys. """
     print("running unify keys for %s" % (given, ))
     got = None
     result_got = None
     try:
         result_got = unify_keys(given)
     except Exception:
         got = type(sys.exc_info()[1])
     if got == error:
         if result_got != result:
             raise AssertionError(
                 "%s was expected to return %s, it returned %s" %
                 (given, result, result_got, ))
     else:
         raise AssertionError(
             "%s was expected to fail with error: %s" %
             (given, error, ))
     print("...test unify keys ok")