示例#1
0
def test_dagit_logs(
    server_mock,
    caplog,
):
    with seven.TemporaryDirectory() as temp_dir:
        with environ({'DAGSTER_HOME': temp_dir}):
            with open(os.path.join(temp_dir, 'dagster.yaml'), 'w') as fd:
                yaml.dump({}, fd, default_flow_style=False)

            DagsterInstance.local_temp(temp_dir)
            runner = CliRunner(env={'DAGSTER_HOME': temp_dir})
            with pushd(path_to_tutorial_file('')):

                result = runner.invoke(
                    ui,
                    [
                        '-w',
                        file_relative_path(__file__,
                                           'telemetry_repository.yaml'),
                    ],
                )
                assert result.exit_code == 0, str(result.exception)

                actions = set()
                for record in caplog.records:
                    message = json.loads(record.getMessage())
                    actions.add(message.get('action'))
                    if message.get('action') == UPDATE_REPO_STATS:
                        assert message.get('pipeline_name_hash') == ''
                        assert message.get('num_pipelines_in_repo') == str(4)
                        assert message.get('repo_hash') == hash_name(
                            'dagster_test_repository')
                    assert set(message.keys()) == set([
                        'action',
                        'client_time',
                        'elapsed_time',
                        'event_id',
                        'instance_id',
                        'pipeline_name_hash',
                        'num_pipelines_in_repo',
                        'repo_hash',
                        'python_version',
                        'metadata',
                        'version',
                    ])

                assert actions == set(
                    [START_DAGIT_WEBSERVER, UPDATE_REPO_STATS])
                assert len(caplog.records) == 2
                assert server_mock.call_args_list == [mock.call()]
示例#2
0
def test_dagit_logs(
    server_mock,
    caplog,
):
    with seven.TemporaryDirectory() as temp_dir:
        with instance_for_test_tempdir(temp_dir):
            runner = CliRunner(env={"DAGSTER_HOME": temp_dir})
            workspace_path = file_relative_path(__file__,
                                                "telemetry_repository.yaml")
            result = runner.invoke(
                ui,
                ["-w", workspace_path],
            )
            assert result.exit_code == 0, str(result.exception)

            expected_repo_stats = {
                hash_name("test_repository"): 1,
                hash_name("dagster_test_repository"): 4,
            }
            actions = set()
            for record in caplog.records:
                message = json.loads(record.getMessage())
                actions.add(message.get("action"))
                if message.get("action") == UPDATE_REPO_STATS:
                    assert message.get("pipeline_name_hash") == ""
                    repo_hash = message.get("repo_hash")

                    assert repo_hash in expected_repo_stats
                    expected_num_pipelines_in_repo = expected_repo_stats.get(
                        repo_hash)
                    assert message.get("num_pipelines_in_repo") == str(
                        expected_num_pipelines_in_repo)

                assert set(message.keys()) == set([
                    "action",
                    "client_time",
                    "elapsed_time",
                    "event_id",
                    "instance_id",
                    "pipeline_name_hash",
                    "num_pipelines_in_repo",
                    "repo_hash",
                    "python_version",
                    "metadata",
                    "version",
                ])

            assert actions == set([START_DAGIT_WEBSERVER, UPDATE_REPO_STATS])
            assert len(caplog.records) == 3
            assert server_mock.call_args_list == [mock.call()]
示例#3
0
文件: test_app.py 项目: sd2k/dagster
def test_dagit_logs(
    server_mock,
    caplog,
):
    with seven.TemporaryDirectory() as temp_dir:
        with environ({"DAGSTER_HOME": temp_dir}):
            with open(os.path.join(temp_dir, "dagster.yaml"), "w") as fd:
                yaml.dump({}, fd, default_flow_style=False)

            DagsterInstance.local_temp(temp_dir)
            runner = CliRunner(env={"DAGSTER_HOME": temp_dir})
            result = runner.invoke(
                ui,
                [
                    "-w",
                    file_relative_path(__file__, "telemetry_repository.yaml"),
                ],
            )
            assert result.exit_code == 0, str(result.exception)

            actions = set()
            for record in caplog.records:
                message = json.loads(record.getMessage())
                actions.add(message.get("action"))
                if message.get("action") == UPDATE_REPO_STATS:
                    assert message.get("pipeline_name_hash") == ""
                    assert message.get("num_pipelines_in_repo") == str(4)
                    assert message.get("repo_hash") == hash_name(
                        "dagster_test_repository")
                assert set(message.keys()) == set([
                    "action",
                    "client_time",
                    "elapsed_time",
                    "event_id",
                    "instance_id",
                    "pipeline_name_hash",
                    "num_pipelines_in_repo",
                    "repo_hash",
                    "python_version",
                    "metadata",
                    "version",
                ])

            assert actions == set([START_DAGIT_WEBSERVER, UPDATE_REPO_STATS])
            assert len(caplog.records) == 2
            assert server_mock.call_args_list == [mock.call()]