test_setuptools.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import pytest
  3. import setuptools
  4. @pytest.fixture
  5. def example_source(tmpdir):
  6. tmpdir.mkdir('foo')
  7. (tmpdir / 'foo/bar.py').write('')
  8. (tmpdir / 'readme.txt').write('')
  9. return tmpdir
  10. def test_findall(example_source):
  11. found = list(setuptools.findall(str(example_source)))
  12. expected = ['readme.txt', 'foo/bar.py']
  13. expected = [example_source.join(fn) for fn in expected]
  14. assert found == expected
  15. def test_findall_curdir(example_source):
  16. with example_source.as_cwd():
  17. found = list(setuptools.findall())
  18. expected = ['readme.txt', os.path.join('foo', 'bar.py')]
  19. assert found == expected
  20. @pytest.fixture
  21. def can_symlink(tmpdir):
  22. """
  23. Skip if cannot create a symbolic link
  24. """
  25. link_fn = 'link'
  26. target_fn = 'target'
  27. try:
  28. os.symlink(target_fn, link_fn)
  29. except (OSError, NotImplementedError, AttributeError):
  30. pytest.skip("Cannot create symbolic links")
  31. os.remove(link_fn)
  32. def test_findall_missing_symlink(tmpdir, can_symlink):
  33. with tmpdir.as_cwd():
  34. os.symlink('foo', 'bar')
  35. found = list(setuptools.findall())
  36. assert found == []