How to use the mqttwarn.util.load_functions function in mqttwarn

To help you get started, we’ve selected a few mqttwarn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jpmens / mqttwarn / tests / test_util.py View on Github external
def test_load_functions():

    # Load valid functions file
    py_mod = load_functions(filepath=funcfile)
    assert py_mod is not None

    # No-op
    py_mod = load_functions(filepath=None)
    assert py_mod is None

    # Load missing functions file
    with pytest.raises(IOError) as excinfo:
        load_functions(filepath='unknown.txt')
    assert str(excinfo.value) == "'{}' not found".format('unknown.txt')

    # Load functions file that is not a python file
    with pytest.raises(ValueError) as excinfo:
        load_functions(filepath=configfile)
    assert str(excinfo.value) == "'{}' does not have the .py or .pyc extension".format(configfile)
github jpmens / mqttwarn / tests / test_util.py View on Github external
py_mod = load_functions(filepath=None)
    assert py_mod is None

    # Load missing functions file
    with pytest.raises(IOError) as excinfo:
        load_functions(filepath='unknown.txt')
    assert str(excinfo.value) == "'{}' not found".format('unknown.txt')

    # Load functions file that is not a python file
    with pytest.raises(ValueError) as excinfo:
        load_functions(filepath=configfile)
    assert str(excinfo.value) == "'{}' does not have the .py or .pyc extension".format(configfile)

    # Load bad functions file
    with pytest.raises(Exception):
        load_functions(filepath=bad_funcfile)
github jpmens / mqttwarn / tests / test_util.py View on Github external
def test_load_function():

    # Load valid functions file
    py_mod = load_functions(filepath=funcfile)
    assert py_mod is not None

    # Load valid function
    func = load_function(name='foobar', py_mod=py_mod)
    assert func is not None

    # Load invalid function, function name does not exist in "funcfile"
    with pytest.raises(AttributeError) as excinfo:
        load_function(name='unknown', py_mod=py_mod)
    assert re.match("Function 'unknown' does not exist in '{}c?'".format(funcfile), str(excinfo.value))
github jpmens / mqttwarn / mqttwarn / configuration.py View on Github external
if self.ca_certs is not None:
            self.tls = True

        if self.tls_version is not None:
            if self.tls_version == 'tlsv1_2':
                self.tls_version = ssl.PROTOCOL_TLSv1_2
            if self.tls_version == 'tlsv1_1':
                self.tls_version = ssl.PROTOCOL_TLSv1_1
            if self.tls_version == 'tlsv1':
                self.tls_version = ssl.PROTOCOL_TLSv1
            if self.tls_version == 'sslv3':
                self.tls_version = ssl.PROTOCOL_SSLv3

        self.loglevelnumber = self.level2number(self.loglevel)
        self.functions = load_functions(self.functions)