Esempio n. 1
0
def test_guess_keywords_fails_without_a_magpie_url(g_m_u):
    g_m_u.return_value = None

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data == {}
def test_guess_keywords_fails_without_a_magpie_url(g_m_u):
    g_m_u.return_value = None

    obj = StubObj({}, {})
    eng = DummyEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data == {}
Esempio n. 3
0
def test_guess_keywords_does_not_fail_when_request_fails(j_a_r, g_m_u):
    j_a_r.side_effect = requests.exceptions.RequestException()
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data == {}
def test_guess_keywords_does_not_fail_when_request_fails(j_a_r, g_m_u):
    j_a_r.side_effect = requests.exceptions.RequestException()
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = StubObj({}, {})
    eng = DummyEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data == {}
Esempio n. 5
0
def test_guess_keywords_accepts_over_point_09(j_a_r, g_m_u):
    j_a_r.return_value = {
        'labels': [
            ('foo', 0.09),
        ],
    }
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = MockObj({}, {})
    eng = MockEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data['keywords_prediction'] == {
        'keywords': [
            {
                'label': 'foo',
                'score': 0.09,
                'accept': True,
            },
        ]
    }
def test_guess_keywords_accepts_over_point_09(j_a_r, g_m_u):
    j_a_r.return_value = {
        'labels': [
            ('foo', 0.09),
        ],
    }
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = StubObj({}, {})
    eng = DummyEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data['keywords_prediction'] == {
        'keywords': [
            {
                'label': 'foo',
                'score': 0.09,
                'accept': True,
            },
        ]
    }
def test_guess_keywords_considers_only_first_ten(j_a_r, g_m_u):
    j_a_r.return_value = {
        'labels': [
            ('k01', 1.00),
            ('k02', 1.00),
            ('k03', 1.00),
            ('k04', 1.00),
            ('k05', 1.00),
            ('k06', 1.00),
            ('k07', 1.00),
            ('k08', 1.00),
            ('k09', 1.00),
            ('k10', 1.00),
            ('k11', 1.00),  # Will be ignored.
        ],
    }
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = StubObj({}, {})
    eng = DummyEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data['keywords_prediction'] == {
        'keywords': [
            {'label': 'k01', 'score': 1.00, 'accept': True},
            {'label': 'k02', 'score': 1.00, 'accept': True},
            {'label': 'k03', 'score': 1.00, 'accept': True},
            {'label': 'k04', 'score': 1.00, 'accept': True},
            {'label': 'k05', 'score': 1.00, 'accept': True},
            {'label': 'k06', 'score': 1.00, 'accept': True},
            {'label': 'k07', 'score': 1.00, 'accept': True},
            {'label': 'k08', 'score': 1.00, 'accept': True},
            {'label': 'k09', 'score': 1.00, 'accept': True},
            {'label': 'k10', 'score': 1.00, 'accept': True},
        ],
    }
def test_guess_keywords_considers_only_first_ten(j_a_r, g_m_u):
    j_a_r.return_value = {
        'labels': [
            ('k01', 1.00),
            ('k02', 1.00),
            ('k03', 1.00),
            ('k04', 1.00),
            ('k05', 1.00),
            ('k06', 1.00),
            ('k07', 1.00),
            ('k08', 1.00),
            ('k09', 1.00),
            ('k10', 1.00),
            ('k11', 1.00),  # Will be ignored.
        ],
    }
    g_m_u.return_value = 'https://magpie.inspirehep.net/predict'

    obj = StubObj({}, {})
    eng = DummyEng()

    assert guess_keywords(obj, eng) is None
    assert obj.extra_data['keywords_prediction'] == {
        'keywords': [
            {'label': 'k01', 'score': 1.00, 'accept': True},
            {'label': 'k02', 'score': 1.00, 'accept': True},
            {'label': 'k03', 'score': 1.00, 'accept': True},
            {'label': 'k04', 'score': 1.00, 'accept': True},
            {'label': 'k05', 'score': 1.00, 'accept': True},
            {'label': 'k06', 'score': 1.00, 'accept': True},
            {'label': 'k07', 'score': 1.00, 'accept': True},
            {'label': 'k08', 'score': 1.00, 'accept': True},
            {'label': 'k09', 'score': 1.00, 'accept': True},
            {'label': 'k10', 'score': 1.00, 'accept': True},
        ],
    }