Esempio n. 1
0
def test_application_spec_invariants():
    s = Service(commands=['command'],
                resources=Resources(memory=1024, vcores=1))

    # No services
    with pytest.raises(ValueError):
        ApplicationSpec(name='dask', queue='default', services={})

    for k, v in [('name', 1), ('queue', 1), ('tags', 1), ('tags', {1, 2, 3}),
                 ('max_attempts', 'foo')]:
        with pytest.raises(TypeError):
            ApplicationSpec(services={'service': s}, **{k: v})

    with pytest.raises(ValueError):
        ApplicationSpec(max_attempts=0, services={'service': s})

    r = Resources(memory=1024, vcores=1)
    c = ['commands']

    # Unknown dependency name
    with pytest.raises(ValueError):
        ApplicationSpec(
            services={
                'a': s,
                'b': Service(resources=r, commands=c, depends=['c', 'd'])
            })

    # Cyclical dependencies
    with pytest.raises(ValueError):
        ApplicationSpec(
            services={
                'a': Service(resources=r, commands=c, depends=['c']),
                'b': Service(resources=r, commands=c, depends=['a']),
                'c': Service(resources=r, commands=c, depends=['b'])
            })
Esempio n. 2
0
def test_service():
    r = Resources(memory=1024, vcores=1)
    c = ['commands']
    s1 = Service(resources=r, commands=c,
                 files={'file': File(source='/test/path')})
    s2 = Service(resources=r, commands=c,
                 files={'file': File(source='/test/path', size=1024)})
    check_specification_methods(s1, s2)
Esempio n. 3
0
def test_application_spec():
    r = Resources(memory=1024, vcores=1)
    c = ['commands']
    s1 = Service(resources=r, commands=c,
                 files={'file': File(source='/test/path')})
    s2 = Service(resources=r, commands=c,
                 files={'file': File(source='/test/path', size=1024)})
    spec1 = ApplicationSpec(services={'service': s1})
    spec2 = ApplicationSpec(services={'service': s2})
    check_specification_methods(spec1, spec2)
Esempio n. 4
0
def test_service():
    r = Resources(memory=1024, vcores=1)
    s1 = Service(resources=r,
                 script='script',
                 node_label="testlabel",
                 files={'file': File(source='/test/path')},
                 nodes=['worker.example.com'],
                 racks=['rack1', 'rack2'],
                 relax_locality=True)
    s2 = Service(resources=r,
                 script='script',
                 files={'file': File(source='/test/path', size=1024)})
    check_specification_methods(s1, s2)
Esempio n. 5
0
def test_application_spec():
    r = Resources(memory=1024, vcores=1)
    s1 = Service(resources=r, script="script",
                 files={'file': File(source='/test/path')})
    s2 = Service(resources=r, script="script",
                 files={'file': File(source='/test/path', size=1024)})
    spec1 = ApplicationSpec(name='test',
                            queue='testqueue',
                            node_label='testlabel',
                            services={'service': s1})
    spec2 = ApplicationSpec(master=Master(script='script', resources=r))
    spec3 = ApplicationSpec(services={'service': s2})
    check_specification_methods(spec1, spec3)
    check_specification_methods(spec2, spec3)
Esempio n. 6
0
def test_service_invariants():
    r = Resources(memory=1024, vcores=1)
    c = ['command']

    with pytest.raises(TypeError):
        Service()

    # No commands provided
    with pytest.raises(ValueError):
        Service(commands=[], resources=r)

    with pytest.raises(TypeError):
        Service(commands='foo', resources=r)

    with pytest.raises(ValueError):
        Service(commands=c, resources=r, instances=-1)

    with pytest.raises(ValueError):
        Service(commands=c, resources=r, max_restarts=-2)

    with pytest.raises(TypeError):
        Service(commands=c, resources=r, env={'a': 1})

    with pytest.raises(TypeError):
        Service(commands=c, resources=r, depends=[1])

    # Mutable defaults properly set
    s = Service(commands=c, resources=r)
    assert isinstance(s.env, dict)
    assert isinstance(s.files, dict)
    assert isinstance(s.depends, set)

    # Strings are converted to File objects
    s = Service(commands=c,
                resources=r,
                files={
                    'target': '/source.zip',
                    'target2': '/source2.txt'
                })
    assert s.files['target'].type == 'archive'
    assert s.files['target2'].type == 'file'
Esempio n. 7
0
def test_service_commands_deprecated():
    script = ('set -x -e\n'
              'command 1\n'
              'command 2')

    with pytest.warns(UserWarning):
        s = Service(commands=['command 1', 'command 2'],
                    resources=Resources(memory=1024, vcores=1))
    assert s.script == script

    with pytest.warns(UserWarning):
        s = Service.from_dict({'resources': {'memory': 1024,
                                             'vcores': 1},
                               'commands': ['command 1', 'command 2']})
    assert s.script == script
Esempio n. 8
0
def test_service_invariants():
    r = Resources(memory=1024, vcores=1)

    with pytest.raises(TypeError):
        Service()

    # Empty script
    with pytest.raises(ValueError):
        Service(script="", resources=r)

    with pytest.raises(TypeError):
        Service(script=1, resources=r)

    with pytest.raises(ValueError):
        Service(script="script", resources=r, instances=-1)

    with pytest.raises(ValueError):
        Service(script="script", resources=r, max_restarts=-2)

    with pytest.raises(TypeError):
        Service(script="script", resources=r, env={'a': 1})

    with pytest.raises(TypeError):
        Service(script="script", resources=r, depends=[1])

    # Mutable defaults properly set
    s = Service(script="script", resources=r)
    assert isinstance(s.env, dict)
    assert isinstance(s.files, dict)
    assert isinstance(s.depends, set)

    # Strings are converted to File objects
    s = Service(script="script", resources=r,
                files={'target': '/source.zip',
                       'target2': '/source2.txt'})
    assert s.files['target'].type == 'archive'
    assert s.files['target2'].type == 'file'

    # File targets are checked
    with pytest.raises(ValueError):
        Service(script="script", resources=r,
                files={'foo/bar': '/source.zip'})
    # Local relative paths are fine
    Service(script="script", resources=r,
            files={'./bar': '/source.zip'})