@@ -482,3 +482,27 @@ async def test_misc_errors(hass, caplog):
482
482
assert "State class is not meant to be instantiated" in caplog .text
483
483
assert "Event class is not meant to be instantiated" in caplog .text
484
484
assert "TrigTime class is not meant to be instantiated" in caplog .text
485
+
486
+
487
+ async def test_install_requirements (hass ):
488
+ """Test install_requirements function."""
489
+ requirements = """
490
+ pytube==9.7.0
491
+ # another test comment
492
+ pykakasi==2.0.1 # test comment
493
+
494
+ """
495
+
496
+ with patch ("os.path.exists" , return_value = True ), patch (
497
+ "custom_components.pyscript.async_hass_config_yaml" , return_value = {}
498
+ ), patch ("custom_components.pyscript.open" , mock_open (read_data = requirements ), create = True ,), patch (
499
+ "custom_components.pyscript.async_process_requirements"
500
+ ) as install_requirements :
501
+ await setup_script (hass , None , dt (2020 , 7 , 1 , 11 , 59 , 59 , 999999 ), "" )
502
+ assert install_requirements .call_args [0 ][2 ] == ["pytube==9.7.0" , "pykakasi==2.0.1" ]
503
+ install_requirements .reset_mock ()
504
+ # Because in tests, packages are not installed, we fake that they are
505
+ # installed so we can test that we don't attempt to install them
506
+ with patch ("custom_components.pyscript.installed_version" , return_value = "2.0.1" ):
507
+ await hass .services .async_call ("pyscript" , "reload" , {}, blocking = True )
508
+ assert not install_requirements .called
0 commit comments