示例#1
0
def test_application_spec_from_yaml():
    spec = ApplicationSpec.from_yaml(app_spec)
    assert isinstance(spec, ApplicationSpec)

    assert spec.name == 'test'
    assert spec.queue == 'default'
    assert spec.tags == {'tag1', 'tag2'}
    assert spec.max_attempts == 2
    assert isinstance(spec.services, dict)
    assert isinstance(spec.services['service_1'], Service)
示例#2
0
def test_application_spec_from_any(tmpdir):
    spec = ApplicationSpec.from_yaml(app_spec)
    spec_path = os.path.join(str(tmpdir), 'test.yaml')
    spec.to_file(spec_path)
    spec_dict = spec.to_dict()

    for obj in [spec, spec_path, spec_dict]:
        spec2 = ApplicationSpec._from_any(obj)
        assert spec == spec2

    with pytest.raises(TypeError):
        ApplicationSpec._from_any(None)
示例#3
0
def test_application_spec_from_yaml():
    spec = ApplicationSpec.from_yaml(app_spec)
    assert isinstance(spec, ApplicationSpec)

    assert spec.name == 'test'
    assert spec.queue == 'default'
    assert spec.node_label == 'cpu'
    assert spec.tags == {'tag1', 'tag2'}
    assert spec.file_systems == ['hdfs://preprod']
    assert spec.max_attempts == 2
    assert spec.acls.enable
    assert spec.acls.view_users == ['*']
    assert isinstance(spec.services, dict)
    assert isinstance(spec.services['service_1'], Service)
示例#4
0
def test_to_file_from_file(tmpdir):
    spec = ApplicationSpec.from_yaml(app_spec)

    for name, format in [('test.yaml', 'infer'), ('test.json', 'infer'),
                         ('test2.yaml', 'json')]:
        path = os.path.join(str(tmpdir), name)
        assert not os.path.exists(path)
        spec.to_file(path, format=format)
        assert os.path.exists(path)
        spec2 = ApplicationSpec.from_file(path, format=format)
        assert spec == spec2

    for name, format in [('bad.yaml', 'invalid'), ('bad.invalid', 'infer')]:
        path = os.path.join(str(tmpdir), name)
        with pytest.raises(ValueError):
            spec.to_file(path, format=format)
        assert not os.path.exists(path)
示例#5
0
def test_application_spec_roundtrip():
    spec = ApplicationSpec.from_yaml(app_spec)
    spec2 = ApplicationSpec.from_yaml(spec.to_yaml())
    assert spec == spec2