60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# Unit tests for pysss_murmur
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# Copyright (C) Sumit Bose <sbose@redhat.com> 2012
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# This program is free software; you can redistribute it and/or modify
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# it under the terms of the GNU General Public License as published by
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# the Free Software Foundation; either version 3 of the License, or
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# (at your option) any later version.
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# This program is distributed in the hope that it will be useful,
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# but WITHOUT ANY WARRANTY; without even the implied warranty of
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# GNU General Public License for more details.
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# You should have received a copy of the GNU General Public License
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose# along with this program. If not, see <http://www.gnu.org/licenses/>.
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas SlebodnikMODPATH = tempfile.mkdtemp(prefix="tp_pysss_murmur_", dir=TEST_DIR)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose " Make sure we load the in-tree module "
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose " Restore the system path "
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose " Import the module and assert it comes from tree "
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas Slebodnik dest_module_path = MODPATH + "/pysss_murmur.so"
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas Slebodnik src_module_path = BUILD_DIR + "/.libs/_py3sss_murmur.so"
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas Slebodnik src_module_path = BUILD_DIR + "/.libs/_py2sss_murmur.so"
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas Slebodnik src_module_path = os.path.abspath(src_module_path)
9e1de5c83371d91e200254cceef70852f5f94fd2Lukas Slebodnik os.symlink(src_module_path, dest_module_path)
38cec21168b3b80c312e9efcfea4eba22a9648c8Fabiano Fidêncio print("Could not load the pysss_murmur module. "
38cec21168b3b80c312e9efcfea4eba22a9648c8Fabiano Fidêncio "Please check if it is compiled", file=sys.stderr)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertEqual(pysss_murmur.__file__, MODPATH + "/pysss_murmur.so")
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, 1, 2, 3)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test", 2)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test")
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, "t", -1, seed)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik # length is off by one
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test", 5,
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test",
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik sid_str = "S-1-5-21-2153326666-2176343378-3404031434"
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik hash_val = pysss_murmur.murmurhash3(sid_str, 0, seed)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik hash_val = pysss_murmur.murmurhash3(sid_str, len(sid_str), seed)
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik val_bin = pysss_murmur.murmurhash3(input_str + '\0',
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik val_bin = pysss_murmur.murmurhash3(input_str + '\0' * 5,
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose suite = unittest.TestLoader().loadTestsFromTestCase(PySssMurmurImport)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose # need to bail out here because pysss_murmur could not be imported
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose # import the pysss_murmur module into the global namespace, but make sure
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose # it's the one in tree
8f83feea4586a8fcf4365e0d22e0a16740424cc2Lukas Slebodnik suite = unittest.TestLoader().loadTestsFromTestCase(PySssMurmurTestNeg)