test_cygwin_copy.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Test yadm.cygwin_copy"""
  2. import os
  3. import pytest
  4. @pytest.mark.parametrize(
  5. 'setting, is_cygwin, expect_link, pre_existing', [
  6. (None, False, True, None),
  7. (True, False, True, None),
  8. (False, False, True, None),
  9. (None, True, True, None),
  10. (True, True, False, None),
  11. (False, True, True, None),
  12. (True, True, False, 'link'),
  13. (True, True, False, 'file'),
  14. ],
  15. ids=[
  16. 'unset, non-cygwin',
  17. 'true, non-cygwin',
  18. 'false, non-cygwin',
  19. 'unset, cygwin',
  20. 'true, cygwin',
  21. 'false, cygwin',
  22. 'pre-existing symlink',
  23. 'pre-existing file',
  24. ])
  25. @pytest.mark.usefixtures('ds1_copy')
  26. def test_cygwin_copy(
  27. runner, yadm_y, paths, cygwin_sys, tst_sys,
  28. setting, is_cygwin, expect_link, pre_existing):
  29. """Test yadm.cygwin_copy"""
  30. if setting is not None:
  31. os.system(' '.join(yadm_y('config', 'yadm.cygwin-copy', str(setting))))
  32. expected_content = f'test_cygwin_copy##{tst_sys}'
  33. alt_path = paths.work.join('test_cygwin_copy')
  34. if pre_existing == 'symlink':
  35. alt_path.mklinkto(expected_content)
  36. elif pre_existing == 'file':
  37. alt_path.write('wrong content')
  38. uname_path = paths.root.join('tmp').mkdir()
  39. if is_cygwin:
  40. uname = uname_path.join('uname')
  41. uname.write(f'#!/bin/sh\necho "{cygwin_sys}"\n')
  42. uname.chmod(0o777)
  43. expected_content = f'test_cygwin_copy##{cygwin_sys}'
  44. env = os.environ.copy()
  45. env['PATH'] = ':'.join([str(uname_path), env['PATH']])
  46. run = runner(yadm_y('alt'), env=env)
  47. assert run.success
  48. assert run.err == ''
  49. assert 'Linking' in run.out
  50. assert alt_path.read() == expected_content
  51. assert alt_path.islink() == expect_link