Exemplo n.º 1
0
def test_coat():
    """Test that attributes are extracted first."""
    class AttrKey(dict):
        a = 7

    ak = AttrKey()
    ak['a'] = 8
    md = MagicDot(ak)
    assert md.a.get() == 7
Exemplo n.º 2
0
def test_solve():
    """Test that setting iter_nf_as_empty creates a new md"""
    md = MagicDot(1)
    assert md is not md.iter_nf_as_empty()
Exemplo n.º 3
0
def test_can():
    """Test that dict key is accessible as a hash ."""
    md = MagicDot({"num": 1})
    assert md.num.get() == 1
Exemplo n.º 4
0
def test_lesson():
    """Tests that NOT_FOUND returns empty generator with iter_nf_as_empty"""
    md = MagicDot(1, iter_nf_as_empty=True).nonexistent
    assert [x for x in md] == []
Exemplo n.º 5
0
def test_cat():
    """Tests that TypeError is raised for valid non-iterable when iter_nf_as_empty() is set"""
    md = MagicDot(1, iter_nf_as_empty=True)
    with pytest.raises(TypeError):
        [x for x in md]
Exemplo n.º 6
0
def test_curve():
    """Test that exception does not affect the get after NOT_FOUND is detected."""
    md = MagicDot({})
    md.nonexistent.exception().get()
Exemplo n.º 7
0
def test_both():
    """Test that exception is enabled with init."""
    md = MagicDot({}, exception=True)
    with pytest.raises(NotFound):
        md.nonexistent.get()
Exemplo n.º 8
0
def test_vote():
    """Tests that pluck of noniterable gives type_error even if .iter_nf_as_empty is set."""
    md = MagicDot(1)
    with pytest.raises(TypeError):
        md.iter_nf_as_empty().pluck('z')
Exemplo n.º 9
0
def test_yellow():
    """Test that a pluck of NOT_FOUND data raises an NotFound exception if .exception is set"""
    nt = namedtuple("NT", "x")(1)
    md = MagicDot([nt, None, nt])
    with pytest.raises(NotFound):
        md.exception().pluck("x")
Exemplo n.º 10
0
def test_neighborhood():
    """Tests that pluck of nonexistent data with .iter_nf_as_empty returns empty."""
    md = MagicDot(1)
    assert md.nonexistent.iter_nf_as_empty().pluck('whatevs').get() == []
Exemplo n.º 11
0
def test_vote():
    """Tests that pluck of noniterable gives type_error"""
    md = MagicDot(1)
    with pytest.raises(TypeError):
        md.pluck('z')
Exemplo n.º 12
0
def test_whistle():
    """Tests pluck of nonexistent data raises TypeError"""
    md = MagicDot(1)
    with pytest.raises(TypeError):
        md.nonexistent.pluck('z')
Exemplo n.º 13
0
def test_money():
    """Tests pluck of keys and nonexistent data."""
    d = {"x": 1}
    md = MagicDot([d, None, d])
    assert md.pluck("x").get() == [1, NOT_FOUND, 1]
Exemplo n.º 14
0
def test_sign():
    """Tests pluck of attributes and nonexistent data."""
    nt = namedtuple("NT", "x")(1)
    md = MagicDot([nt, None, nt])
    assert md.pluck("x").get() == [1, NOT_FOUND, 1]
Exemplo n.º 15
0
def test_reader():
    """Test that setting iter_nf_as_empty twice does note create a new md"""
    md = MagicDot(1, iter_nf_as_empty=True)
    assert md is md.iter_nf_as_empty()
Exemplo n.º 16
0
def test_supply():
    """Test that boolean math is not allowed with magic_dot."""
    md = MagicDot(1)
    with pytest.raises(RuntimeError):
        not md
Exemplo n.º 17
0
def test_other():
    """Test supplied default is returned for NOT_FOUND"""
    md = MagicDot({"num": 1})
    assert md.bubba.get("something") == "something"
Exemplo n.º 18
0
def test_yet():
    """Test NOT_FOUND is returned."""
    md = MagicDot({"num": 1})
    assert md.buba.get() is NOT_FOUND
Exemplo n.º 19
0
def test_ride():
    """Test that indexed processing happens by default."""
    nt = namedtuple("NT", "x")(1)
    md = MagicDot([nt, None, nt])
    assert md[1].get() is None
Exemplo n.º 20
0
def test_important():
    """Test that boolean math is not allowed on NOT_FOUND"""
    md = MagicDot(1)
    with pytest.raises(RuntimeError):
        not md.nonexistent.get()
Exemplo n.º 21
0
def test_been():
    """Test that exception is enabled with exception."""
    md = MagicDot({})
    with pytest.raises(NotFound):
        md.exception().nonexistent
Exemplo n.º 22
0
def test_in():
    """Test that repr for NOT_FOUND works nicely (for documentation)."""
    md = MagicDot(1)
    assert repr(md.nonexistent.get()) == "magic_dot.NOT_FOUND"
Exemplo n.º 23
0
def test_pie():
    """Test that TypeError is raised when iterating over non-data"""
    md = MagicDot(1)
    with pytest.raises(TypeError):
        [x for x in md]
Exemplo n.º 24
0
def test_gate():
    """Test that setting exception creates a new md"""
    md = MagicDot(1)
    assert md is not md.exception()
Exemplo n.º 25
0
def test_atom():
    """Tests that TypeError is raised for NOT_FOUND by default"""
    md = MagicDot(1).nonexistent
    with pytest.raises(TypeError):
        [x for x in md]
Exemplo n.º 26
0
def test_bowl():
    """Test that setting exception twice does note create a new md"""
    md = MagicDot(1, exception=True)
    assert md is md.exception()
Exemplo n.º 27
0
def test_layers():
    """Tests that NOT_FOUND returns empty generator with iter_nf_as_empty()"""
    md = MagicDot(1).nonexistent.iter_nf_as_empty()
    assert [x for x in md] == []
Exemplo n.º 28
0
def test_sign():
    """Tests ability to walk iterable data."""
    md = MagicDot([None, 1, 2])
    expected = [None, 1, 2]
    for x in md:
        assert x.get() == expected.pop(0)