Skip to content

Commit

Permalink
Update ubuntu base image and fix tests, add heic/heif test image.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolshevik committed Jan 17, 2021
1 parent fd3dbbd commit 17de864
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: python
dist: focal
python:
- "3.7"
- "3.8"
- "3.9"
install:
- sudo apt-get install -y libblas-dev liblapack-dev libatlas-base-dev gfortran libheif-dev
- sudo apt-get install -y libblas-dev liblapack-dev libatlas-base-dev gfortran libffi-dev automake make libtool autoconf g++ m4 pkg-config
- wget https://github.com/strukturag/libheif/releases/download/v1.10.0/libheif-1.10.0.tar.gz
- tar xvf libheif-1.10.0.tar.gz && pushd libheif-1.10.0 && ./autogen.sh && ./configure --disable-dependency-tracking && make && sudo make install && popd && rm -rf libheif-1.10.0
- pip install --only-binary=numpy,scipy -r requirements.txt
- pip install -r requirements-test.txt
script: pytest tests/test.py -v
4 changes: 2 additions & 2 deletions duplicate_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _add_to_database(file_, hash_, file_size, image_size, capture_time, db):


def _in_database(file, db):
return db.count({"_id": file}) > 0
return db.count_documents({"_id": file}) > 0


def new_image_files(files, db):
Expand Down Expand Up @@ -214,7 +214,7 @@ def clear(db):


def show(db):
total = db.count()
total = db.count_documents()
pprint(list(db.find()))
print("Total: {}".format(total))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ termcolor==1.1.0
Werkzeug==1.0.1
Flask-Cors==3.0.9
pybktree==1.1
git+https://github.com/david-poirier-csn/pyheif.git
pyheif==0.5.1
Binary file modified tests/images/deeply/nested/image/sideways.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/deeply/nested/image/smaller.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/u.heic
Binary file not shown.
26 changes: 13 additions & 13 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_get_image_files():
images = ['tests/images/u.jpg', 'tests/images/file.png', 'tests/images/file.gif', 'tests/images/file.tiff',
images = ['tests/images/u.jpg', 'tests/images/u.heic', 'tests/images/file.png', 'tests/images/file.gif', 'tests/images/file.tiff',
'tests/images/image.txt', 'tests/images/deeply/nested/different.jpg',
'tests/images/deeply/nested/image/sideways.jpg', 'tests/images/deeply/nested/image/smaller.jpg']
other = ['tests/images/not_image.txt', 'tests/images/not_image.jpb', 'README.md']
Expand All @@ -25,7 +25,7 @@ def test_hash_file():
file, hash_, file_size, image_size, capture_time = result

assert file == image_name
assert hash_ == '4b9e705db4450db6695cba149e2b2d65c3a950e13c7e8778e1cbda081e12a7eb'
assert hash_ == '87d35b107818e5d7963a5d2869d4b4b6c3950a873c7ee11ed2790eba2da2b03d'

result = duplicate_finder.hash_file('tests/images/nothing.png')
assert result is None
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_hash_files_parallel():

file, hash_, file_size, image_size, capture_time = results[0]
assert file == 'tests/images/u.jpg'
assert hash_ == '4b9e705db4450db6695cba149e2b2d65c3a950e13c7e8778e1cbda081e12a7eb'
assert hash_ == '87d35b107818e5d7963a5d2869d4b4b6c3950a873c7ee11ed2790eba2da2b03d'


duplicate_finder.NUM_PROCESSES = 1
Expand Down Expand Up @@ -111,33 +111,33 @@ def test_add():

db_result = db.find_one({'_id' : file_name})
assert db_result['_id'] == file_name
assert db_result['hash'] == '4b9e705db4450db6695cba149e2b2d65c3a950e13c7e8778e1cbda081e12a7eb'
assert db.count() > 0
assert db_result['hash'] == '87d35b107818e5d7963a5d2869d4b4b6c3950a873c7ee11ed2790eba2da2b03d'
assert db.count_documents() > 0


def test_remove():
db = mongomock.MongoClient().image_database.images

duplicate_finder.add(['tests'], db)
assert db.count() > 0
assert db.count_documents() > 0
duplicate_finder.remove(['test'], db)
assert db.count() > 0
assert db.count_documents() > 0

duplicate_finder.remove(['tests'], db)
assert db.count() == 0
assert db.count_documents() == 0

duplicate_finder.remove(['tests'], db)
assert db.count() == 0
assert db.count_documents() == 0


def test_clear():
db = mongomock.MongoClient().image_database.images

duplicate_finder.add(['tests'], db)

assert db.count() > 0
assert db.count_documents() > 0
duplicate_finder.clear(db)
assert db.count() == 0
assert db.count_documents() == 0


def test_find():
Expand All @@ -157,7 +157,7 @@ def test_find():
def test_dedup():
db = mongomock.MongoClient().image_database.images
duplicate_finder.add(['tests'], db)
assert db.count() == 8
assert db.count_documents() == 9

dups = duplicate_finder.find(db, match_time=False)
assert len(dups) == 2
Expand All @@ -174,7 +174,7 @@ def test_dedup():
assert not os.path.exists(item['file_name'])
assert os.path.exists(os.path.join('Trash', os.path.basename(item['file_name'])))

assert db.count() == 4
assert db.count_documents() == 4

# Move files back
for dup in dups:
Expand Down

0 comments on commit 17de864

Please sign in to comment.