<commit_before>from numba.pycc import CC
from numba import i8
from numba.core.types import DictType, unicode_type
from numba.typed import List, Dict
from numba.tests.support import TestCase
import unittest
import os, glob


class TestImportStringHashing(TestCase):

    """
    Tests that numba compiled modules can be imported if they have
     functions that internally hash strings. See issue #6386.
    """
    def setUp(self):
        cc = CC('str_dict_module')

        nb_nt = DictType(unicode_type,i8)

        @cc.export('in_str_dict',(DictType(unicode_type,i8),unicode_type))
        def in_str_dict(d,x):
           if(x not in d):
              d[x] = len(d)

        @cc.export('out_str_dict',DictType(unicode_type,i8)(unicode_type,))
        def out_str_dict(x):
           d = Dict.empty(unicode_type,i8)
           if(x not in d):
              d[x] = len(d)
           return d

        cc.compile()

    def test_import_str_dicts(self):
        from str_dict_module import in_str_dict as _in_str_dict
        from str_dict_module import out_str_dict as _out_str_dict
        d = _out_str_dict('boop')
        _in_str_dict(d,'beep')
        self.assertEqual(d['beep'], 1)

    def tearDown(self):
        os.remove(glob.glob("str_dict_module.*[dll|so]")[0])

if __name__ == "__main__":
    unittest.main()
        

<commit_msg>added test that hashes come out same as python<commit_after>from numba.pycc import CC
from numba import i8
from numba.core.types import DictType, unicode_type
from numba.typed import List, Dict
from numba.tests.support import TestCase
import unittest
import os, glob


class TestImportStringHashing(TestCase):

    """
    Tests that numba compiled modules can be imported if they have
     functions that internally hash strings. See issue #6386.
    """
    def setUp(self):
        cc = CC('str_dict_module')

        nb_nt = DictType(unicode_type,i8)

        @cc.export('in_str_dict',(DictType(unicode_type,i8),unicode_type))
        def in_str_dict(d,x):
           if(x not in d):
              d[x] = len(d)

        @cc.export('out_str_dict',DictType(unicode_type,i8)(unicode_type,))
        def out_str_dict(x):
           d = Dict.empty(unicode_type,i8)
           if(x not in d):
              d[x] = len(d)
           return d

        @cc.export('hash_str',(unicode_type,))
        def hash_str(x):
           return hash(x)

        cc.compile()

    def test_import_str_dicts(self):
        from str_dict_module import in_str_dict as _in_str_dict
        from str_dict_module import out_str_dict as _out_str_dict
        from str_dict_module import hash_str as _hash_str
        d = _out_str_dict('boop')
        _in_str_dict(d,'beep')
        self.assertEqual(d['beep'], 1)
        self.assertEqual(_hash_str('beep'), hash('beep'))

    def tearDown(self):
        os.remove(glob.glob("str_dict_module.*[dll|so]")[0])

if __name__ == "__main__":
    unittest.main()
        


{'fraction_non_alphanumeric': 0.1044928522804629, 'fraction_numerical': 0.007488087134104833, 'mean_word_length': 2.748724489795918, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '339996', 'n_tokens_mistral': 1024, 'n_tokens_neox': 980, 'n_words': 227}