@patch('polyaxon.managers.base.os.path.expanduser')
def test_run_init(self, expanduser):
    expanduser.return_value = tempfile.mkdtemp()
    settings.CLIENT_CONFIG.is_managed = False
    settings.CLIENT_CONFIG.is_offline = False
    with self.assertRaises(PolyaxonClientException):
        Run()
    with self.assertRaises(PolyaxonClientException):
        Run(project='test')
    settings.CLIENT_CONFIG.is_offline = True
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='test', track_code=False, track_env=False)
    assert (exit_mock.call_count == 1)
    assert (run.owner == DEFAULT)
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(owner='owner-test', project='test', track_code=False, track_env=False)
    assert (exit_mock.call_count == 1)
    assert (run.owner == 'owner-test')
    assert (run.project == 'test')
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test')
    assert (exit_mock.call_count == 1)
    assert (run.owner == 'owner-test')
    assert (run.project == 'test')
    settings.CLIENT_CONFIG.is_managed = True
    settings.CLIENT_CONFIG.is_offline = False
    with self.assertRaises(PolyaxonClientException):
        Run()
    settings.CLI_CONFIG.installation = None
    with self.assertRaises(PolyaxonClientException):
        Run(project='test')
    settings.CLIENT_CONFIG.is_offline = True
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    run = Run(project='test')
    assert (run.owner == DEFAULT)
    settings.CLI_CONFIG.installation = None
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    run = Run()
    assert (run.owner == 'user')
    assert (run.project == 'project_bar')
    assert (run.run_uuid == 'uid')
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    run = Run()
    assert (run.owner == 'user')
    assert (run.project == 'project_bar')
    assert (run.run_uuid == 'uid')
@patch('polyaxon.managers.base.os.path.expanduser')
def test_run_init(self, expanduser):
    expanduser.return_value = tempfile.mkdtemp()
    settings.CLIENT_CONFIG.is_managed = False
    settings.CLIENT_CONFIG.is_offline = False
    with self.assertRaises(PolyaxonClientException):
        Run()
    with self.assertRaises(PolyaxonClientException):
        Run(project='test')
    settings.CLIENT_CONFIG.is_offline = True
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='test', track_code=False, track_env=False)
    assert (exit_mock.call_count == 1)
    assert (run.owner == DEFAULT)
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(owner='owner-test', project='test', track_code=False, track_env=False)
    assert (exit_mock.call_count == 1)
    assert (run.owner == 'owner-test')
    assert (run.project == 'test')
    with patch('polyaxon.tracking.run.Run._set_exit_handler') as exit_mock:
        run = Run(project='owner-test.test')
    assert (exit_mock.call_count == 1)
    assert (run.owner == 'owner-test')
    assert (run.project == 'test')
    settings.CLIENT_CONFIG.is_managed = True
    settings.CLIENT_CONFIG.is_offline = False
    with self.assertRaises(PolyaxonClientException):
        Run()
    settings.CLI_CONFIG.installation = None
    with self.assertRaises(PolyaxonClientException):
        Run(project='test')
    settings.CLIENT_CONFIG.is_offline = True
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    run = Run(project='test')
    assert (run.owner == DEFAULT)
    settings.CLI_CONFIG.installation = None
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    run = Run()
    assert (run.owner == 'user')
    assert (run.project == 'project_bar')
    assert (run.run_uuid == 'uid')
    settings.CLI_CONFIG.installation = {'dist': PLATFORM_DIST_CE}
    os.environ[POLYAXON_KEYS_RUN_INSTANCE] = 'user.project_bar.runs.uid'
    run = Run()
    assert (run.owner == 'user')
    assert (run.project == 'project_bar')
    assert (run.run_uuid == 'uid')