Пример #1
0
def test_configure_ipython_exc_logging_with_nonexisting_dir(tmpdir):
    log_dir = Path(tmpdir) / Path("does_not_exist")
    log_file_path = log_dir / Path("bluesky_ipython.log")

    ip = IPython.core.interactiveshell.InteractiveShell()
    os.environ["BLUESKY_IPYTHON_LOG_FILE"] = str(log_file_path)
    with pytest.raises(UserWarning):
        configure_ipython_logging(
            exception_logger=log_exception,
            ipython=ip,
        )
Пример #2
0
def test_configure_ipython_exc_logging_with_unwriteable_dir(tmpdir):
    log_dir = Path(tmpdir)
    log_file_path = log_dir / Path("bluesky_ipython.log")

    log_dir.chmod(stat.S_IREAD)

    ip = IPython.core.interactiveshell.InteractiveShell()
    os.environ["BLUESKY_IPYTHON_LOG_FILE"] = str(log_file_path)
    with pytest.raises(PermissionError):
        configure_ipython_logging(
            exception_logger=log_exception,
            ipython=ip,
        )
Пример #3
0
def test_ipython_exc_logging_existing_default_dir():
    """
    Remove environment variable BLUESKY_IPYTHON_LOG_FILE and
    test that the default log file path is used. This test creates
    a directory rather than using pytest's tmp_path so the test
    must clean up at the end.
    """
    test_appname = "bluesky-test"
    log_dir = Path(appdirs.user_log_dir(appname=test_appname))
    # create the default log directory
    log_dir.mkdir(parents=True, exist_ok=True)
    log_file_path = log_dir / Path("bluesky_ipython.log")

    ip = IPython.core.interactiveshell.InteractiveShell()
    os.environ.pop("BLUESKY_IPYTHON_LOG_FILE", default=None)
    bluesky_ipython_log_file_path = configure_ipython_logging(
        exception_logger=log_exception,
        ipython=ip,
        appdirs_appname=test_appname)

    assert bluesky_ipython_log_file_path == log_file_path
    assert log_file_path.exists()

    bluesky_ipython_log_file_path.unlink()
    bluesky_ipython_log_file_path.parent.rmdir()
Пример #4
0
def test_configure_ipython_exc_logging(tmpdir):
    log_file_path = Path(tmpdir) / Path("bluesky_ipython.log")

    ip = IPython.core.interactiveshell.InteractiveShell()
    os.environ["BLUESKY_IPYTHON_LOG_FILE"] = str(log_file_path)
    bluesky_ipython_log_file_path = configure_ipython_logging(
        exception_logger=log_exception,
        ipython=ip,
    )
    assert bluesky_ipython_log_file_path == log_file_path
    assert log_file_path.exists()
Пример #5
0
def test_configure_ipython_exc_logging_rotate(tmpdir):
    log_file_path = Path(tmpdir) / Path("bluesky_ipython.log")

    with open(log_file_path, "w") as f:
        f.write("log log log")

    ip = IPython.core.interactiveshell.InteractiveShell()
    os.environ["BLUESKY_IPYTHON_LOG_FILE"] = str(log_file_path)
    bluesky_ipython_log_file_path = configure_ipython_logging(
        exception_logger=log_exception, ipython=ip, rotate_file_size=0)
    assert bluesky_ipython_log_file_path == log_file_path
    assert log_file_path.exists()

    old_log_file_path = log_file_path.parent / Path(log_file_path.name +
                                                    ".old")
    assert old_log_file_path.exists()