def test_tutils_local_pythonpath(self): def count_endswith(alist, suffix): return len([x for x in alist if x.endswith(suffix)]) self.assertEqual(0, count_endswith(sys.path, 'TOTO')) tutils.local_pythonpath('TOTO') self.assertEqual(1, count_endswith(sys.path, 'TOTO')) tutils.local_pythonpath('TOTO') self.assertEqual(1, count_endswith(sys.path, 'TOTO')) sys.path.remove(tutils.get_local_path('TOTO')) self.assertEqual(0, count_endswith(sys.path, 'TOTO'))
#! /usr/bin/env python import os import sys import unittest from tutils import local_pythonpath, get_local_path # Setup project-local PYTHONPATH local_pythonpath('..', '..', 'src') import utils import multihash class MultihashTest(unittest.TestCase): 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()) def test_multihash_nonexistent(self): mhs = multihash.multihash_serial_exec() with self.assertRaises(IOError): mhs.hash_file('/tmp/nonexistent')