def assert_mode(path, mode):
    """
    Assert last 3 octal mode digits match given mode exactly

    Parameters
    ----------
    path : pathlib.Path
        Path whose mode to assert
    mode : int
        Expected mode
    """
    actual = path.stat().st_mode & 511
    assert actual == mode, '{:o} != {:o}'.format(actual, mode)
