File: test_diff_from_bash_subshells.py

package info (click to toggle)
python-nbstripout 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 870; sh: 18; makefile: 13
file content (37 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pathlib import Path
import sys

import pytest

# fix this before pytester.chdir() happens
NOTEBOOKS_FOLDER = Path("tests").absolute()


def test_diff_with_process_substitution_nodiff(pytester: pytest.Pytester):
    if sys.platform.startswith("win"):
        pytest.skip("test requires proper bash shell")

    r = pytester.run(
        'bash',
        '-c',
        f'diff <( nbstripout -t {NOTEBOOKS_FOLDER / "test_diff.ipynb"} ) <( nbstripout -t {NOTEBOOKS_FOLDER / "test_diff_output.ipynb"} )',
    )
    assert not r.outlines
    assert r.ret == 0


def test_diff_with_process_substitution_diff(pytester: pytest.Pytester):
    if sys.platform.startswith("win"):
        pytest.skip("test requires proper bash shell")

    r = pytester.run(
        'bash',
        '-c',
        f'diff <( nbstripout -t {NOTEBOOKS_FOLDER / "test_diff.ipynb"} ) <( nbstripout -t {NOTEBOOKS_FOLDER / "test_diff_different.ipynb"} )',
    )
    r.stdout.re_match_lines(r"""(.*)
<     "print(\"aou\")"
---
(.*\"print\(\\\"aou now it is different\\\"\)\")
""".splitlines())
    assert r.ret == 1