test_symlink.py 846 B

123456789101112131415161718192021222324252627282930
  1. import pytest
  2. import osex
  3. import os
  4. import sys
  5. def test_new(tmpdir):
  6. os.chdir(tmpdir.strpath)
  7. osex.symlink("source", "link")
  8. assert os.path.lexists("link")
  9. assert os.readlink("link") == "source"
  10. def test_absolute(tmpdir):
  11. os.chdir(tmpdir.strpath)
  12. os.makedirs(os.path.join("1", "2"))
  13. link = os.path.join("1", "2", "link")
  14. source = os.path.join(os.getcwd(), "1", "source")
  15. osex.symlink(source, link, relative = False)
  16. assert os.path.lexists(link)
  17. assert os.readlink(link) == source
  18. def test_relative(tmpdir):
  19. os.chdir(tmpdir.strpath)
  20. os.makedirs(os.path.join("1", "2"))
  21. link = os.path.join("1", "2", "link")
  22. source = os.path.join(os.getcwd(), "1", "source")
  23. osex.symlink(source, link, relative = True)
  24. assert os.path.lexists(link)
  25. assert os.readlink(link) == "../source"