示例#1
0
def test_dup_names():
    """Make sure that variable name and headers are unique across a table config"""
    with pytest.raises(ValueError) as excinfo:
        TableConfig(name="foo",
                    description="bar",
                    datasets=[],
                    rows=[],
                    columns=[],
                    variables=[
                        RootInfo(name="foo",
                                 headers=["foo", "bar"],
                                 field="name"),
                        RootInfo(name="foo",
                                 headers=["foo", "baz"],
                                 field="name")
                    ])
    assert "Multiple" in str(excinfo.value)
    assert "foo" in str(excinfo.value)

    with pytest.raises(ValueError) as excinfo:
        TableConfig(name="foo",
                    description="bar",
                    datasets=[],
                    rows=[],
                    columns=[],
                    variables=[
                        RootInfo(name="foo",
                                 headers=["spam", "eggs"],
                                 field="name"),
                        RootInfo(name="bar",
                                 headers=["spam", "eggs"],
                                 field="name")
                    ])
    assert "Multiple" in str(excinfo.value)
    assert "spam" in str(excinfo.value)
示例#2
0
def test_register_existing(collection, session):
    """Test the behavior of AraDefinitionCollection.register() on a registered AraDefinition"""
    # Given
    project_id = '6b608f78-e341-422c-8076-35adc8828545'
    # table_config = TableConfigResponseDataFactory()
    # config_uid = table_config["definition_id"]

    table_config = TableConfig(name="name", description="description", datasets=[], rows=[], variables=[], columns=[],
                                   definition_uid = UUID('6b608f78-e341-422c-8076-35adc8828545'))

    table_config_response = TableConfigResponseDataFactory()
    defn_uid = table_config_response["definition"]["id"]
    ver_uid = table_config_response["version"]["id"]
    session.set_response(table_config_response)

    # When
    registered = collection.register(table_config)

    assert registered.definition_uid == UUID(defn_uid)
    assert registered.version_uid == UUID(ver_uid)
    assert session.num_calls == 1

    # Ensure we PUT if we were called with a table config id
    assert session.last_call.method == "PUT"
    assert session.last_call.path == "projects/{}/ara-definitions/6b608f78-e341-422c-8076-35adc8828545".format(project_id)
示例#3
0
def empty_defn() -> TableConfig:
    return TableConfig(name="empty",
                       description="empty",
                       datasets=[],
                       rows=[],
                       variables=[],
                       columns=[],
                       config_uid=UUID("6b608f78-e341-422c-8076-35adc8828545"))
示例#4
0
def test_default_for_material(collection: AraDefinitionCollection, session):
    """Test that default for material hits the right route"""
    # Given
    project_id = '6b608f78-e341-422c-8076-35adc8828545'
    dummy_resp = {
        'config': TableConfig(
            name='foo',
            description='foo',
            variables=[],
            columns=[],
            rows=[],
            datasets=[]
        ).dump(),
        'ambiguous': [
            [
                RootIdentifier(name='foo', headers=['foo'], scope='id').dump(),
                IdentityColumn(data_source='foo').dump(),
            ]
        ],
    }
    session.responses.append(dummy_resp)
    collection.default_for_material(
        material='my_id',
        scope='my_scope',
        name='my_name',
        description='my_description',
    )

    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'my_id',
            'scope': 'my_scope',
            'name': 'my_name',
            'description': 'my_description'
        }
    )
    session.calls.clear()
    session.responses.append(dummy_resp)
    collection.default_for_material(
        material=MaterialRun('foo', uids={'scope': 'id'}),
        scope='ignored',
        name='my_name',
        description='my_description',
    )
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'id',
            'scope': 'scope',
            'name': 'my_name',
            'description': 'my_description'
        }
    )
示例#5
0
def test_build_from_config_failures(collection: GemTableCollection, session):
    with pytest.raises(ValueError):
        collection.build_from_config(uuid4())
    config = TableConfig(name='foo',
                         description='bar',
                         columns=[],
                         rows=[],
                         variables=[],
                         datasets=[],
                         definition_uid=uuid4())
    with pytest.raises(ValueError):
        collection.build_from_config(config)
    config.version_number = 1
    config.config_uid = None
    with pytest.raises(ValueError):
        collection.build_from_config(config)
    config.config_uid = uuid4()
    session.set_responses(
        {'job_id': '12345678-1234-1234-1234-123456789ccc'},
        {
            'job_type':
            'foo',
            'status':
            'Failure',
            'tasks': [{
                'task_type': 'foo',
                'id': 'foo',
                'status': 'Failure',
                'failure_reason': 'because',
                'dependencies': []
            }]
        },
    )
    with pytest.raises(JobFailureError):
        collection.build_from_config(uuid4(), version=1)
    session.set_responses(
        {'job_id': '12345678-1234-1234-1234-123456789ccc'},
        {
            'job_type': 'foo',
            'status': 'In Progress',
            'tasks': []
        },
    )
    with pytest.raises(PollingTimeoutError):
        collection.build_from_config(config, timeout=0)
示例#6
0
def test_init_table_config():
    table_config = TableConfig(name="foo",
                               description="bar",
                               rows=[],
                               columns=[],
                               variables=[],
                               datasets=[])
    assert table_config.config_uid is None
    assert table_config.version_number is None
示例#7
0
def test_update_unregistered_fail(collection, session):
    """Test that AraDefinitionCollection.update() fails on an unregistered AraDefinition"""

    # Given

    table_config = TableConfig(name="name", description="description", datasets=[], rows=[], variables=[], columns=[],
                                   definition_uid = None)

    # When
    with pytest.raises(ValueError, match="Cannot update Table Config without a config_uid."):
        collection.update(table_config)
示例#8
0
def test_missing_variable():
    """Make sure that every data_source matches a name of a variable"""
    with pytest.raises(ValueError) as excinfo:
        TableConfig(
            name="foo", description="bar", datasets=[], rows=[], variables=[],
            columns=[
                MeanColumn(data_source="density")
            ]
        )
    assert "must match" in str(excinfo.value)
    assert "density" in str(excinfo.value)
示例#9
0
def test_init_table_config_with_new_config_uid():
    uid = UUID('6b608f78-e341-422c-8076-35adc8828566')
    table_config = TableConfig(name="foo",
                               description="bar",
                               rows=[],
                               columns=[],
                               variables=[],
                               datasets=[],
                               config_uid=uid)
    assert table_config.config_uid == uid
    assert table_config.definition_uid == uid
示例#10
0
def test_dump_example():
    density = AttributeByTemplate(
        name="density",
        headers=["Slice", "Density"],
        template=LinkByUID(scope="templates", id="density")
    )
    table_config = TableConfig(
        name="Example Table",
        description="Illustrative example that's meant to show how Table Configs will look serialized",
        datasets=[uuid4()],
        variables=[density],
        rows=[MaterialRunByTemplate(templates=[LinkByUID(scope="templates", id="slices")])],
        columns=[
            MeanColumn(data_source=density.name),
            StdDevColumn(data_source=density.name),
            OriginalUnitsColumn(data_source=density.name),
        ]
    )
示例#11
0
def test_build_from_config(collection: GemTableCollection, session):
    config_uid = uuid4()
    config_version = 2
    config = TableConfig(
        name='foo',
        description='bar',
        columns=[],
        rows=[],
        variables=[],
        datasets=[],
        definition_uid=config_uid,
        version_number=config_version,
    )
    expected_table_data = GemTableDataFactory()
    session.set_responses(
        {'job_id': '12345678-1234-1234-1234-123456789ccc'},
        {
            'job_type': 'foo',
            'status': 'In Progress',
            'tasks': []
        },
        {
            'job_type': 'foo',
            'status': 'Success',
            'tasks': [],
            'output': {
                'display_table_id':
                expected_table_data['id'],
                'display_table_version':
                str(expected_table_data['version']),
                'table_warnings':
                json.dumps([
                    {
                        'limited_results': ['foo', 'bar'],
                        'total_count': 3
                    },
                ])
            }
        },
        expected_table_data,
    )
    gem_table = collection.build_from_config(config, version='ignored')
    assert isinstance(gem_table, GemTable)
    assert session.num_calls == 4
示例#12
0
def AraDefinition(*args, **kwargs):
    """[DEPRECATED] Use TableConfig instead."""
    warn(
        "AraDefinition is deprecated and will soon be removed. "
        "Please use TableConfig instead", DeprecationWarning)
    return TableConfig(*args, **kwargs)
示例#13
0
 def _table_config():
     return TableConfig.build(TableConfigResponseDataFactory())
示例#14
0
def test_default_for_material(collection: TableConfigCollection, session):
    """Test that default for material hits the right route"""
    # Given
    project_id = '6b608f78-e341-422c-8076-35adc8828545'
    dummy_resp = {
        'config':
        TableConfig(name='foo',
                    description='foo',
                    variables=[],
                    columns=[],
                    rows=[],
                    datasets=[]).dump(),
        'ambiguous': [[
            RootIdentifier(name='foo', headers=['foo'], scope='id').dump(),
            IdentityColumn(data_source='foo').dump(),
        ]],
    }
    # Specify by Citrine ID
    session.responses.append(dummy_resp)
    collection.default_for_material(
        material='my_id',
        name='my_name',
        description='my_description',
    )
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'my_id',
            'scope': CITRINE_SCOPE,
            'name': 'my_name',
            'description': 'my_description'
        })
    # Specify by id with custom scope, throwing a warning
    session.calls.clear()
    session.responses.append(dummy_resp)
    with warnings.catch_warnings(record=True) as caught:
        collection.default_for_material(material='my_id',
                                        scope='my_scope',
                                        name='my_name',
                                        description='my_description')
        assert len(caught) == 1
        assert issubclass(caught[0].category, DeprecationWarning)
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'my_id',
            'scope': 'my_scope',
            'name': 'my_name',
            'description': 'my_description'
        })
    # Specify by MaterialRun
    session.calls.clear()
    session.responses.append(dummy_resp)
    collection.default_for_material(material=MaterialRun('foo',
                                                         uids={'scope': 'id'}),
                                    name='my_name',
                                    description='my_description',
                                    algorithm=TableBuildAlgorithm.FORMULATIONS)
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'id',
            'scope': 'scope',
            'name': 'my_name',
            'description': 'my_description',
            'algorithm': TableBuildAlgorithm.FORMULATIONS.value
        })
    # Specify by LinkByUID
    session.calls.clear()
    session.responses.append(dummy_resp)
    collection.default_for_material(
        material=LinkByUID(scope="scope", id="id"),
        name='my_name',
        description='my_description',
    )
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'id',
            'scope': 'scope',
            'name': 'my_name',
            'description': 'my_description'
        })

    # And we allowed for the more forgiving call structure, so test it.
    session.calls.clear()
    session.responses.append(dummy_resp)
    collection.default_for_material(
        material=MaterialRun('foo', uids={'scope': 'id'}),
        scope='ignored',
        algorithm=TableBuildAlgorithm.FORMULATIONS.value,
        name='my_name',
        description='my_description',
    )
    assert 1 == session.num_calls
    assert session.last_call == FakeCall(
        method="GET",
        path="projects/{}/table-configs/default".format(project_id),
        params={
            'id': 'id',
            'scope': 'scope',
            'algorithm': TableBuildAlgorithm.FORMULATIONS.value,
            'name': 'my_name',
            'description': 'my_description'
        })