From 564e2f191f8d91f93c7e0a22671f3decaec60a87 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sat, 3 Oct 2015 19:36:31 -0300 Subject: [PATCH] Testing feature detector --- tests/detectors/test_feature_detector.py | 42 +++++++++++++++++++++++ tests/fixtures/images/white-block.png | Bin 0 -> 109 bytes 2 files changed, 42 insertions(+) create mode 100644 tests/detectors/test_feature_detector.py create mode 100644 tests/fixtures/images/white-block.png diff --git a/tests/detectors/test_feature_detector.py b/tests/detectors/test_feature_detector.py new file mode 100644 index 000000000..985cef55a --- /dev/null +++ b/tests/detectors/test_feature_detector.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# thumbor imaging service +# https://github.com/thumbor/thumbor/wiki + +# Licensed under the MIT license: +# http://www.opensource.org/licenses/mit-license +# Copyright (c) 2011 globo.com timehome@corp.globo.com + +from os.path import abspath +from unittest import TestCase +import mock + +from preggy import expect + +from thumbor.detectors.feature_detector import Detector as FeatureDetector +from thumbor.engines.pil import Engine as PilEngine + + +class FeatureDetectorTestCase(TestCase): + def setUp(self): + self.context = mock.Mock(request=mock.Mock(focal_points=[])) + self.engine = PilEngine(self.context) + self.context.modules.engine = self.engine + + def test_should_detect_multiple_points(self): + with open(abspath('./tests/fixtures/images/no_face.jpg')) as f: + self.engine.load(f.read(), None) + + FeatureDetector(self.context, 0, None).detect(lambda: None) + detection_result = self.context.request.focal_points + expect(detection_result).to_be_greater_than(1) + expect(detection_result[0].origin).to_equal('alignment') + + def test_should_not_detect_points(self): + with open(abspath('./tests/fixtures/images/white-block.png')) as f: + self.engine.load(f.read(), None) + + FeatureDetector(self.context, 0, []).detect(lambda: None) + detection_result = self.context.request.focal_points + expect(detection_result).to_length(0) diff --git a/tests/fixtures/images/white-block.png b/tests/fixtures/images/white-block.png new file mode 100644 index 0000000000000000000000000000000000000000..b9d310c9103991a26764dacab462ca493ced76e7 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X_&r@5Ln>}1{rLai-l2h!f%PBLKizYk?|@Pap00i_>zopr E0IK63`v3p{ literal 0 HcmV?d00001