Esempio n. 1
0
def test_target_load_02(mocker):
    '''Loading targets works.'''
    mocker.patch('grizzly.target.TARGETS', None)

    class _FakeEntryPoint1(object):
        name = 'test1'

        @staticmethod
        def load():
            return _FakeTarget1

    class _FakeEntryPoint2(object):
        name = 'test2'

        @staticmethod
        def load():
            return _FakeTarget2

    mocker.patch('grizzly.target.iter_entry_points', lambda _: [_FakeEntryPoint1, _FakeEntryPoint2])
    assert set(available()) == {'test1', 'test2'}
    assert load('test1') is _FakeTarget1
    assert load('test2') is _FakeTarget2
Esempio n. 2
0
def test_target_load_05(mocker):
    '''test load() with broken Target'''
    mocker.patch('grizzly.target.TARGETS', None)

    class _FakeEntryPoint1(object):
        name = 'test1'

        @staticmethod
        def load():
            return Target

    class _FakeEntryPoint2(object):
        name = 'test2'

        @staticmethod
        def load():
            raise Exception("boo!")

    mocker.patch('grizzly.target.iter_entry_points', lambda _: [_FakeEntryPoint1, _FakeEntryPoint2])
    assert set(available()) == {'test1'}
    assert load('test1') is Target
Esempio n. 3
0
def test_target_load_03(mocker):
    '''Non-Target will be skipped.'''
    mocker.patch('grizzly.target.TARGETS', None)

    class _FakeEntryPoint1(object):
        name = 'test1'

        @staticmethod
        def load():
            return Target

    class _FakeEntryPoint2(object):
        name = 'test2'

        @staticmethod
        def load():
            return object

    mocker.patch('grizzly.target.iter_entry_points', lambda _: [_FakeEntryPoint1, _FakeEntryPoint2])
    assert set(available()) == {'test1'}
    assert load('test1') is Target