<commit_before>import unittest
from . import TestCase

from llvmlite import binding as llvm
from llvmlite.binding import dylib
import platform


class TestDylib(TestCase):

    def setUp(self):
        llvm.initialize()
        llvm.initialize_native_target()
        llvm.initialize_native_asmprinter()

    def test_bad_library(self):
        with self.assertRaises(Exception) as context:
            dylib.load_library_permanently("zzzasdkf;jasd;l")
        system = platform.system()
        if system  == "Linux":
            self.assertTrue('zzzasdkf;jasd;l: cannot open shared object file: No such file or directory'
                            in str(context.exception))
        elif system == "Darwin":
            self.assertTrue('dlopen(zzzasdkf;jasd;l, 9): image not found'
                            in str(context.exception))<commit_msg>Add tests to check loading library.<commit_after>from . import TestCase

from llvmlite import binding as llvm
from llvmlite.binding import dylib
import platform
from ctypes.util import find_library
import unittest

@unittest.skipUnless(platform.system() in {"Linux", "Darwin"}, "Unsupport test for current OS")
class TestDylib(TestCase):
    def setUp(self):
        llvm.initialize()
        llvm.initialize_native_target()
        llvm.initialize_native_asmprinter()
        self.system = platform.system()

    def test_bad_library(self):
        with self.assertRaises(Exception) as context:
            dylib.load_library_permanently("zzzasdkf;jasd;l")
        if self.system  == "Linux":
            self.assertTrue('zzzasdkf;jasd;l: cannot open shared object file: No such file or directory'
                            in str(context.exception))
        elif self.system == "Darwin":
            self.assertTrue('dlopen(zzzasdkf;jasd;l, 9): image not found'
                            in str(context.exception))

    def test_libm(self):
        try:
            if self.system  == "Linux":
                libm = find_library("m")
            elif self.system == "Darwin":
                libm = find_library("libm")
            dylib.load_library_permanently(libm)
        except Exception:
            self.fail("Valid call to link library should not fail.")
{'fraction_non_alphanumeric': 0.0927092709270927, 'fraction_numerical': 0.0009000900090009, 'mean_word_length': 2.5229793977812993, 'pattern_counts': {'":': 6, '<': 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': '7221139', 'n_tokens_mistral': 638, 'n_tokens_neox': 632, 'n_words': 161}