Beispiel #1
0
def test_paper_equal():
    my_paper1 = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-a.json')
    my_paper3 = Paper(filename='tests/test_files/paper-k.json')

    assert my_paper1 == my_paper2
    assert my_paper1 != my_paper3
Beispiel #2
0
def test_load_from_semantic_scholar():
    data = Paper()
    data.load_from_semantic_scholar('10.1093/nar/gkw1328')
    assert data['title']=='Rapid resistome mapping using nanopore sequencing'

    data2 = Paper(doi='10.1093/nar/gkw1328')
    assert data2['title']=='Rapid resistome mapping using nanopore sequencing'
Beispiel #3
0
def test_paper_parse_two():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    my_network = PaperNetwork()
    my_network.collection.append(my_paper)
    my_network.collection.append(my_paper2)

    #my_network.parse_papers()

    assert my_network.graph.size() == 6
    assert len(my_network.graph.nodes()) == 6  #-> ['title - x', 'title - a', 'title - y', 'title - b', 'title - c', 'title - k']
    assert my_network.graph.nodes['a']['year'] == "2000"
    assert my_network.graph.nodes['b']['year'] == "1990"
    assert my_network.graph.nodes['x']['year'] == "2003"


    my_network.collection.remove(my_paper2)

    assert my_network.graph.size() == 4
    assert len(my_network.graph.nodes()) == 5


    # Testing the deepcopy function. Everytime we access the graph, we need to check whether the collection changed
    assert my_network.graph.nodes[my_network.collection[0]['paperId']]['year'] == my_network.collection[0]['year']
    my_network.collection[0]['year'] = "9999"
    assert my_network.graph.nodes[my_network.collection[0]['paperId']]['year'] == my_network.collection[0]['year'] # Test that the deepcopy of the Paperlist is functioning
    assert my_network.graph.size() == 4
Beispiel #4
0
def test_paper_list_representations():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    list1 = PaperList([my_paper, my_paper2])
    
    assert list1.titles == ['title - a', 'title - k']
    assert list1.paperIds == ['a', 'k']
Beispiel #5
0
def test_append():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    my_network = PaperNetwork()
    my_network.collection.append(my_paper)

    assert my_paper in my_network.collection 
    assert my_paper2 not in my_network.collection 
Beispiel #6
0
def test_append_not_unique():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper_duplicate = Paper(filename='tests/test_files/paper-a.json')
    my_network = PaperNetwork()

    my_network.collection.append(my_paper)
    with pytest.raises(ValueError, match=r"This paperId is already present, only unique paperIds allowed"):
        my_network.collection.append(my_paper_duplicate)
Beispiel #7
0
def test_paper_list_two():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    listA = PaperList([my_paper, my_paper2])
    listB = copy.deepcopy(listA)

    assert listA == listB

    listA[0]['new key'] = 'makes listA and listB not the same'

    assert listA != listB
Beispiel #8
0
def test_paper_list():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    list1 = PaperList([my_paper])
    list2 = PaperList([my_paper])
    list3 = PaperList([my_paper2])
    assert list1 == list2
    assert list1 != list3
    list1 = PaperList([my_paper, my_paper2])
    list2 = PaperList([my_paper, my_paper2])
    list3 = PaperList([my_paper2, my_paper])
    assert list1 == list2
    assert list1 != list3  # PaperList is a  List and not a Set, so these are not equal
Beispiel #9
0
def test_paper_parse():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    my_network = PaperNetwork()
    my_network.collection.append(my_paper)
    my_network.collection.append(my_paper2)

    assert my_network.graph.size() == 6
    assert len(my_network.graph.nodes()) == 6 #-> ['title - x', 'title - a', 'title - y', 'title - b', 'title - c', 'title - k']
    assert my_network.graph.nodes['a']['year'] == "2000"
    assert my_network.graph.nodes['b']['year'] == "1990"
    assert my_network.graph.nodes['x']['year'] == "2003"

    assert my_network.graph.nodes['c']['year'] == "1991"
    assert my_network.graph.nodes['k']['year'] == "2005"
    assert my_network.graph.nodes['y']['year'] == "2011"
Beispiel #10
0
def test_update_paper_without_paperId():
    my_paper = Paper(filename='tests/test_files/paper-a.json')

    with pytest.raises(ValueError, match=r"Paper cannot have an empty paperId"):
        my_paper['paperId'] = ''

    with pytest.raises(ValueError, match=r"Paper cannot have an empty paperId"):
        del my_paper['paperId']
Beispiel #11
0
def test_paper_json():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    my_paper2 = Paper(filename='tests/test_files/paper-k.json')
    my_network = PaperNetwork()
    my_network.collection.append(my_paper)
    my_network.collection.append(my_paper2)


    assert my_network.calculate_json() == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - y', 'year': '2011', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 0, 'corpus': 5, 'out_degree': 1, 'id': 'y'}, {'title': 'title - b', 'year': '1990', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 0, 'out_degree': 0, 'id': 'b'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'b'}, {'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'y', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}

    # these three cases should not  change the output
    assert my_network.calculate_json(mimimum_citation_count_of_references=1) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - y', 'year': '2011', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 0, 'corpus': 5, 'out_degree': 1, 'id': 'y'}, {'title': 'title - b', 'year': '1990', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 0, 'out_degree': 0, 'id': 'b'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'b'}, {'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'y', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}
    assert my_network.calculate_json(mimimum_citation_count_of_references=1, minimum_times_citing_collection=1) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - y', 'year': '2011', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 0, 'corpus': 5, 'out_degree': 1, 'id': 'y'}, {'title': 'title - b', 'year': '1990', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 0, 'out_degree': 0, 'id': 'b'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'b'}, {'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'y', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}
    assert my_network.calculate_json(minimum_times_citing_collection=1) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - y', 'year': '2011', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 0, 'corpus': 5, 'out_degree': 1, 'id': 'y'}, {'title': 'title - b', 'year': '1990', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 0, 'out_degree': 0, 'id': 'b'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'b'}, {'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'y', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}

    # with restrictions
    assert my_network.calculate_json(mimimum_citation_count_of_references=2) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - y', 'year': '2011', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 0, 'corpus': 5, 'out_degree': 1, 'id': 'y'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'y', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}
    assert my_network.calculate_json(minimum_times_citing_collection=2) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 2, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - x', 'year': '2003', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 1, 'corpus': 5, 'out_degree': 1, 'id': 'x'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'c'}, {'source': 'x', 'target': 'a'}, {'source': 'k', 'target': 'x'}, {'source': 'k', 'target': 'c'}]}

    # double restrictions
    assert my_network.calculate_json(mimimum_citation_count_of_references=2, minimum_times_citing_collection=2 ) == {'directed': True, 'multigraph': False, 'graph': {}, 'nodes': [{'title': 'title - a', 'year': '2000', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 1, 'corpus': 1, 'out_degree': 0, 'id': 'a'}, {'title': 'title - c', 'year': '1991', 'url': [], 'authors': [], 'venue': [], 'warning': [], 'in_degree': 2, 'corpus': 0, 'out_degree': 0, 'id': 'c'}, {'title': 'title - k', 'year': '2005', 'url': [], 'authors': [], 'venue': [], 'warning': ['Serious warning: reference list seems very short (<10)', 'Note: seems like not widely cited (<5)'], 'in_degree': 0, 'corpus': 1, 'out_degree': 0, 'id': 'k'}], 'links': [{'source': 'a', 'target': 'c'}, {'source': 'k', 'target': 'c'}]}
Beispiel #12
0
def test_load_url_fail():
    data = Paper().load_url('http://www.dnacoil.com/doesntwork')
    assert data is False
Beispiel #13
0
def test_load_url_ok():
    """ From jsonplaceholder.com retrieve a fake response to test the url part without overloading semantic scholar"""
    data = json.loads(Paper().load_url('https://jsonplaceholder.typicode.com/todos/1').read())
    assert data == {'userId': 1, 'id': 1, 'title': 'delectus aut autem', 'completed': False}
Beispiel #14
0
def test_load_url_fail():
    Paper().load_url('https://jsonplaceholder.typicode.com/todos/1')
    
Beispiel #15
0
def test_init_fail_both():
    with pytest.raises(Exception) as execinfo:
        Paper(filename='foo', doi='bar')
    assert str(execinfo.value) == 'Cannot use both filename and doi to retreive paper'
Beispiel #16
0
def test_load_from_file_two():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    assert my_paper['title'] == "title - a"
    assert my_paper['year'] == "2000"
    assert len(my_paper['references']) == 2
    assert len(my_paper['citations']) == 2
Beispiel #17
0
def test_load_from_file():
    assert Paper(filename='tests/test_files/10.1038_SLASH_s41564-019-0626-z.json')['title'] == "Rapid MinION profiling of preterm microbiota and antimicrobial-resistant pathogens"
    my_paper = Paper()
    my_paper.load_from_file('tests/test_files/10.1038_SLASH_s41564-019-0626-z.json')
    assert my_paper['title'] == "Rapid MinION profiling of preterm microbiota and antimicrobial-resistant pathogens"
Beispiel #18
0
def test_load_from_semantic_scholar_wrong_doi():
    with pytest.raises(Exception) as execinfo:
        data = Paper().load_from_semantic_scholar('doidoesnotexcist')
    assert str(execinfo.value) == 'Download failed'
Beispiel #19
0
def test_setting_paper_directly_without_title():
    with pytest.raises(ValueError, match=r"Paper cannot have an empty title"):
        my_paper = Paper(data={"paperId":"q","title":"","year":"2000"})
Beispiel #20
0
def test_update_paper_paperId_not_as_string():
    my_paper = Paper(filename='tests/test_files/paper-a.json')
    
    with pytest.raises(TypeError, match=r"paperId must be a string"):
        my_paper['paperId'] = 3
Beispiel #21
0
def test_setting_paper_directly():
    my_paper = Paper(data={"paperId":"q","title":"title - q","year":"2000"})
    assert my_paper['title'] == 'title - q'