Skip to content

Commit

Permalink
Testing feature detector
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef committed Oct 3, 2015
1 parent 7519035 commit 564e2f1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/detectors/test_feature_detector.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added tests/fixtures/images/white-block.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 564e2f1

Please sign in to comment.