2014-05-07 22:42:30 +00:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
2020-07-29 20:52:44 +00:00
|
|
|
from hydrus.core import HydrusConstants as HC
|
|
|
|
|
|
|
|
from hydrus.client import ClientConstants as CC
|
|
|
|
from hydrus.client import ClientImageHandling
|
|
|
|
|
2014-05-07 22:42:30 +00:00
|
|
|
class TestImageHandling( unittest.TestCase ):
|
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
def test_perceptual_hash( self ):
|
2014-05-07 22:42:30 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
perceptual_hashes = ClientImageHandling.GenerateShapePerceptualHashes( os.path.join( HC.STATIC_DIR, 'hydrus.png' ), HC.IMAGE_PNG )
|
2014-05-07 22:42:30 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
self.assertEqual( perceptual_hashes, set( [ b'\xb4M\xc7\xb2M\xcb8\x1c' ] ) )
|
2014-05-07 22:42:30 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
perceptual_hashes = ClientImageHandling.DiscardBlankPerceptualHashes( { CC.BLANK_PERCEPTUAL_HASH } )
|
2019-05-08 21:06:42 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
self.assertEqual( perceptual_hashes, set() )
|
2019-05-08 21:06:42 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
perceptual_hashes = ClientImageHandling.DiscardBlankPerceptualHashes( { b'\xb4M\xc7\xb2M\xcb8\x1c', CC.BLANK_PERCEPTUAL_HASH } )
|
2019-05-08 21:06:42 +00:00
|
|
|
|
2021-12-15 22:16:22 +00:00
|
|
|
self.assertEqual( perceptual_hashes, set( [ b'\xb4M\xc7\xb2M\xcb8\x1c' ] ) )
|
2019-05-08 21:06:42 +00:00
|
|
|
|