Skip to content

Commit

Permalink
Keep utils test coverage at 100%
Browse files Browse the repository at this point in the history
op.__repr__ is useful for debugging only.
  • Loading branch information
girst committed Nov 19, 2020
1 parent 9098373 commit 06506c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mopidy_spotify/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) == "<insert 1 tracks [1] at 1>"
assert str(o1) == "<insert 3 tracks [1...3] at 1>"
assert str(o2) == "<delete 3 tracks [1...3] at 1>"
assert str(o3) == "<move 3 tracks [1...3] at 1 to 2>"

0 comments on commit 06506c0

Please sign in to comment.