def test_addImage(self): # create a troll box in a temp dir and add an image from the "0" test # data set file_dir = os.path.dirname(os.path.realpath(__file__)) sample_path = os.path.join(file_dir, "data", "0", "images", "book.jpg") temp_dir = tempfile.mkdtemp() try: model = ImageModel(troll_dir=temp_dir) model.addImage("http://foo.bar", ["tng"], sample_path) index = model.index(0, 0) self.assertEqual(model.data(index, Qt.DisplayRole), "http://foo.bar") finally: subprocess.call(["rm", "-rf", temp_dir])
def test_setData(self): # create a troll box in a temp dir, add an image from the "0" test # data set, and modify it via setData file_dir = os.path.dirname(os.path.realpath(__file__)) sample_path = os.path.join(file_dir, "data", "0", "images", "book.jpg") temp_dir = tempfile.mkdtemp() try: model = ImageModel(troll_dir=temp_dir) model.addImage("http://foo.bar", ["tng"], sample_path) self.assertEqual(model.data(model.index(0, 0), Qt.DisplayRole), "http://foo.bar") model.setData(model.index(0, 0), "http://bar.bar", Qt.DisplayRole) self.assertEqual(model.data(model.index(0, 0), Qt.DisplayRole), "http://bar.bar") sample_path = os.path.join(file_dir, "data", "0", "images", "koop.jpg") model.setData(model.index(0, 0), sample_path, Qt.DecorationRole) # no good way to check icon currently finally: subprocess.call(["rm", "-rf", temp_dir])