diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_subcmds_sync.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 71e40489..af6bbef7 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
| @@ -265,6 +265,44 @@ class LocalSyncState(unittest.TestCase): | |||
| 265 | self.assertIsNone(self.state.GetFetchTime(projA)) | 265 | self.assertIsNone(self.state.GetFetchTime(projA)) |
| 266 | self.assertEqual(self.state.GetFetchTime(projB), 7) | 266 | self.assertEqual(self.state.GetFetchTime(projB), 7) |
| 267 | 267 | ||
| 268 | def test_prune_removed_and_symlinked_projects(self): | ||
| 269 | """Removed projects that still exists on disk as symlink are pruned.""" | ||
| 270 | with open(self.state._path, "w") as f: | ||
| 271 | f.write( | ||
| 272 | """ | ||
| 273 | { | ||
| 274 | "projA": { | ||
| 275 | "last_fetch": 5 | ||
| 276 | }, | ||
| 277 | "projB": { | ||
| 278 | "last_fetch": 7 | ||
| 279 | } | ||
| 280 | } | ||
| 281 | """ | ||
| 282 | ) | ||
| 283 | |||
| 284 | def mock_exists(path): | ||
| 285 | return True | ||
| 286 | |||
| 287 | def mock_islink(path): | ||
| 288 | if "projB" in path: | ||
| 289 | return True | ||
| 290 | return False | ||
| 291 | |||
| 292 | projA = mock.MagicMock(relpath="projA") | ||
| 293 | projB = mock.MagicMock(relpath="projB") | ||
| 294 | self.state = self._new_state() | ||
| 295 | self.assertEqual(self.state.GetFetchTime(projA), 5) | ||
| 296 | self.assertEqual(self.state.GetFetchTime(projB), 7) | ||
| 297 | with mock.patch("os.path.exists", side_effect=mock_exists): | ||
| 298 | with mock.patch("os.path.islink", side_effect=mock_islink): | ||
| 299 | self.state.PruneRemovedProjects() | ||
| 300 | self.assertIsNone(self.state.GetFetchTime(projB)) | ||
| 301 | |||
| 302 | self.state = self._new_state() | ||
| 303 | self.assertIsNone(self.state.GetFetchTime(projB)) | ||
| 304 | self.assertEqual(self.state.GetFetchTime(projA), 5) | ||
| 305 | |||
| 268 | 306 | ||
| 269 | class GetPreciousObjectsState(unittest.TestCase): | 307 | class GetPreciousObjectsState(unittest.TestCase): |
| 270 | """Tests for _GetPreciousObjectsState.""" | 308 | """Tests for _GetPreciousObjectsState.""" |
