Skip to content

Commit

Permalink
added link to docs in readme, added some tests to test for exceptions…
Browse files Browse the repository at this point in the history
…. Also formatted with black.
  • Loading branch information
akamhy committed Oct 1, 2021
1 parent e1aca6b commit 1b4b81a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<a href="https://github.com/akamhy/dhashpy/actions?query=workflow%3AWindows"><img alt="Build Status" src="https://github.com/akamhy/dhashpy/workflows/Windows/badge.svg"></a>
<a href="https://codecov.io/gh/akamhy/dhashpy"><img alt="codecov" src="https://codecov.io/gh/akamhy/dhashpy/branch/main/graph/badge.svg?token=HVwlPMnsPA"></a>
<a href="https://dhashpy.readthedocs.io/en/latest/"><img alt="docs" src="https://readthedocs.org/projects/dhashpy/badge/?version=latest&style=flat"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>


Expand All @@ -35,24 +36,24 @@ pip install git+https://github.com/akamhy/dhashpy.git
>>> dhash_file = DHash(file)
>>> dhash_file
DHash(hash=0b0110010000000011101010111100110111001101100011111000111100001110, hash_hex=0x6403abcdcd8f8f0e, path=/home/akamhy/Pictures/map_of_maths.png)
>>>
>>>
>>> dhash_file.hash # A 64-bit hash, notice the prefix "0b" indicating it's binary. Total string length = 64 + 2 = 66
'0b0110010000000011101010111100110111001101100011111000111100001110'
>>>
>>>
>>> len(dhash_file)
66
>>> dhash_file.bits_in_hash
64
>>>
>>>
>>> dhash_file.hash_hex
'0x6403abcdcd8f8f0e'
>>>
>>>
>>> dhash_file - "0x6403abcdcd8f8f0e" # You can save the hex value in database to compare later
0
>>>
>>> dhash_file == "0x6403abcdcd8f8f0e" # Both the hex and file have same binary hash.
True
>>>
>>>
>>> dhash_file - "0b0110010000000011101010111100110111001101100011111000111100001110" # You may also save the binary hash value for matching but hex value are smaller
0
>>>
Expand All @@ -66,10 +67,11 @@ dhash_file
9
>>> dhash_file.image
<PIL.Image.Image image mode=L size=9x8 at 0x7F9D324C0580>
>>>

>>>
```

> Docs : <https://dhashpy.readthedocs.io/en/latest/>

### License
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/akamhy/dhashpy/blob/main/LICENSE)
Expand Down
23 changes: 14 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import os
import sys

sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath("../.."))
import dhashpy


# -- Project information -----------------------------------------------------

project = 'dhashpy'
copyright = '2021, Akash Mahanty'
author = 'Akash Mahanty'
html_logo = '../images/dhashpylogo-min.png'
project = "dhashpy"
copyright = "2021, Akash Mahanty"
author = "Akash Mahanty"
html_logo = "../images/dhashpylogo-min.png"
# The short X.Y version.
version = dhashpy.__version__
# The full version, including alpha/beta/rc tags.
Expand All @@ -34,10 +34,15 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon', 'sphinx.ext.viewcode']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -51,7 +56,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'bizstyle'
html_theme = "bizstyle"

# html_theme_options = {
# "show_powered_by": False,
Expand All @@ -65,4 +70,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
11 changes: 10 additions & 1 deletion tests/test_dhashpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_all():

# Prevent end user from passing None for difference
with pytest.raises(TypeError):
assert (dhash_big_baikal - None)
assert dhash_big_baikal - None

# clearly both the Images are same but of different resolution
with pytest.raises(AssertionError):
Expand All @@ -72,3 +72,12 @@ def test_all():
with pytest.raises(FileNotFoundError):
thisfiledoesnotexists = os.path.join(this_dir, "thisfiledoesnotexists.jpg")
DHash(thisfiledoesnotexists)

with pytest.raises(ValueError):
DHash.hex2bin("64", 10)

with pytest.raises(ValueError):
DHash.hamming_distance("abcd", "abc")

with pytest.raises(ValueError):
DHash.bin2hex("10101")

0 comments on commit 1b4b81a

Please sign in to comment.