diff --git a/mopidy_spotify/utils.py b/mopidy_spotify/utils.py index 712b9548..fa6de5ae 100644 --- a/mopidy_spotify/utils.py +++ b/mopidy_spotify/utils.py @@ -45,9 +45,13 @@ def __init__(self, op, tracks, frm, to=0): self.frm = frm self.to = to def __repr__(self): - x = {"-":"delete","+":"insert","m":"move"} - first, last = self.tracks[0].split(":")[-1], self.tracks[-1].split(":")[-1] - return f'<{x.get(self.op)} {len(self.tracks)} tracks [{first}...{last}] at {self.frm} to {self.to}>' + l = len(self.tracks) + first = self.tracks[0].split(":")[-1] + last = self.tracks[-1].split(":")[-1] + tracks = f"{first}...{last}" if l > 1 else first + action = {"-":"delete","+":"insert","m":"move"} + pos = f"{self.frm} to {self.to}" if self.op == 'm' else self.frm + return f'<{action.get(self.op)} {l} tracks [{tracks}] at {pos}>' def myers(old, new): diff --git a/tests/test_utils.py b/tests/test_utils.py index a7f63228..acae559e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,3 +8,13 @@ def test_time_logger(caplog): pass assert re.match(r".*task took \d+ms.*", caplog.text) + +def test_diff_op_repr(): + o0 = utils.op("+", ["1"], 1, 2) + o1 = utils.op("+", ["1", "2", "3"], 1, 2) + o2 = utils.op("-", ["1", "2", "3"], 1, 2) + o3 = utils.op("m", ["1", "2", "3"], 1, 2) + assert str(o0) == "" + assert str(o1) == "" + assert str(o2) == "" + assert str(o3) == ""