Example #1
0
def test_can_use_default_logger_based_on_connection_name(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection
    import logging

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost', name="ABC")
    assert isinstance(connection.logger, logging.Logger)
    assert connection.logger.name == "moler.connection.ABC.io"

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost')
    assert isinstance(connection.logger, logging.Logger)
    assert connection.logger.name == "moler.connection.{}.io".format(connection.name)
Example #2
0
def test_can_switch_off_logging(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  logger_name=None)
    assert connection.logger is None
Example #3
0
def test_uses_moler_connection_name_if_none_given(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    moler_conn.name = "srv2"
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost')
    assert connection.name == moler_conn.name
Example #4
0
def test_can_assign_name_to_connection(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  name="ctrl_server")
    assert connection.name == "ctrl_server"
Example #5
0
def test_can_use_provided_logger(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection
    import logging

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  logger_name="conn.web_srv")
    assert isinstance(connection.logger, logging.Logger)
    assert connection.logger.name == "conn.web_srv"
Example #6
0
def test_changing_connection_name_doesnt_activate_logger_if_logging_is_off(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  name="ABC",
                                                  logger_name=None)
    assert connection.logger is None
    connection.name = "DEF"
    assert connection.logger is None
Example #7
0
def test_changing_connection_name_doesnt_switch_logger_if_external_logger_used(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  name="ABC",
                                                  logger_name="conn.ABC")
    assert connection.logger.name == "conn.ABC"
    connection.name = "DEF"
    assert connection.logger.name == "conn.ABC"
Example #8
0
def test_overwrites_moler_connection_name_with_own_one(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    moler_conn = Connection()
    # during construction
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost', name="web_srv")
    assert moler_conn.name == "web_srv"
    # during direct attribute set
    connection.name = "http_srv"
    assert moler_conn.name == "http_srv"
Example #9
0
def test_changing_connection_name_switches_logger_if_default_logger_used(active_sshshell_connection_class):
    from moler.abstract_moler_connection import AbstractMolerConnection as Connection

    # default logger generated internally by connection
    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  name="ABC")
    assert connection.logger.name == "moler.connection.ABC.io"

    connection.name = "DEF"
    assert connection.logger.name == "moler.connection.DEF.io"
    assert connection.sshshell.logger.name == "moler.connection.DEF.io"

    # default logger via default naming
    moler_conn = Connection()
    connection = active_sshshell_connection_class(moler_connection=moler_conn, host='localhost',
                                                  name="ABC",
                                                  logger_name="moler.connection.ABC.io")
    connection.name = "DEF"
    assert connection.logger.name == "moler.connection.DEF.io"
    assert connection.sshshell.logger.name == "moler.connection.DEF.io"