17
17
KedroTelemetryCLIHooks ,
18
18
KedroTelemetryProjectHooks ,
19
19
_check_for_telemetry_consent ,
20
- _confirm_consent ,
21
20
_is_known_ci_env ,
22
21
)
23
22
@@ -371,8 +370,6 @@ def test_check_for_telemetry_consent_given(self, mocker, fake_metadata):
371
370
with open (telemetry_file_path , "w" , encoding = "utf-8" ) as telemetry_file :
372
371
yaml .dump ({"consent" : True }, telemetry_file )
373
372
374
- mock_create_file = mocker .patch ("kedro_telemetry.plugin._confirm_consent" )
375
- mock_create_file .assert_not_called ()
376
373
assert _check_for_telemetry_consent (fake_metadata .project_path )
377
374
378
375
def test_check_for_telemetry_consent_not_given (self , mocker , fake_metadata ):
@@ -381,29 +378,16 @@ def test_check_for_telemetry_consent_not_given(self, mocker, fake_metadata):
381
378
with open (telemetry_file_path , "w" , encoding = "utf-8" ) as telemetry_file :
382
379
yaml .dump ({"consent" : False }, telemetry_file )
383
380
384
- mock_create_file = mocker .patch ("kedro_telemetry.plugin._confirm_consent" )
385
- mock_create_file .assert_not_called ()
386
381
assert not _check_for_telemetry_consent (fake_metadata .project_path )
387
382
388
383
def test_check_for_telemetry_consent_empty_file (self , mocker , fake_metadata ):
389
384
Path (fake_metadata .project_path , "conf" ).mkdir (parents = True )
390
385
telemetry_file_path = fake_metadata .project_path / ".telemetry"
391
- mock_create_file = mocker .patch (
392
- "kedro_telemetry.plugin._confirm_consent" , return_value = True
393
- )
394
-
395
- assert _check_for_telemetry_consent (fake_metadata .project_path )
396
- mock_create_file .assert_called_once_with (telemetry_file_path )
397
386
398
- def test_check_for_telemetry_no_consent_empty_file (self , mocker , fake_metadata ):
399
- Path (fake_metadata .project_path , "conf" ).mkdir (parents = True )
400
- telemetry_file_path = fake_metadata .project_path / ".telemetry"
401
- mock_create_file = mocker .patch (
402
- "kedro_telemetry.plugin._confirm_consent" , return_value = False
403
- )
387
+ with open (telemetry_file_path , "w" , encoding = "utf-8" ) as telemetry_file :
388
+ yaml .dump ({}, telemetry_file )
404
389
405
- assert not _check_for_telemetry_consent (fake_metadata .project_path )
406
- mock_create_file .assert_called_once_with (telemetry_file_path )
390
+ assert _check_for_telemetry_consent (fake_metadata .project_path )
407
391
408
392
def test_check_for_telemetry_consent_file_no_consent_field (
409
393
self , mocker , fake_metadata
@@ -413,37 +397,14 @@ def test_check_for_telemetry_consent_file_no_consent_field(
413
397
with open (telemetry_file_path , "w" , encoding = "utf8" ) as telemetry_file :
414
398
yaml .dump ({"nonsense" : "bla" }, telemetry_file )
415
399
416
- mock_create_file = mocker .patch (
417
- "kedro_telemetry.plugin._confirm_consent" , return_value = True
418
- )
419
-
420
400
assert _check_for_telemetry_consent (fake_metadata .project_path )
421
- mock_create_file .assert_called_once_with (telemetry_file_path )
422
401
423
402
def test_check_for_telemetry_consent_file_invalid_yaml (self , mocker , fake_metadata ):
424
403
Path (fake_metadata .project_path , "conf" ).mkdir (parents = True )
425
404
telemetry_file_path = fake_metadata .project_path / ".telemetry"
426
405
telemetry_file_path .write_text ("invalid_ yaml" )
427
406
428
- mock_create_file = mocker .patch (
429
- "kedro_telemetry.plugin._confirm_consent" , return_value = True
430
- )
431
-
432
407
assert _check_for_telemetry_consent (fake_metadata .project_path )
433
- mock_create_file .assert_called_once_with (telemetry_file_path )
434
-
435
- def test_confirm_consent_yaml_dump_error (self , mocker , fake_metadata , caplog ):
436
- Path (fake_metadata .project_path , "conf" ).mkdir (parents = True )
437
- telemetry_file_path = fake_metadata .project_path / ".telemetry"
438
- mocker .patch ("yaml.dump" , side_efyfect = Exception )
439
-
440
- assert not _confirm_consent (telemetry_file_path )
441
-
442
- msg = (
443
- "Failed to confirm consent. No data was sent to Heap. Exception: "
444
- "pytest: reading from stdin while output is captured! Consider using `-s`."
445
- )
446
- assert msg in caplog .messages [- 1 ]
447
408
448
409
@mark .parametrize (
449
410
"env_vars,result" ,
0 commit comments