def testAddGroup_01(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) self.assertEqual(collection.getGroups(), []) collection.addGroup('Новая группа') self.assertEqual(collection.getGroups(), ['Новая группа']) newcollection1 = IconsCollection(self.tempDir1) self.assertEqual(newcollection1.getGroups(), ['Новая группа'])
def testRenameGroup_03_self(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup('Новая группа') collection.renameGroup('Новая группа', 'Новая группа') self.assertEqual(collection.getGroups(), ['Новая группа']) newcollection = IconsCollection(self.tempDir1) self.assertEqual(newcollection.getGroups(), ['Новая группа'])
def testRemoveGroup_01(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') collection.addGroup(u'Другая группа') collection.removeGroup(u'Новая группа') self.assertEqual(collection.getGroups(), [u'Другая группа']) newcollection1 = IconsCollection(self.tempDir1) self.assertEqual(newcollection1.getGroups(), [u'Другая группа'])
def testRenameGroup_01(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') self.assertEqual(collection.getGroups(), [u'Новая группа']) collection.renameGroup(u'Новая группа', u'Переименованная группа') self.assertEqual(collection.getGroups(), [u'Переименованная группа']) newcollection1 = IconsCollection(self.tempDir1) self.assertEqual(newcollection1.getGroups(), [u'Переименованная группа'])
def testAddGroup_03(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) self.assertEqual(collection.getGroups(), []) collection.addGroup(u'Новая группа') collection.addGroup(u'Вторая группа') self.assertEqual(collection.getGroups(), [u'Вторая группа', u'Новая группа']) newcollection = IconsCollection(self.tempDir1) self.assertEqual(newcollection.getGroups(), [u'Вторая группа', u'Новая группа'])
def _getGroupsInfo(self): result = [] for n, path in enumerate(getIconsDirList()): # First None is root directory collection = IconsCollection(path) for groupname in [None] + sorted(collection.getGroups(), key=self._localize): # Get group name if groupname is None: title = _(u'Not in groups') else: title = self._localize(groupname) if n != 0: title += u' *' iconslist = collection.getIcons(groupname) cover = collection.getCover(groupname) result.append(IconsGroupInfo(iconslist, title, cover, sort_key=os.path.basename)) self._addRecentIconsGroup(result) return result
def _getGroupsInfo(self): result = [] for n, path in enumerate(getIconsDirList()): # First None is root directory collection = IconsCollection(path) for groupname in [None] + sorted(collection.getGroups(), key=self._localize): # Get group name if groupname is None: title = _(u'Not in groups') else: title = self._localize(groupname) iconslist = collection.getIcons(groupname) cover = collection.getCover(groupname) if cover is None: cover = self._default_group_cover group_type = (IconsGroupInfo.TYPE_BUILTIN if n == 0 else IconsGroupInfo.TYPE_CUSTOM) result.append(IconsGroupInfo(iconslist, title, cover, group_type=group_type, sort_key=os.path.basename)) self._addRecentIconsGroup(result) eventParam = IconsGroupsListInitParams(result) self._application.onIconsGroupsListInit(self._page, eventParam) return eventParam.groupsList
def testRenameGroup_04_self(self): files = [u'new.png', u'image_01.JPG'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') collection.addIcons(u'Новая группа', fullPaths) collection.renameGroup(u'Новая группа', u'Новая группа') self.assertEqual(collection.getGroups(), [u'Новая группа']) self.assertEqual(len(collection.getIcons(u'Новая группа')), 2) newcollection = IconsCollection(self.tempDir1) self.assertEqual(newcollection.getGroups(), [u'Новая группа']) self.assertEqual(len(newcollection.getIcons(u'Новая группа')), 2)
def testAddCover_01_group(self): files = [] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] groupname = u'Новая группа' os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(groupname) collection.addIcons(groupname, fullPaths) coverpath = os.path.join(self.imagesDir, u'icon.png') newCoverPath = os.path.join(self.tempDir1, groupname, IconsCollection.COVER_FILE_NAME) collection.setCover(groupname, coverpath) self.assertTrue(os.path.exists(newCoverPath)) self.assertEqual(os.path.abspath(newCoverPath), os.path.abspath(collection.getCover(groupname))) collection.setCover(groupname, coverpath) self.assertTrue( os.path.exists( os.path.join(self.tempDir1, groupname, IconsCollection.COVER_FILE_NAME)))
def testEmpty_01(self): collection = IconsCollection('testdata/icons/Без иконок') self.assertEqual(collection.getIcons(''), []) self.assertEqual(collection.getGroups(), []) self.assertRaises(KeyError, collection.getIcons, 'Группа') self.assertRaises(KeyError, collection.getCover, 'Группа') self.assertIsNone(collection.getCover(None))
def testRemoveGroup_02(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') collection.removeGroup(u'Новая группа') self.assertEqual(collection.getGroups(), [])
def testGroups_02(self): collection = IconsCollection(u'../test/icons/Только группы') self.assertEqual(len(collection.getIcons(None)), 0) self.assertEqual(collection.getGroups(), [u'Группа 3', u'Группа 4']) self.assertEqual(len(collection.getIcons(u'Группа 3')), 3) self.assertEqual(len(collection.getIcons(u'Группа 4')), 4) self.assertIsNone(collection.getCover(None))
def testEmpty_02(self): collection = IconsCollection(u'../test/icons/Без иконок') self.assertEqual(collection.getIcons(None), []) self.assertEqual(collection.getGroups(), []) self.assertRaises(KeyError, collection.getIcons, u'Группа') self.assertRaises(KeyError, collection.getCover, u'Группа') self.assertIsNone(collection.getCover(u''))
def testAddGroup_02_invalid(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) self.assertRaises(ValueError, collection.addGroup, 'Абырвалг\\Абырвалг') self.assertRaises(ValueError, collection.addGroup, 'Абырвалг/Абырвалг') self.assertRaises(ValueError, collection.addGroup, '')
def testAddIcons_04_invalid(self): files = [u'new.png'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) self.assertRaises(KeyError, collection.addIcons, u'Другая группа', fullPaths)
def testRemoveGroup_03_invalid(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') self.assertRaises(KeyError, collection.removeGroup, u'Абырвалг') self.assertRaises(KeyError, collection.removeGroup, u'')
def testRenameGroup_04_invalid(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') collection.addGroup(u'Абырвалг') self.assertRaises(DuplicateGroupError, collection.renameGroup, u'Новая группа', u'Абырвалг')
def testAddIcons_03_empty(self): files = [] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addIcons(u'', fullPaths) self.assertEqual(collection.getIcons(None), [])
def testAddIcons_02_empty(self): files = [] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup('Новая группа') collection.addIcons('Новая группа', fullPaths) self.assertEqual(collection.getIcons('Новая группа'), [])
def testAddCover_04_root_invalid(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) coverpath = os.path.join(self.imagesDir, u'invalid.png') collection.setCover(u'', coverpath) self.assertFalse( os.path.exists( os.path.join(self.tempDir1, IconsCollection.COVER_FILE_NAME)))
def __init__(self, parent): super(IconsPanel, self).__init__(parent) self._iconsCollections = [ IconsCollection(path) for path in getIconsDirList() ] self.__createGui() self.__appendGroups() self.groupCtrl.SetSelection(0) self.__switchToCurrentGroup()
def testGroups_01(self): collection = IconsCollection(u'../test/icons/Иконки и группы') self.assertEqual(len(collection.getIcons(None)), 4) self.assertEqual(collection.getGroups(), [u'Группа 1', u'Группа 2']) self.assertEqual(len(collection.getIcons(u'Группа 1')), 3) self.assertEqual(len(collection.getIcons(u'Группа 2')), 4) self.assertIsNone(collection.getCover(None)) self.assertTrue( collection.getCover(u'Группа 1').endswith(u'__cover.png')) self.assertIsNone(collection.getCover(u'Группа 2'))
def testAddIcons_06(self): files = [u'new.png'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addIcons(None, fullPaths) icons = collection.getIcons(None) self.assertIn(u'new.png', icons[0])
def testRemoveGroup_04(self): files = ['new.png', 'image_01.JPG'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup('Новая группа') collection.addIcons('Новая группа', fullPaths) collection.removeGroup('Новая группа') self.assertEqual(collection.getGroups(), [])
def testAddIcons_07(self): files = ['new.png', 'image_01.JPG'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addIcons(None, fullPaths) icons = sorted(collection.getIcons(None)) self.assertIn('image_01.png', icons[0]) self.assertIn('new.png', icons[1])
def testRenameGroup_02_invalid(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(u'Новая группа') self.assertRaises(ValueError, collection.renameGroup, u'Новая группа', u'') self.assertRaises(ValueError, collection.renameGroup, u'Новая группа', u'Абырвалг/Абырвалг') self.assertRaises(ValueError, collection.renameGroup, u'Новая группа', u'Абырвалг\\Абырвалг')
def testAddIcons_16_invalid(self): files = [u'invalid.png'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] groupname = u'Новая группа' os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(groupname) collection.addIcons(groupname, fullPaths) icons = sorted(collection.getIcons(groupname)) self.assertEqual(len(icons), 0)
def testAddCover_05_root(self): os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) coverpath = os.path.join(self.imagesDir, u'first.jpg') collection.setCover(None, coverpath) self.assertTrue( os.path.exists( os.path.join(self.tempDir1, IconsCollection.COVER_FILE_NAME))) self.assertEqual( self.__getMaxImageSize( os.path.join(self.tempDir1, IconsCollection.COVER_FILE_NAME)), 16)
def testAddIcons_13(self): files = [u'__sample.png'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] groupname = u'Новая группа' os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(groupname) collection.addIcons(groupname, fullPaths) icons = sorted(collection.getIcons(groupname)) self.assertEqual(len(icons), 1) self.assertNotIn(u'__sample.png', icons[0]) self.assertIn(u'sample.png', icons[0])
def testAddIcons_10_not_exists(self): files = [u'new.png', u'image_01.JPG', u'notexists.png'] fullPaths = [os.path.join(self.imagesDir, fname) for fname in files] groupname = u'Новая группа' os.mkdir(self.tempDir1) collection = IconsCollection(self.tempDir1) collection.addGroup(groupname) collection.addIcons(groupname, fullPaths) icons = sorted(collection.getIcons(groupname)) self.assertEqual(len(icons), 2) self.assertIn(u'image_01.png', icons[0]) self.assertIn(u'new.png', icons[1])