# Path: ubelt/util_links.py
# def symlink(real_path, link_path, overwrite=False, verbose=0):
# def _readlink(link):
# def _can_symlink(verbose=0):  # nocover
# def _dirstats(dpath=None):  # nocover
#             E = os.path.exists(full_path)
#             L = os.path.islink(full_path)
#             F = os.path.isfile(full_path)
#             D = os.path.isdir(full_path)
#             J = util_platform.WIN32 and _win32_links._win32_is_junction(full_path)
#             ELFDJ = [E, L, F, D, J]


from os.path import isdir
from os.path import isfile
from os.path import islink
from os.path import join, exists, relpath, dirname
from ubelt import util_links
            from ubelt import _win32_links
    from functools import wraps
        from ubelt import _win32_links
import ubelt as ub
import pytest
import os
        import sys
    import xdoctest
"""
TODO: test _can_symlink=False variants on systems that can symlink.
"""


def test_rel_dir_link():
    dpath = ub.ensure_app_cache_dir('ubelt', 'test_rel_dir_link')
    ub.delete(dpath, verbose=2)
    ub.ensuredir(dpath, verbose=2)

    real_dpath = join(ub.ensuredir((dpath, 'dir1')), 'real')
    link_dpath = join(ub.ensuredir((dpath, 'dir2')), 'link')
    ub.ensuredir(real_dpath)

    orig = os.getcwd()
    try:
        os.chdir(dpath)
        real_path = relpath(real_dpath, dpath)
        link_path = relpath(link_dpath, dpath)
        link = ub.symlink(real_path, link_path)
        # Note: on windows this is hacked.

# Path: ubelt/util_links.py
# def symlink(real_path, link_path, overwrite=False, verbose=0):
# def _readlink(link):
# def _can_symlink(verbose=0):  # nocover
# def _dirstats(dpath=None):  # nocover
#             E = os.path.exists(full_path)
#             L = os.path.islink(full_path)
#             F = os.path.isfile(full_path)
#             D = os.path.isdir(full_path)
#             J = util_platform.WIN32 and _win32_links._win32_is_junction(full_path)
#             ELFDJ = [E, L, F, D, J]


# Path: tests/test_links.py
from os.path import isdir
from os.path import isfile
from os.path import islink
from os.path import join, exists, relpath, dirname
from ubelt import util_links
            from ubelt import _win32_links
    from functools import wraps
        from ubelt import _win32_links
import ubelt as ub
import pytest
import os
        import sys
    import xdoctest

"""
TODO: test _can_symlink=False variants on systems that can symlink.
"""


def test_rel_dir_link():
    dpath = ub.ensure_app_cache_dir('ubelt', 'test_rel_dir_link')
    ub.delete(dpath, verbose=2)
    ub.ensuredir(dpath, verbose=2)

    real_dpath = join(ub.ensuredir((dpath, 'dir1')), 'real')
    link_dpath = join(ub.ensuredir((dpath, 'dir2')), 'link')
    ub.ensuredir(real_dpath)

    orig = os.getcwd()
    try:
        os.chdir(dpath)
        real_path = relpath(real_dpath, dpath)
        link_path = relpath(link_dpath, dpath)
        link = ub.symlink(real_path, link_path)
        # Note: on windows this is hacked.

        pointed = ub.util_links._readlink(link)