Exemplo n.º 1
0
def test_storage_broken():
    def imp(module):
        if module == 'loda.storage.engines.locmem':
            from loda.storage.engines import locmem
            return locmem

        if module == 'foo':
            class Klass(object):
                def __init__(self, *args, **kwargs):
                    raise Exception('Foo')

            class Module(object):
                def __init__(self):
                    self.bar = Klass()

            return Module()

        pytest.fail('Untested module import \'%s\'' % module)

    with pytest.raises(ProgrammingError) as ctx:
        with patch('importlib.import_module', imp):
            Script(
                {
                    'storage': 'foo.bar'
                }
            )

    assert ctx.value.args[0] == 'Error loading \'foo.bar\' storage engine.'
Exemplo n.º 2
0
def test_action_not_dict():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'foo': None
            }
        )

    assert ctx.value.args[0] == 'stage config must be a dict or list.'
Exemplo n.º 3
0
def test_stages_not_list():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'stages': 'foo'
            }
        )

    assert ctx.value.args[0] == 'stages must be a list.'
Exemplo n.º 4
0
def test_storage_bad_string():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'storage': ['foo.bar']
            }
        )

    assert ctx.value.args[0] == 'storage must be a string.'
Exemplo n.º 5
0
def test_actors_not_list():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'actors': 'foo.bar'
            }
        )

    assert ctx.value.args[0] == 'actors must be a list.'
Exemplo n.º 6
0
def test_actor_not_found():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'actors': ['foo.bar']
            }
        )

    assert ctx.value.args[0] == 'Actor \'foo.bar\' not found.'
Exemplo n.º 7
0
def test_greedy_actor():
    script = Script({
        'actors': ['tests.greedy'],
        'default': [{
            'line': 'perform'
        }]
    })

    script.run()
Exemplo n.º 8
0
def test_exclude_tags_invalid():
    with pytest.raises(ConfigError) as ctx:
        Script({
            'actors': ['tests.generator'],
            'default': {
                'exclude_tags': False,
                'lines': ['generate']
            }
        })

    assert ctx.value.args[0] == 'exclude_tags must be a string or list.'
Exemplo n.º 9
0
def test_storage_not_found():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'storage': 'foo.bar'
            }
        )

    assert ctx.value.args[0] == (
        'Storage engine module \'foo\' not found.'
    )
Exemplo n.º 10
0
def test_tags_false():
    script = Script({
        'actors': ['tests.generator'],
        'default': {
            'tags': 'performed',
            'lines': ['generate']
        }
    })

    script.run()
    bucket = script.storage.bucket('tests.actors.generator')
    assert bucket.get('counter') is None
Exemplo n.º 11
0
def test_tags_true():
    script = Script({
        'actors': ['tests.greedy', 'tests.generator'],
        'perform': ['perform'],
        'generate': {
            'tags': 'performed',
            'lines': ['generate']
        }
    })

    script.run()
    bucket = script.storage.bucket('tests.actors.generator')
    assert bucket.get('counter') == 5
Exemplo n.º 12
0
def test_each_invalid():
    script = Script({
        'actors': ['tests.generator', 'tests.logic'],
        'default': [{
            'line': 'generate',
            'each': '$loop'
        }]
    })

    def err(ex):
        raise ex

    with pytest.raises(ScriptError):
        script.run()
Exemplo n.º 13
0
def test_action_not_in_stage():
    with pytest.raises(ConfigError) as ctx:
        Script(
            {
                'foo': {
                    'stage': 'foo'
                }
            }
        )

    assert ctx.value.args[0] == (
        'Action \'foo\' will not run as it does not belong to any defined '
        'stage.'
    )
Exemplo n.º 14
0
def test_each_break():
    script = Script({
        'actors': ['tests.generator', 'tests.logic'],
        '$loop': ['increment foo', 'break'],
        'default': [{
            'line': 'generate',
            'each': '$loop'
        }]
    })

    def err(ex):
        raise ex

    script.on('line.error', err)
    script.run()

    assert script.context['counter'] == 1
    bucket = script.storage.bucket('tests.actors.logic')
    assert bucket.get('foo') == 1
Exemplo n.º 15
0
def test_each_set():
    script = Script({
        'actors': ['tests.generator', 'tests.logic'],
        '$loop': ['set foo = {{ number }}'],
        'default': [{
            'line': 'generate',
            'each': '$loop'
        }]
    })

    def err(ex):
        raise ex

    script.on('line.error', err)
    script.run()

    assert script.context['counter'] == 5
    bucket = script.storage.bucket('tests.actors.logic')
    assert bucket.get('foo') == '5'
Exemplo n.º 16
0
def test_unless():
    script = Script({
        'actors': ['tests.generator', 'tests.logic'],
        'default':
        ['generate', {
            'line': 'set foo = bar',
            'unless': 'counter == 5'
        }]
    })

    def err(ex):
        raise ex

    script.on('line.error', err)
    script.run()

    assert script.context['counter'] == 5
    bucket = script.storage.bucket('tests.actors.logic')
    assert bucket.get('foo') is None
Exemplo n.º 17
0
def test_actor_class_not_found():
    def imp(module):
        if module == 'loda.storage.engines.locmem':
            from loda.storage.engines import locmem
            return locmem

        if module == 'foo.actors.bar':
            class Module(object):
                pass

            return Module()

        pytest.fail('Untested module import \'%s\'' % module)

    with pytest.raises(ProgrammingError) as ctx:
        with patch('importlib.import_module', imp):
            Script(
                {
                    'actors': ['foo.bar']
                }
            )

    assert ctx.value.args[0] == 'Actor class not found.'
Exemplo n.º 18
0
def test_storage_class_not_found():
    def imp(module):
        if module == 'loda.storage.engines.locmem':
            from loda.storage.engines import locmem
            return locmem

        if module == 'foo':
            class Module(object):
                pass

            return Module()

        pytest.fail('Untested module import \'%s\'' % module)

    with pytest.raises(ConfigError) as ctx:
        with patch('importlib.import_module', imp):
            Script(
                {
                    'storage': 'foo.bar'
                }
            )

    assert ctx.value.args[0] == 'Storage engine class \'bar\' not found.'
Exemplo n.º 19
0
def test_dry_run():
    filename = os.path.join(
        os.path.dirname(
            os.path.dirname(__file__)
        ),
        'fixtures',
        'test_items.yaml'
    )

    script = Script(
        {
            'actors': [
                'loda.inoreader',
                'loda.twitter'
            ],
            'builtin': [
                'hold foo for 1 minute',
                'release foo',
                'pick 1 from items',
                'pick 1 from items at random'
            ],
            'rss': [
                'get latest articles in starred folder'
            ],
            'twitter': [
                'follow @jack',
                'follow #podcasters',
                'find tweets from:jack',
                'tweet "hello Jack"',
                'rt 12345'
            ]
        }
    )

    script.fixtures.add('items', filename)
    script.dry_run = True
    script.run()
Exemplo n.º 20
0
def test_generator_type():
    script = Script({'actors': ['tests.generator'], 'default': ['generate']})

    script.run()
    bucket = script.storage.bucket('tests.actors.generator')
    assert bucket.get('counter') == 5
Exemplo n.º 21
0
def test_config_not_dict():
    with pytest.raises(ConfigError) as ctx:
        Script([])

    assert ctx.value.args[0] == 'Config must be a dict.'
Exemplo n.º 22
0
def test_if_invalid():
    with pytest.raises(ConfigError) as ctx:
        Script({'default': [{'line': 'do', 'if': True}]})

    assert ctx.value.args[0] == 'if conditions must be a string or list.'
Exemplo n.º 23
0
def test_extra_config():
    with pytest.raises(ConfigError) as ctx:
        Script({'default': [{'line': 'do', 'foo': 'bar'}]})

    assert ctx.value.args[0] == 'Line configruation invalid.'