<commit_before># -*- coding: utf-8 -*-

import pytest

from IPython.testing.globalipapp import get_ipython
from IPython.core.history import HistoryManager


@pytest.fixture(scope='session')
def kernel():
    HistoryManager.enabled = False
    ip = get_ipython()
    ip.extension_manager.load_extension('ipybind')
    return ip


@pytest.fixture(scope='function')
def ip(kernel):
    kernel.reset()
    return kernel


def module(code):
    return """PYBIND11_PLUGIN(test) {{
        py::module m("test");
        {}
        return m.ptr();
    }}""".format(code)


def test_pybind11_capture(ip, capsys):
    ip.run_line_magic('pybind11_capture', '-f')
    out, _ = capsys.readouterr()
    assert 'capturing is not available' in out


def test_import_all(ip):
    ip.run_cell_magic('pybind11', '', module("""
        m.attr("x") = py::cast(1);
        m.attr("_y") = py::cast(2);
        m.attr("__z") = py::cast(3);
    """))
    assert ip.user_ns['x'] == 1
    assert ip.user_ns['_y'] == 2
    assert '__z' not in ip.user_ns<commit_msg>(Fix magics arguments in the test)<commit_after># -*- coding: utf-8 -*-

import pytest

from IPython.testing.globalipapp import get_ipython
from IPython.core.history import HistoryManager


@pytest.fixture(scope='session')
def kernel():
    HistoryManager.enabled = False
    ip = get_ipython()
    ip.extension_manager.load_extension('ipybind')
    return ip


@pytest.fixture(scope='function')
def ip(kernel):
    kernel.reset()
    return kernel


def module(code):
    return """PYBIND11_PLUGIN(test) {{
        py::module m("test");
        {}
        return m.ptr();
    }}""".format(code)


def test_pybind11_capture(ip, capsys):
    ip.run_line_magic('pybind11_capture', '')
    out, _ = capsys.readouterr()
    assert 'capturing is not available' in out


def test_import_all(ip):
    ip.run_cell_magic('pybind11', '-f', module("""
        m.attr("x") = py::cast(1);
        m.attr("_y") = py::cast(2);
        m.attr("__z") = py::cast(3);
    """))
    assert ip.user_ns['x'] == 1
    assert ip.user_ns['_y'] == 2
    assert '__z' not in ip.user_ns
{'fraction_non_alphanumeric': 0.16420047732696896, 'fraction_numerical': 0.013365155131264916, 'mean_word_length': 3.3485477178423237, 'pattern_counts': {'":': 0, '<': 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': '4082009', 'n_tokens_mistral': 770, 'n_tokens_neox': 746, 'n_words': 150}