Esempio n. 1
0
def test_side_effects_list(mock):
    mock.side_effect = [{1: 'a'}, {2: 'a'}, {3: 'a'}, {4: 'a'}]

    assert crazy.use_some_crazy_stuff(1) == {1: 'a'}
    assert crazy.use_some_crazy_stuff(1) == {2: 'a'}
    assert crazy.use_some_crazy_stuff(1) == {3: 'a'}
    assert crazy.use_some_crazy_stuff(1) == {4: 'a'}
Esempio n. 2
0
def test_mock_requests(mock_get):
    d = {'biz': 'baz'}
    response = MagicMock()
    response.json.return_value = d
    mock_get.return_value = response

    assert crazy.use_some_crazy_stuff(1) == d
Esempio n. 3
0
def test_side_effects(mock):
    mock.side_effect = lambda val: {val: 'a'}

    assert crazy.use_some_crazy_stuff(1) == {1: 'a'}
    assert crazy.use_some_crazy_stuff(2) == {2: 'a'}
    assert crazy.use_some_crazy_stuff('pie') == {'pie': 'a'}
Esempio n. 4
0
def test_use_crazy_stuff_1(mock):
    d = {'foo': 'bar'}
    mock.return_value = d

    assert crazy.use_some_crazy_stuff(1) == d
Esempio n. 5
0
def test_do_something_with_monkeypatch(monkeypatch):
    monkeypatch.setattr(crazy, 'do_some_crazy_stuff', lambda val: {val: 'a'})
    assert crazy.use_some_crazy_stuff(1) == {1: 'a'}
    assert crazy.use_some_crazy_stuff(2) == {2: 'a'}
    assert crazy.use_some_crazy_stuff(3) == {3: 'a'}