def test_image_detection(self):
     with TempDir() as tmpdir:
         tmpfn = os.path.join(tmpdir.name, 'input')
         out = open(tmpfn, "w")
         out.write("\x89PNG\r\n\x1a\n" + (" " * 1024))
         out.close()
         is_image = get_sha1sums(tmpfn, os.path.getsize(tmpfn), 1024)[3]
         self.assertTrue(is_image)
 def test_2049_bytes_file(self):
     with TempDir() as tmpdir:
         tmpfn = os.path.join(tmpdir.name, 'input')
         write_binary(2049, tmpfn)
         hashs = get_sha1sums(tmpfn, os.path.getsize(tmpfn), 1024)
         self.assertEqual(hashs, ('5b00669c480d5cffbdfa8bdba99561160f2d1b77', '170751534f1a95fd80a7a25787ecad2b60368e0a',
                                  {2048L: 'f10ccfde60c17db26e7d85d35665c7661dbbeb2c'}, False))
         self.assertEqual(get_partial_sha1(tmpfn, 0, 1024), '5b00669c480d5cffbdfa8bdba99561160f2d1b77')
         self.assertEqual(get_partial_sha1(tmpfn, 0, 2048), 'f10ccfde60c17db26e7d85d35665c7661dbbeb2c')
         self.assertEqual(get_partial_sha1(tmpfn, 0, 2049), '170751534f1a95fd80a7a25787ecad2b60368e0a')
 def test_file_of_buffer_size(self):
     with TempDir() as tmpdir:
         tmpfn = os.path.join(tmpdir.name, 'input')
         write_big_binary(4, tmpfn)
         hashs = get_sha1sums(tmpfn, os.path.getsize(tmpfn), 1024)
         self.assertEqual(hashs, ('5b00669c480d5cffbdfa8bdba99561160f2d1b77', 'd697024ed93ff625330d050391ade99cd5cbddad',
                                  {2048L: 'f10ccfde60c17db26e7d85d35665c7661dbbeb2c',
                                   4096L: 'e9dded8c84614e894501965af60c2525794a8c7d',
                                   8192L: 'ecca46e1a1d0a6012713b09a870d84f695b6d9b0',
                                   16384L: '80cb9c430d80c3084649f65e0ca25dabbffb1b62',
                                   32768L: '1edf14b9f91477ed8071b1f66e2d4c2849501b91',
                                   65536L: 'f04977267a391b2c8f7ad8e070f149bc19b0fc25',
                                   131072L: 'f826028ed472b1fadeddbf54fc1912a095d28795',
                                   262144L: '37ef77696fc255bf53b4cdd014b223676f2dc8bb',
                                   524288L: '6c10df9ee9fa4b1c8495b19becb7f8ae8a07ad96',
                                   1048576L: 'ecfc8e86fdd83811f9cc9bf500993b63069923be',
                                   2097152L: '3394ba403303c0784f836bdb1ee13a4bfd14e6de'}, False))
 def get_or_insert_content(self, fullpath, size):
     first, full, other, is_image = get_sha1sums(fullpath, size, MIN_LENGTH)
     other_hashs = " ".join(["%d:%s" % x for x in other.items()])
     obj = Content(size, full, first, other_hashs, is_image)
     return self.db.get_or_insert_content(obj)
 def test_1025_bytes_file(self):
     with TempDir() as tmpdir:
         tmpfn = os.path.join(tmpdir.name, 'input')
         write_binary(1025, tmpfn)
         hashs = get_sha1sums(tmpfn, os.path.getsize(tmpfn), 1024)
         self.assertEqual(hashs, ('5b00669c480d5cffbdfa8bdba99561160f2d1b77', '409c9978384c2832af4a98bafe453dfdaa8e8054', {}, False))
 def test_1024_file(self):
     with TempDir() as tmpdir:
         tmpfn = os.path.join(tmpdir.name, 'input')
         write_binary(1024, tmpfn)
         hashs = get_sha1sums(tmpfn, os.path.getsize(tmpfn), 1024)
         self.assertEqual(hashs, ('5b00669c480d5cffbdfa8bdba99561160f2d1b77', '5b00669c480d5cffbdfa8bdba99561160f2d1b77', {}, False))