def test_update_encode_error(self): test_fuzzy_hash_obj = new() with self.assertRaises(FuzzyHashError) as context: test_fuzzy_hash_obj.update('тестовая строка для fazzy hash', 'ascii') self.assertTrue('Data encoding error. The "encoding" value cannot be' in str(context.exception))
def test_new_raise(self): with mock.patch('pyssdeep.ssdeep_pep_452.fuzzy_new', fuzzy_new_mock_raise): with self.assertRaises(FuzzyHashError) as context: test_fuzzy_hash_obj = new() self.assertTrue('Unable to create hash context. Error code: -1' in str( context.exception))
def test_digest_type_error(self): test_fuzzy_hash_obj = new() with self.assertRaises(TypeError) as context: test_result = test_fuzzy_hash_obj.digest(None) self.assertTrue( 'Flag value must be of int type not "<class \'NoneType\'>".' in str(context.exception))
def test_update_hash_context_error(self): test_fuzzy_hash_obj = new() test_fuzzy_hash_obj._state = None with self.assertRaises(FuzzyHashError) as context: test_fuzzy_hash_obj.update(b'this test fuzzy hash string') self.assertTrue('Unable to update hash object. Hash context error.' in str(context.exception))
def test_update_type_error(self): test_fuzzy_hash_obj = new() with self.assertRaises(TypeError) as context: test_fuzzy_hash_obj.update(None) self.assertTrue( 'Invalid data type. The data type cannot be "<class \'NoneType\'>".' in str(context.exception))
def test_update_raise(self): test_fuzzy_hash_obj = new() with mock.patch('pyssdeep.ssdeep_pep_452.fuzzy_update', fuzzy_update_mock_raise): with self.assertRaises(FuzzyHashError) as context: test_fuzzy_hash_obj.update(b'this test fuzzy hash string') self.assertTrue('Unable to update hash object. Error code: -1' in str( context.exception))
def test_digest_size_raise(self): test_fuzzy_hash_obj = new() with mock.patch('pyssdeep.ssdeep_pep_452.FuzzyHash.digest', digest_mock_raise): with self.assertRaises(FuzzyHashError) as context: test_result = test_fuzzy_hash_obj.digest_size self.assertTrue('Unable to return the digest size value.' in str( context.exception))
def test_copy_raise(self): test_fuzzy_hash_obj = new() with mock.patch('pyssdeep.ssdeep_pep_452.fuzzy_clone', fuzzy_clone_mock_raise): with self.assertRaises(FuzzyHashError) as context: test_fuzzy_hash_obj_copy = test_fuzzy_hash_obj.copy() self.assertTrue('Unable to clone hash object. Error code: -1' in str( context.exception))
def test_digest_raise(self): test_fuzzy_hash_obj = new() with mock.patch('pyssdeep.ssdeep_pep_452.fuzzy_digest', fuzzy_digest_mock_raise): with self.assertRaises(FuzzyHashError) as context: test_result = test_fuzzy_hash_obj.digest() self.assertTrue( 'Unable to compute digest of hash object. Error code: -1' in str( context.exception))
def test_copy(self): test_fuzzy_hash_obj = new() test_fuzzy_hash_obj._state.contents.bh[0].digest = b'test_fuzzy_digest' test_fuzzy_hash_obj_copy = test_fuzzy_hash_obj.copy() test_fuzzy_hash_obj_copy._state.contents.bh[ 0].digest = b'test_fuzzy_copy_digest' self.assertEqual(test_fuzzy_hash_obj_copy._state.contents.bh[0].digest, b'test_fuzzy_copy_digest') self.assertEqual(test_fuzzy_hash_obj._state.contents.bh[0].digest, b'test_fuzzy_digest')
def test_new(self): test_fuzzy_hash_obj = new() self.assertEqual(test_fuzzy_hash_obj._state.contents.bhstart, 0) self.assertEqual(test_fuzzy_hash_obj._state.contents.bhend, 1) self.assertEqual(test_fuzzy_hash_obj._state.contents.bhendlimit, 30) self.assertEqual(test_fuzzy_hash_obj._state.contents.total_size, 0) self.assertEqual(test_fuzzy_hash_obj._state.contents.reduce_border, 192) self.assertEqual(test_fuzzy_hash_obj._state.contents.flags, 0) self.assertEqual(test_fuzzy_hash_obj._state.contents.rollmask, 0)
def test_digest_size(self): test_fuzzy_hash_obj = new() test_result = test_fuzzy_hash_obj.digest_size self.assertEqual(test_result, 1)
def test_update(self): test_fuzzy_hash_obj = new() test_fuzzy_hash_obj.update(b'this test fuzzy hash string') self.assertEqual(test_fuzzy_hash_obj._state.contents.total_size, 27)
def test_digest(self): test_fuzzy_hash_obj = new() test_result = test_fuzzy_hash_obj.digest() self.assertEqual(test_result, '3::')
def test_name(self): test_fuzzy_hash_obj = new() test_result = test_fuzzy_hash_obj.name self.assertEqual(test_result, 'ssdeep')
def test_block_size(self): test_fuzzy_hash_obj = new() test_result = test_fuzzy_hash_obj.block_size self.assertEqual(test_result, 3)
def test_digest_hash_context_error(self): test_fuzzy_hash_obj = new() test_fuzzy_hash_obj._state = None with self.assertRaises(FuzzyHashError) as context: test_result = test_fuzzy_hash_obj.digest() self.assertTrue('Unable to update hash object. Hash context error.')