@@ -52,25 +52,77 @@ async def test_reauth_started(
5252
5353
5454@pytest .mark .parametrize ("platforms" , [[Platform .IMAGE ]])
55- async def test_oserror_remove_image (
55+ @pytest .mark .parametrize (
56+ ("exists" , "is_dir" , "rmtree_called" ),
57+ [
58+ (True , True , True ),
59+ (False , False , False ),
60+ (True , False , False ),
61+ ],
62+ ids = [
63+ "old_storage_removed" ,
64+ "new_storage_ignored" ,
65+ "no_existing_storage" ,
66+ ],
67+ )
68+ async def test_remove_old_storage_directory (
5669 hass : HomeAssistant ,
57- setup_entry : MockConfigEntry ,
70+ mock_roborock_entry : MockConfigEntry ,
5871 storage_path : pathlib .Path ,
5972 hass_client : ClientSessionGenerator ,
6073 caplog : pytest .LogCaptureFixture ,
74+ exists : bool ,
75+ is_dir : bool ,
76+ rmtree_called : bool ,
6177) -> None :
62- """Test that we gracefully handle failing to remove old map storage."""
78+ """Test cleanup of old old map storage."""
79+ with (
80+ patch (
81+ "homeassistant.components.roborock.roborock_storage.Path.exists" ,
82+ return_value = exists ,
83+ ),
84+ patch (
85+ "homeassistant.components.roborock.roborock_storage.Path.is_dir" ,
86+ return_value = is_dir ,
87+ ),
88+ patch (
89+ "homeassistant.components.roborock.roborock_storage.shutil.rmtree" ,
90+ ) as mock_rmtree ,
91+ ):
92+ await hass .config_entries .async_setup (mock_roborock_entry .entry_id )
93+ await hass .async_block_till_done ()
94+ assert mock_roborock_entry .state is ConfigEntryState .LOADED
6395
96+ assert mock_rmtree .called == rmtree_called
97+
98+
99+ @pytest .mark .parametrize ("platforms" , [[Platform .IMAGE ]])
100+ async def test_oserror_remove_storage_directory (
101+ hass : HomeAssistant ,
102+ mock_roborock_entry : MockConfigEntry ,
103+ storage_path : pathlib .Path ,
104+ hass_client : ClientSessionGenerator ,
105+ caplog : pytest .LogCaptureFixture ,
106+ ) -> None :
107+ """Test that we gracefully handle failing to remove old map storage."""
64108 with (
65109 patch (
66110 "homeassistant.components.roborock.roborock_storage.Path.exists" ,
111+ return_value = True ,
112+ ),
113+ patch (
114+ "homeassistant.components.roborock.roborock_storage.Path.is_dir" ,
115+ return_value = True ,
67116 ),
68117 patch (
69118 "homeassistant.components.roborock.roborock_storage.shutil.rmtree" ,
70119 side_effect = OSError ,
71120 ) as mock_rmtree ,
72121 ):
73- await hass .config_entries .async_remove (setup_entry .entry_id )
122+ await hass .config_entries .async_setup (mock_roborock_entry .entry_id )
123+ await hass .async_block_till_done ()
124+ assert mock_roborock_entry .state is ConfigEntryState .LOADED
125+
74126 assert mock_rmtree .called
75127 assert "Unable to remove map files" in caplog .text
76128
0 commit comments