def test_broken_link(): """ CommandLine: python -m ubelt.tests.test_links test_broken_link """ dpath = ub.ensure_app_cache_dir('ubelt', 'test_broken_link') ub.delete(dpath, verbose=2) ub.ensuredir(dpath, verbose=2) util_links._dirstats(dpath) broken_fpath = join(dpath, 'broken_fpath.txt') broken_flink = join(dpath, 'broken_flink.txt') ub.touch(broken_fpath, verbose=2) util_links._dirstats(dpath) ub.symlink(broken_fpath, broken_flink, verbose=2) util_links._dirstats(dpath) ub.delete(broken_fpath, verbose=2) util_links._dirstats(dpath) # make sure I am sane that this is the correct check. can_symlink = util_links._can_symlink() print('can_symlink = {!r}'.format(can_symlink)) if can_symlink: # normal behavior assert islink(broken_flink) assert not exists(broken_flink) else: # on windows hard links are essentially the same file. # there is no trace that it was actually a link. assert exists(broken_flink)
def assert_broken_link(path, want=True): if util_links._can_symlink(): print('path={} should{} be a broken link'.format( path, ' ' if want else ' not')) positive = not exists(path) and islink(path) check_path_condition(path, positive, want, 'broken link') else: # TODO: we can test this # positive = util_links._win32_is_junction(path) print('path={} should{} be a broken link (junction)'.format( path, ' ' if want else ' not')) print('cannot check this yet')