File: test_iregexp.py

package info (click to toggle)
python-jsonpath 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,024 kB
  • sloc: python: 9,462; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 990 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
import pytest

try:
    import iregexp_check  # noqa: F401

    IREGEXP_AVAILABLE = True
except ImportError:
    IREGEXP_AVAILABLE = False

import jsonpath


@pytest.mark.skipif(IREGEXP_AVAILABLE is False, reason="requires iregexp_check")
def test_iregexp_check() -> None:
    # Character classes are OK.
    query = "$[?match(@, '[0-9]+')]"
    data = ["123", "abc", "abc123"]
    assert jsonpath.findall(query, data) == ["123"]

    # Multi character escapes are not.
    query = "$[?match(@, '\\\\d+')]"
    assert jsonpath.findall(query, data) == []


@pytest.mark.skipif(IREGEXP_AVAILABLE, reason="iregexp_check is available")
def test_no_iregexp_check() -> None:
    # Character classes are OK.
    query = "$[?match(@, '[0-9]+')]"
    data = ["123", "abc", "abc123"]
    assert jsonpath.findall(query, data) == ["123"]

    # Multi character escapes are OK when iregexp_check is not installed.
    query = "$[?match(@, '\\\\d+')]"
    assert jsonpath.findall(query, data) == ["123"]