def test_path_replace_no(self): ss = ''' #Markdown with no image ''' img_det = ImageManager(ss) self.assertEqual(ss, img_det.replace_path_imgs('/main'))
def test_download_img(self): import os url = 'http://www.rokers.io/img/logo.png' imgs = [['logo rokers', url], ['image', 'img.png']] text = self.create_random_text_from_img_list(imgs) img_det = ImageManager(text) img_det.download('./imgs/') self.assertTrue(os.path.isdir("./imgs/")) self.assertTrue(os.path.exists("./imgs/logo.png"))
def test_path_replace_multiple(self): for i in range(1, 5): text_list = self.create_random_text_list(i) imgs_list = self.create_random_imgs(i) path = '/complex_path/test/' imgs_list_expected = [[img[0], path + img[1].split('/')[-1]] for img in imgs_list] text = self.merge_text_and_img_lists(text_list, imgs_list) text_expected = self.merge_text_and_img_lists( text_list, imgs_list_expected) img_det = ImageManager(text) self.assertEqual(text_expected, img_det.replace_path_imgs(path))
def test_path_replace_any(self): import os.path for i in range(1, 20): text, imgs = self.create_random_text_with_img(i) img_det = ImageManager(text) path = '/img/test/' img_repr = [path + img.split('/')[-1] for img in img_det.imgs]
def test_general(self): for i in range(1, 5): text, imgs = self.create_random_text_with_img(i) img_det = ImageManager(text) self.assertTrue(img_det.imgs) self.assertEqual(len(img_det.imgs), i) for img in imgs: self.assertTrue(img[1] in img_det.imgs)
def test_no_image(self): ss = ''' #Markdown with no image ''' img_det = ImageManager(ss) self.assertFalse(img_det.imgs)
def test_one_image(self): ss = ''' #Markdown with image ![lkjsd](img.png) ''' img_det = ImageManager(ss) self.assertTrue(img_det.imgs) self.assertTrue('img.png' in img_det.imgs) self.assertEqual(len(img_det.imgs), 1)
def test_path_replace_one(self): ss = ''' #Markdown with image ![lkjsd](img.png) ''' ss_expected_1 = ''' #Markdown with image ![lkjsd](/main/img.png) ''' ss_expected_2 = ''' #Markdown with image ![lkjsd](main/img.png) ''' img_det = ImageManager(ss) self.assertEqual(ss_expected_1, img_det.replace_path_imgs('/main')) self.assertEqual(ss_expected_2, img_det.replace_path_imgs('main'))