示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#8
0
def test_update_same_name_sibling(animal):
    cat = animal.get('cat')
    with pytest.raises(DuplicateNameError):
        cat.update(name='dog')
示例#9
0
def test_update_same_name_parent(animal):
    cat = animal.get('cat')
    with pytest.raises(DuplicateNameError):
        cat.update(name='mammal')
示例#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'