pysss_murmur-test.py revision 9e1de5c83371d91e200254cceef70852f5f94fd2
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)
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda print("Could not load the pysss_murmur module. Please check if it is compiled", file=sys.stderr)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertEqual(pysss_murmur.__file__, MODPATH + "/pysss_murmur.so")
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose hash = pysss_murmur.murmurhash3("S-1-5-21-2153326666-2176343378-3404031434", 41, 0xdeadbeef)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, 1, 2, 3)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test", 2)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test")
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test", -1, 3)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test", 2,
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose 0xffffffffff)
60e51fd2764291df2332f36ff478777627d92b57Sumit Bose self.assertRaises(ValueError, pysss_murmur.murmurhash3, "test",
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