def test_event_logger_from_non_managed_run(self):
    settings.CLIENT_CONFIG.is_managed = False
    settings.CLIENT_CONFIG.is_offline = False
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test', track_code=False, track_env=False, collect_artifacts=False, auto_create=False)
    assert (exit_mock.call_count == 1)
    artifacts_context = CONTEXT_ARTIFACTS_FORMAT.format(run.run_uuid)
    assert (run.get_artifacts_path() == artifacts_context)
    assert (run.get_outputs_path() == CONTEXTS_OUTPUTS_SUBPATH_FORMAT.format(artifacts_context))
    assert (run._event_logger is None)
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test', run_uuid='uuid', track_code=False, track_env=False, collect_artifacts=False)
    assert (exit_mock.call_count == 1)
    artifacts_context = CONTEXT_ARTIFACTS_FORMAT.format(run.run_uuid)
    assert (run.get_artifacts_path() == artifacts_context)
    assert (run.get_outputs_path() == CONTEXTS_OUTPUTS_SUBPATH_FORMAT.format(artifacts_context))
    assert (run._event_logger is None)
    run.set_artifacts_path()
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uuid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uuid'))
    with patch('polyaxon.tracking.run.EventFileWriter') as mock_call:
        run.set_run_event_logger()
    assert (mock_call.call_count == 1)
    with patch('polyaxon.tracking.run.ResourceFileWriter') as mock_call:
        run.set_run_resource_logger()
    assert (mock_call.call_count == 1)
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'true'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'true'
    settings.CLIENT_CONFIG.is_managed = True
    with patch('polyaxon.tracking.run.EventFileWriter') as event_call:
        with patch('polyaxon.tracking.run.ResourceFileWriter') as resource_call:
            with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
                with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_call:
                    run = Run(project='owner-test.test', run_uuid='uuid')
    assert (refresh_call.call_count == 1)
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (exit_call.call_count == 1)
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uuid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uuid'))
def test_event_logger_from_non_managed_run(self):
    settings.CLIENT_CONFIG.is_managed = False
    settings.CLIENT_CONFIG.is_offline = False
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test', track_code=False, track_env=False, collect_artifacts=False, auto_create=False)
    assert (exit_mock.call_count == 1)
    artifacts_context = CONTEXT_ARTIFACTS_FORMAT.format(run.run_uuid)
    assert (run.get_artifacts_path() == artifacts_context)
    assert (run.get_outputs_path() == CONTEXTS_OUTPUTS_SUBPATH_FORMAT.format(artifacts_context))
    assert (run._event_logger is None)
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test', run_uuid='uuid', track_code=False, track_env=False, collect_artifacts=False)
    assert (exit_mock.call_count == 1)
    artifacts_context = CONTEXT_ARTIFACTS_FORMAT.format(run.run_uuid)
    assert (run.get_artifacts_path() == artifacts_context)
    assert (run.get_outputs_path() == CONTEXTS_OUTPUTS_SUBPATH_FORMAT.format(artifacts_context))
    assert (run._event_logger is None)
    run.set_artifacts_path()
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uuid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uuid'))
    with patch('polyaxon.tracking.run.EventFileWriter') as mock_call:
        run.set_run_event_logger()
    assert (mock_call.call_count == 1)
    with patch('polyaxon.tracking.run.ResourceFileWriter') as mock_call:
        run.set_run_resource_logger()
    assert (mock_call.call_count == 1)
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'true'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'true'
    settings.CLIENT_CONFIG.is_managed = True
    with patch('polyaxon.tracking.run.EventFileWriter') as event_call:
        with patch('polyaxon.tracking.run.ResourceFileWriter') as resource_call:
            with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
                with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_call:
                    run = Run(project='owner-test.test', run_uuid='uuid')
    assert (refresh_call.call_count == 1)
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (exit_call.call_count == 1)
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uuid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uuid'))