Skip to content

Commit

Permalink
Setup project for travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bunchesofdonald committed Jul 25, 2015
1 parent 8030e7f commit 2aacf60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: python
python:
- "2.7"
- "3.4"
install: "pip install -r requirements.txt"
script: py.test
14 changes: 6 additions & 8 deletions photohash/tests/test_photohash.py
@@ -1,14 +1,11 @@
from os.path import abspath, dirname, join
import sys
import unittest

TESTS_ROOT = join(dirname(abspath(__file__)))
ASSETS_ROOT = join(TESTS_ROOT, 'assets')
MODULE_ROOT = join(TESTS_ROOT, '../')

sys.path.append(MODULE_ROOT)

from photohash import average_hash, distance, is_look_alike, _hamming_distance
from photohash.photohash import average_hash, distance, is_look_alike, _hamming_distance


class PhotoHashTestCase(unittest.TestCase):
Expand All @@ -34,15 +31,18 @@ def setUp(self):
]

def test_average_hash(self):
"""average_hash should output the expected hash for each test image"""
for photo in self.photos:
self.assertEqual(photo['average_hash'], average_hash(photo['path']))

def test_hamming_distance(self):
"""_hamming_distance should know the distance between two strings"""
self.assertEqual(_hamming_distance('roses', 'toned'), 3)
self.assertEqual(_hamming_distance('are', 'are'), 0)
self.assertEqual(_hamming_distance('read', 'daer'), 4)

def test_distance(self):
"""distance should know the distance between the average_hash of two test images"""
for i in range(len(self.photos)):
for j in range(i, len(self.photos)):
hamming_distance = _hamming_distance(
Expand All @@ -56,6 +56,8 @@ def test_distance(self):
)

def test_is_look_alike(self):
"""is_look_alike should know if two images look similar"""

# Test that the same image will return True.
self.assertTrue(is_look_alike(self.photos[2]['path'], self.photos[2]['path']))

Expand All @@ -72,7 +74,3 @@ def test_is_look_alike(self):

# Test that a scaled verision of the same image is within default tolerance.
self.assertTrue(is_look_alike(self.photos[1]['path'], self.photos[3]['path']))


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions requirements.txt
@@ -1 +1,2 @@
Pillow>=2.1.0
pytest==2.7.2

0 comments on commit 2aacf60

Please sign in to comment.