Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved some formatting #68

Merged
merged 6 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ def change_key(self, old, new):
if old == new:
return
if new in self._keys:
raise ValueError("Can't replace %s with %s, %s is already a key" %
(old, new, new))
raise ValueError("Can't replace {} with {}, {} is already a key"
.format(old, new, new))
QuLogic marked this conversation as resolved.
Show resolved Hide resolved
if old not in self._keys:
raise KeyError("Can't replace %s with %s, %s is not a key" %
(old, new, old))
raise KeyError("Can't replace {} with {}, {} is not a key"
.format(old, new, old))
QuLogic marked this conversation as resolved.
Show resolved Hide resolved

self._keys.remove(old)
self._keys.add(new)
Expand Down Expand Up @@ -246,7 +246,7 @@ def __iter__(self):
yield dict(left)
else:
for a, b in self._op(self._left, self._right):
out = dict()
out = {}
out.update(a)
out.update(b)
yield out
Expand Down
22 changes: 11 additions & 11 deletions test_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_add():
c1 = cycler(c='rgb')
c2 = cycler(lw=range(3))
# addition
_cycler_helper(c1+c2, 3, ['c', 'lw'], [list('rgb'), range(3)])
_cycler_helper(c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)])
_cycles_equal(c2+c1, c1+c2)
_cycler_helper(c1 + c2, 3, ['c', 'lw'], [list('rgb'), range(3)])
_cycler_helper(c2 + c1, 3, ['c', 'lw'], [list('rgb'), range(3)])
_cycles_equal(c2 + c1, c1 + c2)


def test_add_len_mismatch():
Expand Down Expand Up @@ -89,12 +89,12 @@ def test_inplace():
def test_constructor():
c1 = cycler(c='rgb')
c2 = cycler(ec=c1)
_cycler_helper(c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
_cycler_helper(c1 + c2, 3, ['c', 'ec'], [['r', 'g', 'b']] * 2)
c3 = cycler(c=c1)
_cycler_helper(c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
_cycler_helper(c3 + c2, 3, ['c', 'ec'], [['r', 'g', 'b']] * 2)
# Using a non-string hashable
c4 = cycler(1, range(3))
_cycler_helper(c4+c1, 3, [1, 'c'], [range(3), ['r', 'g', 'b']])
_cycler_helper(c4 + c1, 3, [1, 'c'], [range(3), ['r', 'g', 'b']])

# addition using cycler()
_cycler_helper(cycler(c='rgb', lw=range(3)),
Expand All @@ -118,7 +118,7 @@ def test_failures():

c3 = cycler(ec=c1)

pytest.raises(ValueError, cycler, c=c2+c3)
pytest.raises(ValueError, cycler, c=c2 + c3)


def test_simplify():
Expand All @@ -130,12 +130,12 @@ def test_simplify():

def test_multiply():
c1 = cycler(c='rgb')
_cycler_helper(2*c1, 6, ['c'], ['rgb'*2])
_cycler_helper(2 * c1, 6, ['c'], ['rgb' * 2])

c2 = cycler(ec=c1)
c3 = c1 * c2

_cycles_equal(2*c3, c3*2)
_cycles_equal(2 * c3, c3 * 2)


def test_mul_fails():
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_call():
c_cycle = c()
assert isinstance(c_cycle, cycle)
j = 0
for a, b in zip(2*c, c_cycle):
for a, b in zip(2 * c, c_cycle):
j += 1
assert a == b

Expand Down Expand Up @@ -373,7 +373,7 @@ def test_contains():
assert 'a' not in b
assert 'b' not in a

ab = a+b
ab = a + b

assert 'a' in ab
assert 'b' in ab