Exemplo n.º 1
0
def test_repository_snap_all_props():
    @solid
    def noop_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        noop_solid()

    @repository
    def noop_repo():
        return [noop_pipeline]

    external_repo_data = external_repository_data_from_def(noop_repo)

    assert external_repo_data.name == 'noop_repo'
    assert len(external_repo_data.external_pipeline_datas) == 1
    assert isinstance(external_repo_data.external_pipeline_datas[0], ExternalPipelineData)

    pipeline_snapshot = external_repo_data.external_pipeline_datas[
        0
    ].pipeline_snapshot_with_id.pipeline_snapshot
    assert isinstance(pipeline_snapshot, PipelineSnapshot)
    assert pipeline_snapshot.name == 'noop_pipeline'
    assert pipeline_snapshot.description is None
    assert pipeline_snapshot.tags == {}
Exemplo n.º 2
0
def test_repository_snap_empty():
    @repository
    def empty_repo():
        return []

    external_repo_data = external_repository_data_from_def(empty_repo)
    assert external_repo_data.name == 'empty_repo'
    assert len(external_repo_data.external_pipeline_datas) == 0
Exemplo n.º 3
0
def test_external_repository_data(snapshot):
    @repository
    def repo():
        return [a_pipeline, a_schedule]

    external_repo_data = external_repository_data_from_def(repo)
    assert external_repo_data.get_external_pipeline_data('a_pipeline')
    assert external_repo_data.get_external_schedule_data('a_schedule')
    assert external_repo_data.get_external_partition_set_data(
        'a_schedule_partitions')
    snapshot.assert_match(serialize_pp(external_repo_data))
Exemplo n.º 4
0
    def test_out_of_process_reload_location(self, graphql_context):
        result = execute_dagster_graphql(graphql_context,
                                         RELOAD_REPOSITORY_LOCATION_QUERY,
                                         {'repositoryLocationName': 'test'})

        assert result
        assert result.data
        assert result.data['reloadRepositoryLocation']
        assert result.data['reloadRepositoryLocation'][
            '__typename'] == 'RepositoryLocation'
        assert result.data['reloadRepositoryLocation']['name'] == 'test'
        assert result.data['reloadRepositoryLocation']['repositories'] == [{
            'name':
            'test_repo'
        }]
        assert result.data['reloadRepositoryLocation'][
            'isReloadSupported'] is True

        with mock.patch(
                # note it where the function is *used* that needs to mocked, not
                # where it is defined.
                # see https://docs.python.org/3/library/unittest.mock.html#where-to-patch
                'dagster.api.snapshot_repository.execute_unary_api_cli_command'
        ) as cli_command_mock:

            @repository
            def new_repo():
                return []

            new_repo_data = external_repository_data_from_def(new_repo)

            cli_command_mock.return_value = new_repo_data

            result = execute_dagster_graphql(
                graphql_context,
                RELOAD_REPOSITORY_LOCATION_QUERY,
                {'repositoryLocationName': 'test'},
            )

            assert cli_command_mock.call_count == 1

            assert result.data['reloadRepositoryLocation']['repositories'] == [
                {
                    'name': 'new_repo'
                }
            ]
Exemplo n.º 5
0
def test_repository_snap_all_props():
    @solid
    def noop_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        noop_solid()

    repo = RepositoryDefinition(name='noop_repo',
                                pipeline_defs=[noop_pipeline])
    external_repo_data = external_repository_data_from_def(repo)

    assert external_repo_data.name == 'noop_repo'
    assert len(external_repo_data.external_pipeline_datas) == 1
    assert isinstance(external_repo_data.external_pipeline_datas[0],
                      ExternalPipelineData)

    pipeline_snapshot = external_repo_data.external_pipeline_datas[
        0].pipeline_snapshot
    assert isinstance(pipeline_snapshot, PipelineSnapshot)
    assert pipeline_snapshot.name == 'noop_pipeline'
    assert pipeline_snapshot.description is None
    assert pipeline_snapshot.tags == {}
    def test_out_of_process_reload_location(self, graphql_context):
        result = execute_dagster_graphql(graphql_context,
                                         RELOAD_REPOSITORY_LOCATION_QUERY,
                                         {"repositoryLocationName": "test"})

        assert result
        assert result.data
        assert result.data["reloadRepositoryLocation"]
        assert result.data["reloadRepositoryLocation"][
            "__typename"] == "RepositoryLocation"
        assert result.data["reloadRepositoryLocation"]["name"] == "test"
        assert result.data["reloadRepositoryLocation"]["repositories"] == [{
            "name":
            "test_repo"
        }]
        assert result.data["reloadRepositoryLocation"][
            "isReloadSupported"] is True

        with mock.patch(
                # note it where the function is *used* that needs to mocked, not
                # where it is defined.
                # see https://docs.python.org/3/library/unittest.mock.html#where-to-patch
                "dagster.core.host_representation.handle.sync_list_repositories_grpc"
        ) as cli_command_mock:

            with mock.patch(
                    # note it where the function is *used* that needs to mocked, not
                    # where it is defined.
                    # see https://docs.python.org/3/library/unittest.mock.html#where-to-patch
                    "dagster.core.host_representation.repository_location.sync_get_streaming_external_repositories_grpc"
            ) as external_repository_mock:

                @repository
                def new_repo():
                    return []

                new_repo_data = external_repository_data_from_def(new_repo)

                external_repository_mock.return_value = [
                    ExternalRepository(
                        new_repo_data,
                        RepositoryHandle(
                            "new_repo", graphql_context.
                            repository_locations[0].location_handle),
                    )
                ]

                cli_command_mock.return_value = ListRepositoriesResponse(
                    repository_symbols=[],
                    executable_path=sys.executable,
                    repository_code_pointer_dict={
                        "new_repo":
                        CodePointer.from_python_file(__file__, "new_repo",
                                                     None)
                    },
                )

                result = execute_dagster_graphql(
                    graphql_context,
                    RELOAD_REPOSITORY_LOCATION_QUERY,
                    {"repositoryLocationName": "test"},
                )

                assert cli_command_mock.call_count == 1
                assert external_repository_mock.call_count == 1

                assert result.data["reloadRepositoryLocation"][
                    "repositories"] == [{
                        "name": "new_repo"
                    }]
Exemplo n.º 7
0
def repository_snapshot_command(repository_python_origin):

    recon_repo = recon_repository_from_origin(repository_python_origin)
    return external_repository_data_from_def(recon_repo.get_definition())
Exemplo n.º 8
0
def test_repository_snap_empty():
    repo = RepositoryDefinition(name='empty_repo', pipeline_defs=[])
    external_repo_data = external_repository_data_from_def(repo)
    assert external_repo_data.name == 'empty_repo'
    assert len(external_repo_data.external_pipeline_datas) == 0
Exemplo n.º 9
0
def repository_snapshot_command(output_file, **kwargs):
    recon_repo = recon_repo_for_cli_args(kwargs)
    definition = recon_repo.get_definition()
    ipc_write_unary_response(output_file,
                             external_repository_data_from_def(definition))
Exemplo n.º 10
0
def repository_snapshot_command(**kwargs):
    recon_repo = recon_repo_for_cli_args(kwargs)
    definition = recon_repo.get_definition()

    active_data = external_repository_data_from_def(definition)
    click.echo(serialize_dagster_namedtuple(active_data))
Exemplo n.º 11
0
def test_external_repository_data(snapshot):
    rep_def = RepositoryDefinition(name='repo', pipeline_defs=[a_pipeline])
    snapshot.assert_match(serialize_pp(external_repository_data_from_def(rep_def)))
Exemplo n.º 12
0
def mock_external_repository_data():
    external_repo_data = external_repository_data_from_def(noop_repo())
    return serialize_dagster_namedtuple(external_repo_data)