From 71593d438dff1a54986c94b469faa31c4581f6c7 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Wed, 22 Dec 2021 22:14:43 +0100 Subject: Fixed additive loading issue --- session_manager_unittest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'session_manager_unittest.py') diff --git a/session_manager_unittest.py b/session_manager_unittest.py index 7fb8c55..532ae75 100644 --- a/session_manager_unittest.py +++ b/session_manager_unittest.py @@ -33,6 +33,9 @@ class PlaylistMock: def getSongs(self): return self.songs + def clear(self): + self.__init__() + class ABControllerMock: def __init__(self): self.limits = dict() @@ -45,6 +48,9 @@ class ABControllerMock: def getLimits(self, song): return self.limits.get(song) + def clear(self): + self.__init__() + class MockFile: def __init__(self, init=""): self.contents = init @@ -138,3 +144,20 @@ def test_loadAndSaveEmptySession(): assert songs == list() for s in songs: assert abControllerMock.getLimits(s) == None + +def test_loadSessionNotAdditive(): + playlistMock = PlaylistMock() + abControllerMock = ABControllerMock() + uut = SessionManager(playlistMock, abControllerMock) + + sessionFile = MockFile(dumps(testSession)) + uut.loadSession(sessionFile) + uut.loadSession(sessionFile) + + songs = playlistMock.getSongs() + assert len(songs) == len(set(songs)) + for s in songs: + abLimits = abControllerMock.getLimits(s) + if abLimits is not None: + abLimitStr = [f"[{l[0]}, {l[1]}] " for l in abLimits] + assert len(abLimitStr) == len(set(abLimitStr)) -- cgit v1.2.3