'The resulting ``virtualenv`` only contains symlinks to files inside the
virtualenv and to /usr on the host OS.'

def test_internal_symlinks_only(self):

    target_path = FilePath(self.mktemp())
    create_virtualenv(root=target_path)
    allowed_targets = (target_path, FilePath('/usr'))
    bad_links = []
    for path in target_path.walk():
        if path.islink():
            realpath = path.realpath()
            for allowed_target in allowed_targets:
                try:
                    realpath.segmentsFrom(allowed_target)
                except ValueError:
                    pass
                else:
                    break
            else:
                bad_links.append(path)
    if bad_links:
        self.fail(('Symlinks    outside    of    virtualenv    detected:' + '\n'.join(((('/'.join(path.segmentsFrom(target_path)) + '    ->    ') + path.realpath().path) for path in bad_links))))
