Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testShellItem.py 2.8KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Test IShellItem and related interfaces
  2. import unittest
  3. from win32com.shell import knownfolders, shell, shellcon
  4. class TestShellItem(unittest.TestCase):
  5. def assertShellItemsEqual(self, i1, i2):
  6. n1 = i1.GetDisplayName(shellcon.SHGDN_FORPARSING)
  7. n2 = i2.GetDisplayName(shellcon.SHGDN_FORPARSING)
  8. self.assertEqual(n1, n2)
  9. def test_idlist_roundtrip(self):
  10. pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
  11. item = shell.SHCreateItemFromIDList(pidl, shell.IID_IShellItem)
  12. pidl_back = shell.SHGetIDListFromObject(item)
  13. self.assertEqual(pidl, pidl_back)
  14. def test_parsing_name(self):
  15. sf = shell.SHGetDesktopFolder()
  16. flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
  17. children = sf.EnumObjects(0, flags)
  18. child_pidl = next(children)
  19. name = sf.GetDisplayNameOf(child_pidl, shellcon.SHGDN_FORPARSING)
  20. item = shell.SHCreateItemFromParsingName(name, None, shell.IID_IShellItem)
  21. # test the name we get from the item is the same as from the folder.
  22. self.assertEqual(name, item.GetDisplayName(shellcon.SHGDN_FORPARSING))
  23. def test_parsing_relative(self):
  24. desktop_pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
  25. desktop_item = shell.SHCreateItemFromIDList(desktop_pidl, shell.IID_IShellItem)
  26. sf = shell.SHGetDesktopFolder()
  27. flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
  28. children = sf.EnumObjects(0, flags)
  29. child_pidl = next(children)
  30. name_flags = shellcon.SHGDN_FORPARSING | shellcon.SHGDN_INFOLDER
  31. name = sf.GetDisplayNameOf(child_pidl, name_flags)
  32. item = shell.SHCreateItemFromRelativeName(
  33. desktop_item, name, None, shell.IID_IShellItem
  34. )
  35. # test the name we get from the item is the same as from the folder.
  36. self.assertEqual(name, item.GetDisplayName(name_flags))
  37. def test_create_in_known_folder(self):
  38. item = shell.SHCreateItemInKnownFolder(
  39. knownfolders.FOLDERID_Desktop, 0, None, shell.IID_IShellItem
  40. )
  41. # this will do for now :)
  42. def test_create_item_with_parent(self):
  43. desktop_pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
  44. desktop_item = shell.SHCreateItemFromIDList(desktop_pidl, shell.IID_IShellItem)
  45. sf = shell.SHGetDesktopFolder()
  46. flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
  47. children = sf.EnumObjects(0, flags)
  48. child_pidl = next(children)
  49. item1 = shell.SHCreateItemWithParent(
  50. desktop_pidl, None, child_pidl, shell.IID_IShellItem
  51. )
  52. item2 = shell.SHCreateItemWithParent(None, sf, child_pidl, shell.IID_IShellItem)
  53. self.assertShellItemsEqual(item1, item2)
  54. if __name__ == "__main__":
  55. unittest.main()