def test_image_count(self): """Check message for images count""" self.setup_conf(CONFIG_COUNT, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(127, 264, "gif", "image001.gif"), 2: new_image(127, 264, "png", "image002.png")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '2.0')
def test_image_count(self): """Check message for images count""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_COUNT, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(127, 264, "gif", "image001.gif"), 2: new_image(127, 264, "png", "image002.png")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '2.0')
def test_image_count(self): """Check message for images count""" self.setup_conf( CONFIG_COUNT, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({ 1: new_image(127, 264, "gif", "image001.gif"), 2: new_image(127, 264, "png", "image002.png") }) result = self.check_pad(msg.as_string()) self.assertEqual(result, '2.0')
def test_image_count(self): """Check message for images count""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_COUNT, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({ 1: new_image(127, 264, "gif", "image001.gif"), 2: new_image(127, 264, "png", "image002.png") }) result = self.check_pad(msg.as_string()) self.assertEqual(result, '2.0')
def test_extract_metadata(self): patch("pad.plugins.image_info.ImageInfoPlugin._add_name").start() patch("pad.plugins.image_info.ImageInfoPlugin._update_counts").start() patch("pad.plugins.image_info.ImageInfoPlugin._save_stats").start() add_name_calls = [] update_counts_calls = [] save_stats_calls = [] images = {} for x in range(5): images.update({ x: new_image(1, 1, "jpg", "%s.jpg" % x) }) add_name_calls.append(call(self.mock_msg, "%s.jpg" % x)) update_counts_calls.append(call(self.mock_msg, "jpg", by=1)) save_stats_calls.append(call(self.mock_msg, new_image_string((1, 1), "RGB"), "jpg")) self.mock_msg.msg = new_email(images) for part in self.mock_msg.msg.walk(): payload = part.get_payload(decode=True) self.plugin.extract_metadata(self.mock_msg, payload, None, part) self.plugin._add_name.assert_has_calls(add_name_calls) self.plugin._update_counts.assert_has_calls(update_counts_calls) self.plugin._save_stats.assert_has_calls(save_stats_calls)
def test_image_name_fail(self): """Fail for image name""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({1: new_image(1, 1, "gif", "image0011.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_image_text_ratio(self): """Check message for ration between text and images""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_IMG_RATIO, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_range(self): """Check message for image with size in range""" self.setup_conf( CONFIG_RANGE, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(320, 220, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_pixel_coverage(self): """Check message for image pixel coverage""" self.setup_conf( CONFIG_COVERAGE, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(200, 200, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_name(self): """Check message for image name""" self.setup_conf( CONFIG_NAMED, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(1, 1, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_many_rules_match(self): """Check message for image name, size and count""" self.setup_conf( CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COUNT, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '3.0')
def test_image_text_ratio(self): """Check message for ration between text and images""" self.setup_conf(CONFIG_IMG_RATIO, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_size_fail(self): """Fail for image size""" self.setup_conf(CONFIG_SIZED, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(127, 222, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_image_range(self): """Check message for image with size in range""" self.setup_conf(CONFIG_RANGE, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(320, 220, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_range(self): """Check message for image with size in range""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_RANGE, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({1: new_image(320, 220, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_pixel_coverage(self): """Check message for image pixel coverage""" self.setup_conf(CONFIG_COVERAGE, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(200, 200, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_size_fail(self): """Fail for image size""" self.setup_conf( CONFIG_SIZED, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(127, 222, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_image_name(self): """Check message for image name""" self.setup_conf(CONFIG_NAMED, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(1, 1, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_text_ratio(self): """Check message for ration between text and images""" self.setup_conf( CONFIG_IMG_RATIO, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_many_rules_match(self): """Check message for image name, size and count""" self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COUNT, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '3.0')
def test_many_rules_match(self): """Check message for image name, size and count""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COUNT, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '3.0')
def test_image_name_fail(self): """Fail for image name""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(1, 1, "gif", "image0011.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_image_text_ratio(self): """Check message for ration between text and images""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_IMG_RATIO, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_image_range(self): """Check message for image with size in range""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_RANGE, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(320, 220, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '1.0')
def test_no_matches_of_many(self): """Check message for image name, size and coverage and no matches""" self.setup_conf( CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COVERAGE, pre_config="loadplugin oa.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email({1: new_image(100, 100, "gif", "image002.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_no_matches_of_many(self): """Check message for image name, size and coverage and no matches""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COVERAGE, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email({1: new_image(100, 100, "gif", "image002.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_many_rules_match(self): """Check message for image name, size and count""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COUNT, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(127, 264, "gif", "image001.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '3.0')
def test_no_matches_of_many(self): """Check message for image name, size and coverage and no matches""" self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COVERAGE, pre_config="loadplugin pad.plugins.image_info.ImageInfoPlugin\n" "report _SCORE_") msg = new_email( {1: new_image(100, 100, "gif", "image002.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')
def test_no_matches_of_many(self): """Check message for image name, size and coverage and no matches""" cwd = os.path.join(os.getcwd(), "pad", "plugins", "image_info.py") self.setup_conf(CONFIG_NAMED + "\n" + CONFIG_SIZED + "\n" + CONFIG_COVERAGE, pre_config="loadplugin ImageInfoPlugin {0}\n" "report _SCORE_".format(cwd)) msg = new_email( {1: new_image(100, 100, "gif", "image002.gif")}) result = self.check_pad(msg.as_string()) self.assertEqual(result, '0.0')