Ejemplo n.º 1
0
def test_is_sibling(animal):
    dog = animal.get('dog')
    cat = animal.get('cat')
    lion = animal.get('lion')
    assert cat.is_sibling(cat) is False
    assert cat.is_sibling(dog) is True
    assert cat.is_sibling(lion) is False
Ejemplo n.º 2
0
def test_delete_leaf(animal):
    cat = animal.get('cat')
    lion = animal.get('lion')

    animal.delete('lion')

    assert lion not in cat._children
    assert lion._parent is None
Ejemplo n.º 3
0
def test_delete_from_the_middle(animal):
    cat = animal.get('cat')
    lion = animal.get('lion')

    animal.delete('cat/lion')

    assert lion not in cat._children
    assert lion._parent is None
Ejemplo n.º 4
0
def test_delete_3_nodes_path(animal):
    cat = animal.get('cat')
    lion = animal.get('lion')

    animal.delete('mammal/cat/lion')

    assert lion not in cat._children
    assert lion._parent is None
Ejemplo n.º 5
0
def test_delete_2_nodes_path(animal):
    mammal = animal.get('mammal')
    cat = animal.get('cat')

    animal.delete('mammal/cat')

    assert cat not in mammal._children
    assert cat._parent is None
Ejemplo n.º 6
0
def test_move(animal):
    lion = animal.get('lion')
    dog = animal.get('dog')
    cat = animal.get('cat')

    # invalid move
    with pytest.raises(RootMoveError):
        animal.move('animal', 'lion')

    # valid move
    animal.move('lion', 'dog')
    assert lion._parent is dog
    assert lion in dog.children
    assert lion not in cat.children
Ejemplo n.º 7
0
def test_add(animal):
    bird = Category(name='bird')
    animal.add(bird)
    assert bird in animal._children

    wild_dog = Category(name='wild_dog')
    animal.add(wild_dog, 'dog')
    assert wild_dog in animal.get('dog')._children

    tiger = Category(name='tiger')
    animal.add(tiger, 'cat')
    assert tiger in animal.get('cat')._children

    white_lion = Category(name='white_lion')
    animal.add(white_lion, 'cat/lion')
    assert white_lion in animal.get('cat/lion')._children
Ejemplo n.º 8
0
def test_update_same_name_sibling(animal):
    cat = animal.get('cat')
    with pytest.raises(DuplicateNameError):
        cat.update(name='dog')
Ejemplo n.º 9
0
def test_update_same_name_parent(animal):
    cat = animal.get('cat')
    with pytest.raises(DuplicateNameError):
        cat.update(name='mammal')
Ejemplo n.º 10
0
def test_update(animal):
    cat = animal.get('cat')
    cat.update(name='cats', description='some description')
    assert cat.name == 'cats'
    assert cat.description == 'some description'