Skip to content

Commit 955a58d

Browse files
Moved warning to stderr (#394)
1 parent ab36dfb commit 955a58d

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

databricks_cli/jobs/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,6 @@ def check_version(api_client, version):
287287
'to use Jobs API 2.0. In order to use the latest Jobs features ' +
288288
'please upgrade to 2.1: \'databricks jobs configure --version=2.1\'. ' +
289289
'Future versions of this CLI will default to the new Jobs API. ' +
290-
'Learn more at https://docs.databricks.com/dev-tools/api/latest/jobs.html'
291-
)
290+
'Learn more at https://docs.databricks.com/dev-tools/api/latest/jobs.html',
291+
err=True
292+
)

tests/jobs/test_cli.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def test_create_cli_json(jobs_api_mock):
5353
jobs_api_mock.create_job.return_value = CREATE_RETURN
5454
runner = CliRunner()
5555
runner.invoke(cli.create_cli, ['--json', CREATE_JSON])
56-
assert jobs_api_mock.create_job.call_args[0][0] == json.loads(CREATE_JSON)
56+
assert jobs_api_mock.create_job.call_args[0][0] == json.loads(
57+
CREATE_JSON)
5758
assert echo_mock.call_args[0][0] == pretty_format(CREATE_RETURN)
5859

5960

@@ -66,7 +67,8 @@ def test_create_cli_json_file(jobs_api_mock, tmpdir):
6667
jobs_api_mock.create_job.return_value = CREATE_RETURN
6768
runner = CliRunner()
6869
runner.invoke(cli.create_cli, ['--json-file', path])
69-
assert jobs_api_mock.create_job.call_args[0][0] == json.loads(CREATE_JSON)
70+
assert jobs_api_mock.create_job.call_args[0][0] == json.loads(
71+
CREATE_JSON)
7072
assert echo_mock.call_args[0][0] == pretty_format(CREATE_RETURN)
7173

7274

@@ -218,9 +220,12 @@ def test_run_now_with_params(jobs_api_mock):
218220
'--spark-submit-params', SPARK_SUBMIT_PARAMS])
219221
assert jobs_api_mock.run_now.call_args[0][0] == 1
220222
assert jobs_api_mock.run_now.call_args[0][1] == json.loads(JAR_PARAMS)
221-
assert jobs_api_mock.run_now.call_args[0][2] == json.loads(NOTEBOOK_PARAMS)
222-
assert jobs_api_mock.run_now.call_args[0][3] == json.loads(PYTHON_PARAMS)
223-
assert jobs_api_mock.run_now.call_args[0][4] == json.loads(SPARK_SUBMIT_PARAMS)
223+
assert jobs_api_mock.run_now.call_args[0][2] == json.loads(
224+
NOTEBOOK_PARAMS)
225+
assert jobs_api_mock.run_now.call_args[0][3] == json.loads(
226+
PYTHON_PARAMS)
227+
assert jobs_api_mock.run_now.call_args[0][4] == json.loads(
228+
SPARK_SUBMIT_PARAMS)
224229
assert echo_mock.call_args[0][0] == pretty_format(RUN_NOW_RETURN)
225230

226231

@@ -234,21 +239,26 @@ def test_configure():
234239
@provide_conf
235240
def test_list_throws_if_invalid_option_for_version_20():
236241
runner = CliRunner()
237-
args = [['--all'], ['--expand-tasks'], ['--offset', '20'], ['--limit', '20']]
242+
args = [['--all'], ['--expand-tasks'],
243+
['--offset', '20'], ['--limit', '20']]
238244

239245
for arg in args:
240246
result = runner.invoke(cli.configure, ['--version=2.0'] + arg)
241247
assert result.exit_code == 2
242248

243249

244-
LIST_RETURN_1 = {'jobs': [{'job_id': '1', 'settings': {'name': 'a'}}], 'has_more': True}
245-
LIST_RETURN_2 = {'jobs': [{'job_id': '2', 'settings': {'name': 'b'}}], 'has_more': True}
246-
LIST_RETURN_3 = {'jobs': [{'job_id': '3', 'settings': {'name': 'c'}}], 'has_more': False}
250+
LIST_RETURN_1 = {
251+
'jobs': [{'job_id': '1', 'settings': {'name': 'a'}}], 'has_more': True}
252+
LIST_RETURN_2 = {
253+
'jobs': [{'job_id': '2', 'settings': {'name': 'b'}}], 'has_more': True}
254+
LIST_RETURN_3 = {
255+
'jobs': [{'job_id': '3', 'settings': {'name': 'c'}}], 'has_more': False}
247256

248257

249258
@provide_conf
250259
def test_list_all(jobs_api_mock):
251-
jobs_api_mock.list_jobs.side_effect = iter([LIST_RETURN_1, LIST_RETURN_2, LIST_RETURN_3])
260+
jobs_api_mock.list_jobs.side_effect = iter(
261+
[LIST_RETURN_1, LIST_RETURN_2, LIST_RETURN_3])
252262
runner = CliRunner()
253263
result = runner.invoke(cli.list_cli, ['--version=2.1', '--all'])
254264
rows = [(1, 'a'), (2, 'b'), (3, 'c')]
@@ -302,6 +312,7 @@ def test_check_version():
302312
cli.check_version(api_client, None)
303313
assert echo_mock.called
304314
assert 'Your CLI is configured to use Jobs API 2.0' in echo_mock.call_args[0][0]
315+
assert echo_mock.call_args_list[0][1]['err'] is True
305316
# databricks jobs list --version=2.0
306317
with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
307318
cli.check_version(api_client, "2.0")

0 commit comments

Comments
 (0)