<commit_before>from nbdiff.adapter import git_adapter as g
from pretend import stub


def test_get_modified_notebooks_empty():
    g.subprocess = stub(check_output=lambda cmd: '')
    adapter = g.GitAdapter()
    result = adapter.get_modified_notebooks()
    assert result == []


def test_get_unmerged_notebooks_empty():
    g.subprocess = stub(check_output=lambda cmd: '')
    adapter = g.GitAdapter()
    result = adapter.get_unmerged_notebooks()
    assert result == []<commit_msg>Test unmerged notebooks git adapter<commit_after>from nbdiff.adapter import git_adapter as g
from pretend import stub


def test_get_modified_notebooks_empty():
    g.subprocess = stub(check_output=lambda cmd: '')
    adapter = g.GitAdapter()
    result = adapter.get_modified_notebooks()
    assert result == []


def test_get_modified_notebooks():
    adapter = g.GitAdapter()

    def check_output_stub(cmd):
        if '--modified' in cmd:
            output = '''foo.ipynb
bar.ipynb
foo.txt
baz.ipynb
'''
            return output
        elif '--unmerged' in cmd:
            return ''.join([
                '100755\thash\t{i}\tfoo.ipynb\n'
                for i in [1, 2, 3]
            ])

    def popen(*args, **kwargs):
        return stub(stdout=stub(read=lambda: ""))

    g.open = lambda fname: stub(read=lambda: "")
    g.subprocess = stub(
        check_output=check_output_stub,
        PIPE='foo',
        Popen=popen,
    )
    result = adapter.get_modified_notebooks()
    assert result[0][2] == 'bar.ipynb'
    assert result[1][2] == 'baz.ipynb'


def test_get_unmerged_notebooks_empty():
    g.subprocess = stub(check_output=lambda cmd: '')
    adapter = g.GitAdapter()
    result = adapter.get_unmerged_notebooks()
    assert result == []


def test_get_unmerged_notebooks():
    adapter = g.GitAdapter()

    def check_output_stub(cmd):
        if '--unmerged' in cmd:
            f1 = ''.join([
                '100755\thash\t{i}\tfoo.ipynb\n'
                for i in [1, 2, 3]
            ])
            f2 = ''.join([
                '100755\thash\t{i}\tbar.ipynb\n'
                for i in [1, 2, 3]
            ])
            f3 = ''.join([
                '100755\thash\t{i}\tfoo.py\n'
                for i in [1, 2, 3]
            ])
            return f1 + f2 + f3

    def popen(*args, **kwargs):
        return stub(stdout=stub(read=lambda: ""))

    g.open = lambda fname: stub(read=lambda: "")
    g.subprocess = stub(
        check_output=check_output_stub,
        PIPE='foo',
        Popen=popen,
    )
    result = adapter.get_unmerged_notebooks()
    assert len(result) == 2
    assert result[0][3] == 'foo.ipynb'
    assert result[1][3] == 'bar.ipynb'
{'fraction_non_alphanumeric': 0.13166728832525176, 'fraction_numerical': 0.019022752704214847, 'mean_word_length': 2.3316770186335405, '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': '5598687', 'n_tokens_mistral': 959, 'n_tokens_neox': 902, 'n_words': 186}