def test_enforce_line_length(capsys): s = 80 * "*" y(s) y(s, enforce_line_length=True) out, err = capsys.readouterr() assert (err == """\ y| s: '********************************************************************************' y| s: '************************************************************************ """) with y.preserve(): y.configure(line_length=20, show_line_number=True) y() out, err1 = capsys.readouterr() y(enforce_line_length=True) out, err2 = capsys.readouterr() err1 = err1.rstrip("\n") err2 = err2.rstrip("\n") assert len(err2) == 20 assert err1[10:20] == err2[10:20] assert len(err1) > 20 res = y("abcdefghijklmnopqrstuvwxyz", p="", ell=1, ll=20, as_str=True).rstrip("\n") assert res == "'abcdefghijklmnopqrs" assert len(res) == 20
def test_clone(): hello = "world" z = y.clone() z.configure(prefix="z| ") sy = y(hello, as_str=True) with y.preserve(): y.configure(show_line_number=True) sz = z(hello, as_str=True) assert sy.replace("y", "z") == sz
def test_calls(): with pytest.raises(TypeError): y.new(a=1) with pytest.raises(TypeError): y.clone(a=1) with pytest.raises(TypeError): y.configure(a=1) with pytest.raises(TypeError): y(12, a=1) with pytest.raises(TypeError): y(a=1)
def test_enabled(capsys): with y.preserve(): y("One") y.configure(enabled=False) y("Two") s = y("Two", as_str=True) assert s == "y| 'Two'\n" y.configure(enabled=True) y("Three") out, err = capsys.readouterr() assert (err == """\ y| 'One' y| 'Three' """)
def test_enabled3(capsys): with y.preserve(): y.configure(enabled=[]) y(2) with pytest.raises(TypeError): @y() def add2(x): return x + 2 with pytest.raises(AttributeError): with y(): pass @y(decorator=True) def add2(x): return x + 2 with y(context_manager=True): pass
def test_enabled2(capsys): with y.preserve(): y.configure(enabled=False) line0 = y("line0") noline0 = y(prefix="no0") pair0 = y("p0", "p0") s0 = y("s0", as_str=True) y.configure(enabled=[]) line1 = y("line1") noline1 = y(prefix="no1") pair1 = y("p1", "p1") s1 = y("s1", as_str=True) y.configure(enabled=True) line2 = y("line2") noline2 = y(prefix="no2") pair2 = y("p2", "p2") s2 = y("s2", as_str=True) out, err = capsys.readouterr() assert "line0" not in err and "p0" not in err and "no0" not in err assert "line1" not in err and "p1" not in err and "no1" not in err assert "line2" in err and "p2" in err and "no2" in err assert line0 == "line0" assert line1 == "line1" assert line2 == "line2" assert noline0 is None assert noline1 is None assert noline2 is None assert pair0 == ("p0", "p0") assert pair1 == ("p1", "p1") assert pair2 == ("p2", "p2") assert s0 == "y| 's0'\n" assert s1 == "y| 's1'\n" assert s2 == "y| 's2'\n"
def test_values_only(): with y.preserve(): y.configure(values_only=True) hello = "world" s = y(hello, as_str=True) assert s == "y| 'world'\n"