def __init__(self, parent): super().__init__("") self.layout = QtWidgets.QVBoxLayout() self.layout.setSpacing(6) self.parent = parent # Kills off any borders self.setStyleSheet('''QGroupBox{background-color:none;border:1px;}''') self.setFlat(True) self.item = None self.pixmap_cache = LRUCache(40) self.cover_art_label = QtWidgets.QLabel('') self.cover_art_label.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter) self.cover_art = CoverArtThumbnail(False, True, self.pixmap_cache, parent) self.cover_art.image_dropped.connect(self.fetch_remote_image) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.orig_cover_art_label = QtWidgets.QLabel('') self.orig_cover_art = CoverArtThumbnail(False, False, self.pixmap_cache, parent) self.orig_cover_art_label.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter) self.show_details_button = QtWidgets.QPushButton(_('Show more details'), self) self.layout.addWidget(self.cover_art_label) self.layout.addWidget(self.cover_art) self.layout.addWidget(self.orig_cover_art_label) self.layout.addWidget(self.orig_cover_art) self.layout.addWidget(self.show_details_button) self.layout.addSpacerItem(spacerItem) self.setLayout(self.layout) self.orig_cover_art.setHidden(True) self.show_details_button.setHidden(True) self.show_details_button.clicked.connect(self.show_cover_art_info)
def test_max_size(self): lrucache = LRUCache(3) lrucache['test1'] = 1 lrucache['test2'] = 2 lrucache['test3'] = 3 lrucache['test4'] = 4 self.assertNotIn('test1', lrucache)
def test_lru(self): lrucache = LRUCache(3) lrucache['test1'] = 1 lrucache['test2'] = 2 lrucache['test3'] = 3 self.assertEqual(len(lrucache._ordered_keys), 3) self.assertEqual('test3', lrucache._ordered_keys[0]) self.assertEqual('test2', lrucache._ordered_keys[1]) self.assertEqual('test1', lrucache._ordered_keys[2]) self.assertEqual(2, lrucache['test2']) self.assertEqual('test2', lrucache._ordered_keys[0]) self.assertEqual('test3', lrucache._ordered_keys[1]) self.assertEqual('test1', lrucache._ordered_keys[2]) lrucache['test1'] = 4 self.assertEqual('test1', lrucache._ordered_keys[0]) self.assertEqual('test2', lrucache._ordered_keys[1]) self.assertEqual('test3', lrucache._ordered_keys[2])
def test_del_keyerror(self): lrucache = LRUCache(3) with self.assertRaises(KeyError): del lrucache['notakey']
def test_get_keyerror(self): lrucache = LRUCache(3) with self.assertRaises(KeyError): value = lrucache['notakey']
def test_dict_like_init(self): lrucache = LRUCache(3, [('test1', 1), ('test2', 2)]) self.assertEqual(lrucache['test1'], 1) self.assertEqual(lrucache['test2'], 2)
def test_simple_del(self): lrucache = LRUCache(3) lrucache['test'] = 1 del lrucache['test'] self.assertNotIn('test', lrucache) self.assertNotIn('test', lrucache._ordered_keys)
def test_simple_getset(self): lrucache = LRUCache(3) lrucache['test'] = 1 self.assertEqual(lrucache['test'], 1) self.assertIn('test', lrucache._ordered_keys)