import pytest import osex import os def test_new(tmpdir): os.chdir(tmpdir.strpath) osex.symlink("source", "link") assert os.path.lexists("link") assert os.readlink("link") == "source" def test_absolute1(tmpdir): os.chdir(tmpdir.strpath) os.makedirs(os.path.join("1", "2")) link = os.path.join("1", "2", "link") source = os.path.join(os.getcwd(), "1", "source") osex.symlink(source, link) assert os.path.lexists(link) assert os.readlink(link) == source def test_absolute2(tmpdir): os.chdir(tmpdir.strpath) os.makedirs(os.path.join("1", "2")) link = os.path.join("1", "2", "link") source = os.path.join(os.getcwd(), "1", "source") osex.symlink(source, link, relative = False) assert os.path.lexists(link) assert os.readlink(link) == source def test_relative(tmpdir): os.chdir(tmpdir.strpath) os.makedirs(os.path.join("1", "2")) link = os.path.join("1", "2", "link") source = os.path.join(os.getcwd(), "1", "source") osex.symlink(source, link, relative = True) assert os.path.lexists(link) assert os.readlink(link) == "../source" def test_suitable_link_exists(tmpdir): os.chdir(tmpdir.strpath) osex.symlink("source", "link") assert os.path.lexists("link") osex.symlink("source", "link") osex.symlink("source", "link", override = False) def test_divergent_link_exists(tmpdir): os.chdir(tmpdir.strpath) osex.symlink("source1", "link") assert os.path.lexists("link") with pytest.raises(OSError): osex.symlink("source2", "link") with pytest.raises(OSError): osex.symlink("source3", "link", override = False) def test_dir_exists(tmpdir): os.chdir(tmpdir.strpath) os.mkdir("dir") assert os.path.exists("dir") with pytest.raises(OSError): osex.symlink("source", "dir") with pytest.raises(OSError): osex.symlink("source", "dir", override = False) def test_override(tmpdir): os.chdir(tmpdir.strpath) osex.symlink("source1", "link") assert os.path.lexists("link") osex.symlink("source2", "link", override = True) assert os.path.lexists("link") assert os.readlink("link") == "source2"