File: test_history_dummy.py

package info (click to toggle)
xonsh 0.13.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,024 kB
  • sloc: python: 46,350; makefile: 136; sh: 41; xml: 17
file content (41 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download | duplicates (3)
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
40
41
"""Tests the dummy history backend."""

import pytest

from xonsh.history.dummy import DummyHistory
from xonsh.history.main import construct_history


@pytest.mark.parametrize("backend", ["dummy", DummyHistory, DummyHistory()])
def test_construct_history_str(xession, backend):
    xession.env["XONSH_HISTORY_BACKEND"] = backend
    assert isinstance(construct_history(), DummyHistory)


def test_ignore_regex_invalid(xession, capsys):
    xession.env["XONSH_HISTORY_BACKEND"] = "dummy"
    xession.env["XONSH_HISTORY_IGNORE_REGEX"] = "**"
    history = construct_history()
    captured = capsys.readouterr()
    assert (
        "XONSH_HISTORY_IGNORE_REGEX is not a valid regular expression and will be ignored"
        in captured.err
    )
    assert not history.is_ignored({"inp": "history"})


def test_is_ignore(xession):
    xession.env["XONSH_HISTORY_BACKEND"] = "dummy"
    xession.env["XONSH_HISTORY_IGNORE_REGEX"] = "(ls|cat)"
    history = construct_history()
    assert history.is_ignored({"inp": "cat foo.txt"})
    assert not history.is_ignored({"inp": "history"})
    assert history.is_ignored({"inp": "ls bar"})


def test_is_ignore_no_regex(xession):
    xession.env["XONSH_HISTORY_BACKEND"] = "dummy"
    history = construct_history()
    assert not history.is_ignored({"inp": "cat foo.txt"})
    assert not history.is_ignored({"inp": "history"})
    assert not history.is_ignored({"inp": "ls bar"})