test_commonpath.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. from larigira.unused import old_commonpath
  3. def test_same():
  4. assert old_commonpath(['/foo/bar', '/foo/bar/']) == '/foo/bar'
  5. def test_prefix():
  6. assert old_commonpath(['/foo/bar', '/foo/zap/']) == '/foo'
  7. assert old_commonpath(['/foo/bar/', '/foo/zap/']) == '/foo'
  8. assert old_commonpath(['/foo/bar/', '/foo/zap']) == '/foo'
  9. assert old_commonpath(['/foo/bar', '/foo/zap']) == '/foo'
  10. try:
  11. from os.path import commonpath
  12. except ImportError:
  13. pass # TODO: log the fact and clarify
  14. else:
  15. # these tests are only available on python >= 3.5. That's fine though, as
  16. # our CI will perform validation of those cases to see if they match python
  17. # behavior
  18. @pytest.fixture(params=['a', 'a/', 'a/b', 'a/b/', 'a/b/c', ])
  19. def relpath(request):
  20. return request.param
  21. @pytest.fixture
  22. def abspath(relpath):
  23. return '/' + relpath
  24. @pytest.fixture(params=['', '/'])
  25. def slashed_abspath(abspath, request):
  26. return '%s%s' % (abspath, request.param)
  27. slashed_abspath_b = slashed_abspath
  28. @pytest.fixture
  29. def abspath_couple(slashed_abspath, slashed_abspath_b):
  30. return (slashed_abspath, slashed_abspath_b)
  31. def test_abspath_match(abspath_couple):
  32. assert commonpath(abspath_couple) == old_commonpath(abspath_couple)
  33. @pytest.fixture(params=['', '/'])
  34. def slashed_relpath(relpath, request):
  35. s = '%s%s' % (relpath, request.param)
  36. if s:
  37. return s
  38. slashed_relpath_b = slashed_relpath
  39. @pytest.fixture
  40. def relpath_couple(slashed_relpath, slashed_relpath_b):
  41. return (slashed_relpath, slashed_relpath_b)
  42. def test_relpath_match(relpath_couple):
  43. assert commonpath(relpath_couple) == old_commonpath(relpath_couple)