Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_fsbrowser_item.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from pathlib import Path
  2. from ..fsbrowser_item import FSBrowserItem
  3. from datalad.distribution.dataset import Dataset
  4. from datalad.tests.utils_pytest import (
  5. assert_equal,
  6. assert_in,
  7. assert_not_in,
  8. assert_raises,
  9. )
  10. from PySide6.QtCore import (
  11. Qt,
  12. )
  13. from ..status_light import GooeyStatusLight
  14. def test_GooeyStatusLight(tmp_path):
  15. ds = Dataset(tmp_path).create()
  16. GooeyStatusLight.__call__(dataset=ds, path=ds.pathobj)
  17. def test_FSBrowserItem():
  18. fsb_item = FSBrowserItem(Path.cwd())
  19. assert_equal(fsb_item.pathobj, Path.cwd())
  20. assert_equal(fsb_item.__str__(), f'FSBrowserItem<{Path.cwd()}>')
  21. def test_pathobj_none():
  22. with assert_raises(RuntimeError):
  23. FSBrowserItem(None).pathobj()
  24. item_types = ['directory', 'symlink', 'file', 'dataset']
  25. lsdir_results = [
  26. {
  27. 'path': f'some_{t}.txt',
  28. 'type': t,
  29. 'action': 'gooey-lsdir',
  30. 'status': 'ok'
  31. }
  32. for t in item_types
  33. ]
  34. lsdir_results+=\
  35. [
  36. {
  37. 'path': 'test_error_no_message',
  38. 'type': 'file',
  39. 'action': 'gooey-lsdir',
  40. 'status': 'error',
  41. 'message': ''
  42. },
  43. {
  44. 'path': 'test_error_with_message',
  45. 'type': 'file',
  46. 'action': 'gooey-lsdir',
  47. 'status': 'error',
  48. 'message': 'Permissions denied'
  49. },
  50. ]
  51. def test_update_from_lsdir_result():
  52. for res in lsdir_results:
  53. fsb_item = FSBrowserItem(res['path'])
  54. fsb_item.update_from_lsdir_result(res)
  55. # check if item type is same as result type
  56. assert_equal(fsb_item.datalad_type, res['type'])
  57. # test status 'error'
  58. if res['status'] == 'error'\
  59. and res['message'] == 'Permissions denied':
  60. # test isDisabled is correct
  61. assert_equal(fsb_item.isDisabled(), True)
  62. # test status 'ok'
  63. if res['status'] == 'ok':
  64. # test isDisabled is correct
  65. assert_equal(fsb_item.isDisabled(), False)
  66. # test childIndicatorPolicy
  67. if res['type'] in ('directory', 'dataset'):
  68. assert_equal(fsb_item.childIndicatorPolicy(), 0)
  69. # test directory state is None
  70. if res['type'] == 'directory':
  71. assert_equal(fsb_item.data(2, Qt.EditRole), None)
  72. states = ['untracked', 'clean', 'modified', 'deleted', 'unknown', 'added']
  73. status_light_results = [
  74. {
  75. 'path': f'dataset/some_file_{i}.txt',
  76. 'type': 'file',
  77. 'action': 'status',
  78. 'status': 'ok',
  79. 'refds': 'dataset',
  80. 'state': state
  81. }
  82. for i, state in enumerate(states)
  83. ]
  84. status_light_results+=\
  85. [
  86. {
  87. 'path': 'dataset/some_dir',
  88. 'type': 'directory',
  89. 'action': 'status',
  90. 'status': 'ok',
  91. 'refds': 'dataset'
  92. },
  93. {
  94. 'path': 'dataset/some_other_file.txt',
  95. 'type': 'file',
  96. 'action': 'status',
  97. 'status': 'error',
  98. 'message': 'something_went_wrong',
  99. 'refds': 'dataset'
  100. },
  101. ]
  102. def test_update_from_status_result():
  103. """"""
  104. for res in status_light_results:
  105. fsb_item = FSBrowserItem(res['path'])
  106. fsb_item.update_from_status_result(res)
  107. state = res.get('state')
  108. if state is None:
  109. if res.get('status') == 'error' and 'message' in res:
  110. assert_equal(fsb_item.data(2, Qt.EditRole), res.get('message'))
  111. else:
  112. assert_equal(fsb_item.data(2, Qt.EditRole), state)
  113. if state == 'deleted':
  114. assert_equal(fsb_item.childIndicatorPolicy(), 1)
  115. # test item type
  116. assert_equal(fsb_item.data(1, Qt.EditRole), res.get('type'))
  117. res1 = {
  118. 'path': 'parent_dir/child1',
  119. 'type': 'directory',
  120. 'action': 'gooey-lsdir',
  121. 'status': 'ok'
  122. }
  123. res2 = {
  124. 'path': 'parent_dir/child2',
  125. 'type': 'file',
  126. 'action': 'gooey-lsdir',
  127. 'status': 'ok'
  128. }
  129. def test_item_children():
  130. # create parent item and two child items
  131. fsb_parent = FSBrowserItem(Path('parent_dir'))
  132. fsb_child1 = FSBrowserItem.from_lsdir_result(res1, parent=fsb_parent)
  133. fsb_child2 = FSBrowserItem.from_lsdir_result(res2, parent=fsb_parent)
  134. # check that child items are in fact children of parent
  135. children = list(fsb_parent.children_())
  136. assert_in(fsb_child1, children)
  137. assert_in(fsb_child2, children)
  138. # remove a child and check result
  139. fsb_parent.removeChild(fsb_child1)
  140. children = list(fsb_parent.children_())
  141. assert_not_in(fsb_child1, children)
  142. assert_in(fsb_child2, children)