Exemplo n.º 1
0
def test_wrap(test_root_entry_json, test_entry_json, test_child_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    root_entry.wrap(entry)
    assert entry in root_entry.children
Exemplo n.º 2
0
def test_link(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    assert len(entry.children) == 1
    assert len(child.parents) == 1
    assert child in entry.children
    assert entry in child.parents
Exemplo n.º 3
0
def test_wrap_should_not_add_additional_children(test_root_entry_json,
                                                 test_entry_json,
                                                 test_child_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    root_entry.wrap(entry)
    assert len(root_entry.children) == 1
Exemplo n.º 4
0
def test_items_should_not_contains_root_id(test_root_entry_json,
                                           test_entry_json,
                                           test_child_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    root_entry.wrap(entry)
    root_items = root_entry.items()
    assert root_entry.id not in root_items
Exemplo n.º 5
0
def test_items_should_not_contains_additional_item(test_root_entry_json,
                                                   test_entry_json,
                                                   test_child_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    root_entry.wrap(entry)
    root_items = root_entry.items()
    assert len(root_items) == 2
Exemplo n.º 6
0
def test_wrap_should_not_add_duplicate_child_ids(test_root_entry_json,
                                                 test_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    root_entry.wrap(entry)
    root_entry.wrap(entry)
    assert len(root_entry.child_ids) == 1
Exemplo n.º 7
0
def test_entry_properties(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry.root_dir is None
    assert entry.id == test_entry_json['id']
    assert entry.name == test_entry_json['name']
    assert entry.description == test_entry_json['description']
    assert entry.citation_uri == test_entry_json['citation_uri']
    assert entry.positive_examples == test_entry_json['positive_examples']
    assert entry.child_ids == test_entry_json['child_ids']
    assert entry.restrictions == test_entry_json['restrictions']
Exemplo n.º 8
0
def test_items_should_contains_all_entries(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    items = entry.items()
    assert entry.id in items
    assert child.id in items
Exemplo n.º 9
0
def test_contains_with_entry(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    invalid = Entry(None, 'invalid_id', 'Test Child')
    entry.link(child)
    assert child in entry
    assert invalid not in entry
Exemplo n.º 10
0
def test_items_should_contains_all_entries(test_root_entry_json,
                                           test_entry_json,
                                           test_child_entry_json):
    root_entry = RootEntry(**test_root_entry_json)
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    root_entry.wrap(entry)
    items = entry.items()
    root_items = root_entry.items()
    assert all(map(lambda item: item in root_items, items))
Exemplo n.º 11
0
def test_initial_parents(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert len(entry.parents) == 0
Exemplo n.º 12
0
def test_identifiers(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry.identifiers == (entry.id, entry.name, entry.slug_name)
Exemplo n.º 13
0
def test_proper_name(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert '.' not in entry.proper_name
Exemplo n.º 14
0
def test_slug_name_should_not_contains_leading_or_trailing_dashes(test_entry2_json):
    entry = Entry(None, **test_entry2_json)
    assert not (entry.slug_name.startswith('-') or entry.slug_name.endswith('-'))
Exemplo n.º 15
0
def test_link_with_intruder_child(test_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, 'invalid_id', 'Test Child')
    with pytest.raises(ValueError):
        entry.link(child)
Exemplo n.º 16
0
def test_string_representation_should_contains_id(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry.id in str(entry)
Exemplo n.º 17
0
def test_equality_against_str(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry == '/m/0dgw9r'
    assert entry == 'Human sounds'
    assert entry == 'human-sounds'
Exemplo n.º 18
0
def test_getitem(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    assert entry[child.id] == child
Exemplo n.º 19
0
def test_paths(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    assert os.path.join(entry.proper_name, child.proper_name) in child.paths
Exemplo n.º 20
0
def test_contains_with_invalid_type(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert 1 not in entry
Exemplo n.º 21
0
def test_contains_with_str(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    assert child.id in entry
    assert 'invalid_id' not in entry
Exemplo n.º 22
0
def test_link_already_linked_child(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    with pytest.raises(ValueError):
        entry.link(child)
Exemplo n.º 23
0
def test_initial_children(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert len(entry.children) == 0
Exemplo n.º 24
0
def test_getitem_with_invalid_type_key(test_entry_json):
    entry = Entry(None, **test_entry_json)
    with pytest.raises(KeyError):
        assert entry[1]
Exemplo n.º 25
0
def test_equality(test_entry_json):
    entry1 = Entry(None, **test_entry_json)
    entry2 = Entry(None, **test_entry_json)
    assert entry1 == entry2
Exemplo n.º 26
0
def test_items_should_not_contains_additional_item(test_entry_json, test_child_entry_json):
    entry = Entry(None, **test_entry_json)
    child = Entry(None, **test_child_entry_json)
    entry.link(child)
    items = entry.items()
    assert len(items) == 2
Exemplo n.º 27
0
def test_equality_with_invalid_type(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry != 1
Exemplo n.º 28
0
def test_slug_name(test_entry_json):
    entry = Entry(None, **test_entry_json)
    assert entry.slug_name == 'human-sounds'
Exemplo n.º 29
0
def test_dirs(test_root_dir, test_entry_json, test_child_entry_json):
    entry = Entry(root_dir=test_root_dir, **test_entry_json)
    child = Entry(root_dir=test_root_dir, **test_child_entry_json)
    entry.link(child)
    assert os.path.join(test_root_dir, entry.proper_name, child.proper_name) in child.dirs
Exemplo n.º 30
0
def test_link_with_invalid_type(test_entry_json):
    entry = Entry(None, **test_entry_json)
    with pytest.raises(TypeError):
        entry.link('child')