Beispiel #1
0
def test_jsonp_path_cached():
    class C(str):
        pass

    p = C("a/b")
    assert jsonp_path(p) == ["a", "b"]
    p._jsonp = False
    assert jsonp_path(p) == [p]
    assert p._jsonp == False
    p._jsonp = None
    assert jsonp_path(p) == ["a", "b"]
    assert p._jsonp == None
Beispiel #2
0
def test_modifs_rename_fn(mod, exp, ser_method):
    renamer = lambda n: f"p.{n}"
    dep = mod()
    got = dep_renamed(dep, renamer)
    assert repr(got) == exp
    assert repr(ser_method(got)) == exp
    assert modifier_kws(got) == modifier_kws(dep)

    if getattr(dep, "_sideffected", None):
        # Check not just(!) `_repr` has changed.
        assert got._sideffected != dep._sideffected

    if getattr(dep, "_jsonp", None):
        assert got._jsonp != dep._jsonp
        assert got._jsonp == jsonp_path(got)
        assert got._jsonp == jsonp_path(str(got))
Beispiel #3
0
def test_jsonp_path_None():
    with pytest.raises(TypeError):
        jsonp_path(None)
Beispiel #4
0
def test_jsonp_path_with_spaces():
    assert jsonp_path("/ some ") == ["", " some "]
    assert jsonp_path("/ some /  ") == ["", " some ", "  "]

    assert jsonp_path(" some ") == [" some "]
    assert jsonp_path(" some /  ") == [" some ", "  "]
Beispiel #5
0
def test_jsonp_path_folder():
    assert jsonp_path("/a/") == [""]
Beispiel #6
0
def test_jsonp_path_regular():
    assert jsonp_path("/a") == ["", "a"]

    assert jsonp_path("/a/b") == ["", "a", "b"]
Beispiel #7
0
def test_jsonp_path_root():
    assert jsonp_path("/") == [""]
Beispiel #8
0
def test_jsonp_path_empty():
    assert jsonp_path("") == [""]
Beispiel #9
0
def test_jsonp_path_massive(inp, exp):
    if isinstance(exp, Exception):
        with pytest.raises(type(exp), match=str(exp)):
            jsonp_path(inp)
    else:
        assert jsonp_path(inp) == exp