def test_event_logger_from_a_managed_run(self):
    settings.CLIENT_CONFIG.is_managed = True
    settings.CLIENT_CONFIG.is_offline = False
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'false'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'false'
    with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
        run = Run()
    assert (refresh_call.call_count == 1)
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uid'))
    assert (run._event_logger is None)
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'true'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'true'
    with patch('polyaxon.tracking.run.Run.set_run_event_logger') as event_call:
        with patch('polyaxon.tracking.run.Run.set_run_resource_logger') 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(project='test.test', run_uuid='uuid')
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (refresh_call.call_count == 1)
    assert (exit_call.call_count == 1)
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    with patch('polyaxon.tracking.run.Run.set_run_event_logger') as event_call:
        with patch('polyaxon.tracking.run.Run.set_run_resource_logger') as resource_call:
            with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
                Run()
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (refresh_call.call_count == 1)
def test_event_logger_from_a_managed_run(self):
    settings.CLIENT_CONFIG.is_managed = True
    settings.CLIENT_CONFIG.is_offline = False
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'false'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'false'
    with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
        run = Run()
    assert (refresh_call.call_count == 1)
    assert (run.get_artifacts_path() == CONTEXT_MOUNT_ARTIFACTS_FORMAT.format('uid'))
    assert (run.get_outputs_path() == CONTEXT_MOUNT_RUN_OUTPUTS_FORMAT.format('uid'))
    assert (run._event_logger is None)
    os.environ[POLYAXON_KEYS_COLLECT_ARTIFACTS] = 'true'
    os.environ[POLYAXON_KEYS_COLLECT_RESOURCES] = 'true'
    with patch('polyaxon.tracking.run.Run.set_run_event_logger') as event_call:
        with patch('polyaxon.tracking.run.Run.set_run_resource_logger') 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(project='test.test', run_uuid='uuid')
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (refresh_call.call_count == 1)
    assert (exit_call.call_count == 1)
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    with patch('polyaxon.tracking.run.Run.set_run_event_logger') as event_call:
        with patch('polyaxon.tracking.run.Run.set_run_resource_logger') as resource_call:
            with patch('polyaxon.tracking.run.Run.refresh_data') as refresh_call:
                Run()
    assert (event_call.call_count == 1)
    assert (resource_call.call_count == 1)
    assert (refresh_call.call_count == 1)