Beispiel #1
0
def test_greedy_actor():
    script = Script({
        'actors': ['tests.greedy'],
        'default': [{
            'line': 'perform'
        }]
    })

    script.run()
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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()
Beispiel #5
0
def test_bad_file():
    filename = os.path.join(
        os.path.dirname(
            os.path.dirname(__file__)
        ),
        'fixtures',
        'test_settings',
        'empty.yaml'
    )

    with pytest.raises(ConfigError) as ctx:
        Script.from_file(filename)

    assert ctx.value.args[0] == (
        'Script must be a collection of key-value pairs.'
    )
Beispiel #6
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.'
Beispiel #7
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.'
Beispiel #8
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.'
Beispiel #9
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.'
Beispiel #10
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.'
Beispiel #11
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.'
Beispiel #12
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.'
    )
Beispiel #13
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.'
Beispiel #14
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.'
    )
Beispiel #15
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()
Beispiel #16
0
def test_from_file():
    filename = os.path.join(
        os.path.dirname(
            os.path.dirname(__file__)
        ),
        'fixtures',
        'test_settings',
        'script.yaml'
    )

    def err(ex):
        raise ex

    script = Script.from_file(filename)
    script.on('line.error', err)
    script.run()
    bucket = script.storage.bucket('tests.actors.settings')
    assert bucket.get('foo') == 'baz'
Beispiel #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.'
Beispiel #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.'
Beispiel #19
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
Beispiel #20
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
Beispiel #21
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'
Beispiel #22
0
def test_config_not_dict():
    with pytest.raises(ConfigError) as ctx:
        Script([])

    assert ctx.value.args[0] == 'Config must be a dict.'
Beispiel #23
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.'
Beispiel #24
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
Beispiel #25
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.'