File: test_diff_from_bash_subshells.py

package info (click to toggle)
python-nbstripout 0.9.0-1~exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 464 kB
  • sloc: python: 1,068; sh: 20; makefile: 13
file content (39 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (2)
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
38
39
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