Exemple #1
0
def test_has_getter(number, json, monkeypatch):
    getters = {}
    monkeypatch.setattr('oeispy.getters.GETTERS', getters)
    seq = oeis.A(number, json)
    assert seq.has_getter is False
    getters[number] = lambda x: None
    seq = oeis.A(number, json)
    assert seq.has_getter is True
Exemple #2
0
def test_has_generator(number, json, monkeypatch):
    generators = {}
    monkeypatch.setattr('oeispy.generators.GENERATORS', generators)
    seq = oeis.A(number, json)
    assert seq.has_generator is False
    generators[number] = lambda: None
    seq = oeis.A(number, json)
    assert seq.has_generator is True
Exemple #3
0
def test_iter_with_generator(number, json, monkeypatch):
    expected = (a for a in range(0))
    generators = {number: lambda: expected}
    monkeypatch.setattr('oeispy.generators.GENERATORS', generators)
    seq = oeis.A(number, json)
    output = iter(seq)
    assert output == expected
Exemple #4
0
def test_retrievable(number, json, monkeypatch):
    generators = {}
    getters = {}
    monkeypatch.setattr('oeispy.generators.GENERATORS', generators)
    monkeypatch.setattr('oeispy.getters.GETTERS', getters)
    seq = oeis.A(number, json)
    assert seq.retrievable is False
    generators[number] = lambda x: None
    seq = oeis.A(number, json)
    assert seq.retrievable is True
    del generators[number]
    seq = oeis.A(number, json)
    assert seq.retrievable is False
    getters[number] = lambda: None
    seq = oeis.A(number, json)
    assert seq.retrievable is True
Exemple #5
0
def test_getitem_less_than_offset(number, json, monkeypatch):
    getter = mock.Mock()
    monkeypatch.setattr('oeispy.getters.GETTERS', {number: getter})
    seq = oeis.A(number, json)
    assert seq._get is getter
    with pytest.raises(IndexError):
        _ = seq[seq.offset - 1]
Exemple #6
0
def test_init_without_json(number, json, monkeypatch):
    rq_get = mock.Mock()
    rq_get.return_value.json.return_value = {'results': [json]}
    monkeypatch.setattr('requests.get', rq_get)
    seq = oeis.A(number)
    assert seq.entry == json
    assert seq.number == number
    rq_get.assert_called_once_with(oeis.URI_FORMAT.format(number=number))
    rq_get.return_value.json.assert_called_once()
Exemple #7
0
def test_iter_no_generator(number, json, monkeypatch):
    generators = {}
    monkeypatch.setattr('oeispy.generators.GENERATORS', generators)
    seq = oeis.A(number, json)
    with pytest.raises(NotImplementedError):
        iter(seq)
Exemple #8
0
def test_init_with_json_given(number, json):
    seq = oeis.A(number, json)
    assert seq.entry == json
    assert seq.number == number
Exemple #9
0
def test_getitem_gets_from_data(number, json, monkeypatch):
    monkeypatch.setattr('oeispy.getters.GETTERS', {})
    seq = oeis.A(number, json)
    seq.data = mock.MagicMock()
    seq.data.__len__.return_value = 1
    assert seq[seq.offset] == seq.data[0]
Exemple #10
0
def test_get_succeeds(number, json, monkeypatch):
    getter = mock.Mock()
    monkeypatch.setattr('oeispy.getters.GETTERS', {number: getter})
    seq = oeis.A(number, json)
    assert seq._get is getter
    assert seq.get(seq.offset) == getter.return_value
Exemple #11
0
def seq(request):
    return oeis.A(*request.param)
Exemple #12
0
def test_get_no_getter(number, json, monkeypatch):
    monkeypatch.setattr('oeispy.getters.GETTERS', {})
    seq = oeis.A(number, json)
    assert seq._get is None
    with pytest.raises(NotImplementedError):
        seq.get(0)