Exemplo n.º 1
0
    def test_multihash_nonexistent(self):
        mhs = multihash.multihash_serial_exec()
        with self.assertRaises(IOError):
            mhs.hash_file('/tmp/nonexistent')

        mhp = multihash.multihash_hashlib()
        with self.assertRaises(IOError):
            mhp.hash_file('/tmp/nonexistent')
Exemplo n.º 2
0
 def test_multihash_files(self):
     files = [os.devnull, 'random_1M.bin', 'random_5M.bin']
     for fn in files:
         local_path = get_local_path('..', 'data', fn)
         mhs = multihash.multihash_serial_exec()
         mhp = multihash.multihash_hashlib()
         mhs.hash_file(local_path)
         mhp.hash_file(local_path)
         self.assertEquals(mhs.hexdigests(), mhp.hexdigests())
Exemplo n.º 3
0
 def test_multihash_gethash_serial_nonexistent_hash(self):
     mh = multihash.multihash_serial_exec()
     with utils.stringio() as output:
         with utils.redirect('stdout', output):
             nonexistent_hash = 'nonexistent_hash_algo'
             self.assertFalse(mh.get_hash(os.devnull, nonexistent_hash))
             out = ("%s: '%s%s': Cannot execute, please check it is properly"
                    " installed, and available through your PATH environment "
                    "variable.\n%s: [Errno 2] No such file or directory\n" %
                    (sys.argv[0], nonexistent_hash, 'sum', sys.argv[0]))
             out = out.split("\n")[0]
             self.assertEqual(output.getvalue().split("\n")[0], out)
Exemplo n.º 4
0
 def test_multihash_string_serial(self):
     mh = multihash.multihash_serial_exec()
     with open('test.txt', 'wb') as test_file:
         test_file.write('toto')
         test_file.flush()
         mh.hash_file('test.txt')
         self.assertEquals(mh.hexdigests()['md5'], 'f71dbe52628a3f83a77ab494817525c6')
         test_file.write('titi')
         test_file.flush()
         mh.hash_file('test.txt')
         self.assertEquals(mh.hexdigests()['md5'], '92fdff5b8595ef3f9ac0de664ce21532')
     os.remove('test.txt')
Exemplo n.º 5
0
 def test_multihash_gethash_serial(self):
     mh = multihash.multihash_serial_exec()
     self.assertEquals(mh.get_hash(os.devnull, 'md5'), 'd41d8cd98f00b204e9800998ecf8427e')
     self.assertIsNone(mh.get_hash('/tmp/nonexistent', 'md5'))