示例#1
0
def test_append_sleuth_to_customize(request, caplog):
    caplog.set_level(logging.INFO)
    customize_path = Path("yow")

    def fin():
        if customize_path.exists():
            customize_path.unlink()

    request.addfinalizer(finalizer=fin)
    fin()  # run ahead in case failed tests left junk

    syspath_sleuth.create_site_customize(customize_path)
    syspath_sleuth.append_sleuth_to_customize(customize_path)
    record: logging.LogRecord
    for record in caplog.get_records("call"):
        if f"Appending {SysPathSleuth.__name__} to site customize: yow" in record.message:
            assert record.levelname == "INFO"
            break
    else:
        pytest.fail("Did not find expected log record.")

    assert customize_path.exists()
    src_lines: List[str]
    src_lines, _ = inspect.getsourcelines(
        runtime_syspath.syspath_sleuth.syspath_sleuth)

    with customize_path.open() as site_customize_path_f:
        site_customize_lines: List[str] = site_customize_path_f.readlines()

    assert src_lines == site_customize_lines
示例#2
0
def test_create_reverse_sleuth_patch(request):
    customize_path = Path("yow")
    copied_customize_path = customize_path.with_suffix(
        syspath_sleuth.PRE_SLEUTH_SUFFIX)
    reverse_patch_path = customize_path.with_suffix(
        syspath_sleuth.REVERSE_PATCH_SUFFIX)

    def fin():
        if customize_path.exists():
            customize_path.unlink()
        if copied_customize_path.exists():
            copied_customize_path.unlink()
        if reverse_patch_path.exists():
            reverse_patch_path.unlink()

    request.addfinalizer(finalizer=fin)
    fin()  # run ahead in case failed tests left junk

    syspath_sleuth.create_site_customize(customize_path)
    assert customize_path.exists()

    syspath_sleuth.copy_site_customize(customize_path)
    copied_customize_path.exists()

    syspath_sleuth.append_sleuth_to_customize(customize_path)
    assert customize_path.exists() and customize_path.stat().st_size > 0

    syspath_sleuth.create_reverse_sleuth_patch(customize_path)
    assert not copied_customize_path.exists()
    assert reverse_patch_path.exists()
示例#3
0
def test_copy_site_customize(request):
    test_path = Path("yow")
    copied_file_path = test_path.with_suffix(syspath_sleuth.PRE_SLEUTH_SUFFIX)

    def fin():
        if test_path.exists():
            test_path.unlink()
        if copied_file_path.exists():
            copied_file_path.unlink()

    request.addfinalizer(finalizer=fin)
    fin()  # run ahead in case failed tests left junk

    syspath_sleuth.create_site_customize(test_path)
    syspath_sleuth.copy_site_customize(test_path)

    assert copied_file_path.exists()
示例#4
0
def test_reverse_patch_sleuth(request, caplog):
    caplog.set_level(logging.INFO)
    customize_path = Path("yow")
    copied_customize_path = customize_path.with_suffix(
        syspath_sleuth.PRE_SLEUTH_SUFFIX)
    reverse_patch_path = customize_path.with_suffix(
        syspath_sleuth.REVERSE_PATCH_SUFFIX)

    def fin():
        if customize_path.exists():
            customize_path.unlink()
        if copied_customize_path.exists():
            copied_customize_path.unlink()
        if reverse_patch_path.exists():
            reverse_patch_path.unlink()

    request.addfinalizer(finalizer=fin)
    fin()  # run ahead in case failed tests left junk

    syspath_sleuth.create_site_customize(customize_path)
    assert customize_path.exists()

    syspath_sleuth.copy_site_customize(customize_path)
    copied_customize_path.exists()

    syspath_sleuth.append_sleuth_to_customize(customize_path)
    assert customize_path.exists() and customize_path.stat().st_size > 0

    syspath_sleuth.create_reverse_sleuth_patch(customize_path)
    assert not copied_customize_path.exists()
    assert reverse_patch_path.exists()

    syspath_sleuth.reverse_patch_sleuth(customize_path)

    assert not reverse_patch_path.exists()
    assert not customize_path.exists()

    record: logging.LogRecord
    for record in caplog.get_records("call"):
        if f"Removing {SysPathSleuth.__name__} from site customize: yow" in record.message:
            assert record.levelname == "INFO"
            break
    else:
        pytest.fail("Did not find expected log record.")
示例#5
0
def test_create_site_customize(request, caplog):
    test_path = Path("yow.yowsa")

    def fin():
        if test_path.exists():
            test_path.unlink()

    request.addfinalizer(finalizer=fin)
    fin()  # run ahead in case failed tests left junk

    syspath_sleuth.create_site_customize(test_path)

    record: logging.LogRecord
    for record in caplog.get_records("call"):
        if "Creating system site: yow.yowsa" in record.message:
            assert record.levelname == "WARNING"
            break

    assert test_path.exists()