Skip to content

Commit f9f0722

Browse files
committed
Fix PEP8 max line length violation
close #434
1 parent d47fb2a commit f9f0722

File tree

111 files changed

+701
-905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+701
-905
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ install:
1818
- pip install -r requirements-travis.txt
1919

2020
before_script:
21-
- flake8 ./exercises/ --max-line-length=99 --select=E,W
21+
- flake8 .
2222

2323
script:
2424
- ./test/check-exercises.py

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ python test/check-exercises.py
3535

3636
The Python code in this repo is meant to largely obey the [PEP8 style guide](https://www.python.org/dev/peps/pep-0008/).
3737

38-
This repo uses [flake8](http://flake8.readthedocs.org/en/latest/) to enforce the coding standard. When you submit a PR, it needs to pass the flake8 tool with no warnings, or it won't be accepted. Here are the settings used by the build system:
39-
40-
```
41-
flake8 [your-code-here.py] --max-line-length=99 --select=E,W
42-
```
38+
This repo uses [flake8](http://flake8.readthedocs.org/en/latest/) to enforce the coding standard. When you submit a PR, it needs to pass the flake8 tool with no warnings, or it won't be accepted.
4339

4440
## Pull Requests
4541

exercises/accumulate/accumulate_test.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def test_empty_sequence(self):
88
self.assertEqual([], accumulate([], lambda x: x / 2))
99

1010
def test_pow(self):
11-
self.assertEqual([1, 4, 9, 16, 25], accumulate([1, 2, 3, 4, 5],
12-
lambda x: x * x))
11+
self.assertEqual([1, 4, 9, 16, 25],
12+
accumulate([1, 2, 3, 4, 5], lambda x: x * x))
1313

1414
def test_divmod(self):
1515
inp = [10, 17, 23]
@@ -18,8 +18,10 @@ def test_divmod(self):
1818

1919
def test_composition(self):
2020
inp = [10, 17, 23]
21-
self.assertEqual(inp, accumulate(accumulate(inp, lambda x: divmod(x, 7)),
22-
lambda x: 7 * x[0] + x[1]))
21+
self.assertEqual(inp,
22+
accumulate(
23+
accumulate(inp, lambda x: divmod(x, 7)),
24+
lambda x: 7 * x[0] + x[1]))
2325

2426
def test_capitalize(self):
2527
inp = ['hello', 'world']
@@ -29,8 +31,10 @@ def test_capitalize(self):
2931
def test_recursive(self):
3032
inp = list('abc')
3133
out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
32-
self.assertEqual(out, accumulate(inp, lambda x: accumulate(list('123'),
33-
lambda y: x + y)))
34+
self.assertEqual(
35+
out,
36+
accumulate(inp,
37+
lambda x: accumulate(list('123'), lambda y: x + y)))
3438

3539

3640
if __name__ == '__main__':

exercises/acronym/acronym_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from acronym import abbreviate
44

5-
65
# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
76

7+
88
class AcronymTest(unittest.TestCase):
99
def test_basic(self):
1010
self.assertEqual('PNG', abbreviate('Portable Network Graphics'))
@@ -25,7 +25,8 @@ def test_non_acronym_all_caps_word(self):
2525
self.assertEqual('GIMP', abbreviate('GNU Image Manipulation Program'))
2626

2727
def test_hyphenated(self):
28-
self.assertEqual('CMOS', abbreviate('Complementary metal-oxide semiconductor'))
28+
self.assertEqual('CMOS',
29+
abbreviate('Complementary metal-oxide semiconductor'))
2930

3031

3132
if __name__ == '__main__':

exercises/all-your-base/all_your_base_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
from all_your_base import rebase
44

5-
65
# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
76

8-
class AllYourBaseTests(unittest.TestCase):
97

8+
class AllYourBaseTests(unittest.TestCase):
109
def test_single_bit_to_one_decimal(self):
1110
self.assertEqual(rebase(2, [1], 10), [1])
1211

exercises/all-your-base/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def from_digits(digits, base):
2-
return sum(n * base ** i for i, n in enumerate(reversed(digits)))
2+
return sum(n * base**i for i, n in enumerate(reversed(digits)))
33

44

55
def to_digits(number, base_to):

exercises/allergies/allergies_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class AllergiesTests(unittest.TestCase):
7-
87
def test_no_allergies_means_not_allergic(self):
98
allergies = Allergies(0)
109
self.assertFalse(allergies.is_allergic_to('peanuts'))

exercises/allergies/example.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
class Allergies(object):
22

33
_allergies = [
4-
"eggs",
5-
"peanuts",
6-
"shellfish",
7-
"strawberries",
8-
"tomatoes",
9-
"chocolate",
10-
"pollen",
11-
"cats"
4+
"eggs", "peanuts", "shellfish", "strawberries", "tomatoes",
5+
"chocolate", "pollen", "cats"
126
]
137

148
def __init__(self, score):
@@ -19,5 +13,7 @@ def is_allergic_to(self, allergy):
1913

2014
@property
2115
def lst(self):
22-
return [allergy for allergy in self._allergies
23-
if self.is_allergic_to(allergy)]
16+
return [
17+
allergy for allergy in self._allergies
18+
if self.is_allergic_to(allergy)
19+
]

exercises/anagram/anagram_test.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,45 @@
66
class AnagramTests(unittest.TestCase):
77
def test_no_matches(self):
88
self.assertEqual(
9-
[],
10-
detect_anagrams('diaper', 'hello world zombies pants'.split())
11-
)
9+
[], detect_anagrams('diaper', 'hello world zombies pants'.split()))
1210

1311
def test_detect_simple_anagram(self):
14-
self.assertEqual(
15-
['tan'],
16-
detect_anagrams('ant', 'tan stand at'.split())
17-
)
12+
self.assertEqual(['tan'],
13+
detect_anagrams('ant', 'tan stand at'.split()))
1814

1915
def test_detect_multiple_anagrams(self):
2016
self.assertEqual(
2117
['stream', 'maters'],
22-
detect_anagrams('master', 'stream pigeon maters'.split())
23-
)
18+
detect_anagrams('master', 'stream pigeon maters'.split()))
2419

2520
def test_does_not_confuse_different_duplicates(self):
26-
self.assertEqual(
27-
[],
28-
detect_anagrams('galea', ['eagle'])
29-
)
21+
self.assertEqual([], detect_anagrams('galea', ['eagle']))
3022

3123
def test_eliminate_anagram_subsets(self):
32-
self.assertEqual(
33-
[],
34-
detect_anagrams('good', 'dog goody'.split())
35-
)
24+
self.assertEqual([], detect_anagrams('good', 'dog goody'.split()))
3625

3726
def test_detect_anagram(self):
3827
self.assertEqual(
3928
['inlets'],
40-
detect_anagrams('listen', 'enlists google inlets banana'.split())
41-
)
29+
detect_anagrams('listen', 'enlists google inlets banana'.split()))
4230

4331
def test_multiple_anagrams(self):
4432
self.assertEqual(
4533
'gallery regally largely'.split(),
4634
detect_anagrams(
4735
'allergy',
48-
'gallery ballerina regally clergy largely leading'.split()
49-
)
50-
)
36+
'gallery ballerina regally clergy largely leading'.split()))
5137

5238
def test_anagrams_are_case_insensitive(self):
5339
self.assertEqual(
5440
['Carthorse'],
5541
detect_anagrams('Orchestra',
56-
'cashregister Carthorse radishes'.split())
57-
)
42+
'cashregister Carthorse radishes'.split()))
5843

5944
def test_same_word_isnt_anagram(self):
60-
self.assertEqual(
61-
[],
62-
detect_anagrams('banana', ['banana'])
63-
)
45+
self.assertEqual([], detect_anagrams('banana', ['banana']))
6446

65-
self.assertEqual(
66-
[],
67-
detect_anagrams('go', 'go Go GO'.split())
68-
)
47+
self.assertEqual([], detect_anagrams('go', 'go Go GO'.split()))
6948

7049

7150
if __name__ == '__main__':

exercises/anagram/example.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
def detect_anagrams(word, candidates):
2-
return [candidate
3-
for candidate in candidates
4-
if _letters(candidate) == _letters(word)
5-
if candidate.lower() != word.lower()]
2+
return [
3+
candidate for candidate in candidates
4+
if _letters(candidate) == _letters(word)
5+
if candidate.lower() != word.lower()
6+
]
67

78

89
def _letters(word):

exercises/atbash-cipher/atbash_cipher_test.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
from atbash_cipher import decode, encode
44

5-
65
# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
76

8-
class AtbashCipherTest(unittest.TestCase):
97

8+
class AtbashCipherTest(unittest.TestCase):
109
def test_encode_no(self):
1110
self.assertMultiLineEqual("ml", encode("no"))
1211

@@ -41,14 +40,11 @@ def test_decode_word(self):
4140
def test_decode_sentence(self):
4241
self.assertMultiLineEqual(
4342
"anobstacleisoftenasteppingstone",
44-
decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v")
45-
)
43+
decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"))
4644

4745
def test_decode_numbers(self):
48-
self.assertMultiLineEqual(
49-
"testing123testing",
50-
decode("gvhgr mt123 gvhgr mt")
51-
)
46+
self.assertMultiLineEqual("testing123testing",
47+
decode("gvhgr mt123 gvhgr mt"))
5248

5349
def test_decode_all_the_letters(self):
5450
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
@@ -57,10 +53,8 @@ def test_decode_all_the_letters(self):
5753

5854
# additional track specific test
5955
def test_encode_decode(self):
60-
self.assertMultiLineEqual(
61-
"testing123testing",
62-
decode(encode("Testing, 1 2 3, testing."))
63-
)
56+
self.assertMultiLineEqual("testing123testing",
57+
decode(encode("Testing, 1 2 3, testing.")))
6458

6559

6660
if __name__ == '__main__':

exercises/atbash-cipher/example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
else:
77
maketrans = str.maketrans
88

9-
109
BLKSZ = 5
1110
trtbl = maketrans(ascii_lowercase, ascii_lowercase[::-1])
1211

@@ -17,8 +16,8 @@ def base_trans(text):
1716

1817
def encode(plain):
1918
cipher = base_trans(plain)
20-
return " ".join([cipher[i:i + BLKSZ]
21-
for i in range(0, len(cipher), BLKSZ)])
19+
return " ".join(
20+
[cipher[i:i + BLKSZ] for i in range(0, len(cipher), BLKSZ)])
2221

2322

2423
def decode(ciphered):

exercises/beer-song/beer_song_test.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@
66
class BeerTest(unittest.TestCase):
77
def test_a_verse(self):
88
self.assertEqual(
9-
verse(8),
10-
"8 bottles of beer on the wall, 8 bottles of beer.\n"
9+
verse(8), "8 bottles of beer on the wall, 8 bottles of beer.\n"
1110
"Take one down and pass it around, "
12-
"7 bottles of beer on the wall.\n"
13-
)
11+
"7 bottles of beer on the wall.\n")
1412

1513
def test_verse_1(self):
1614
self.assertEqual(
17-
verse(1),
18-
"1 bottle of beer on the wall, 1 bottle of beer.\n"
15+
verse(1), "1 bottle of beer on the wall, 1 bottle of beer.\n"
1916
"Take it down and pass it around, "
20-
"no more bottles of beer on the wall.\n"
21-
)
17+
"no more bottles of beer on the wall.\n")
2218

2319
def test_verse_2(self):
2420
self.assertEqual(
25-
verse(2),
26-
"2 bottles of beer on the wall, 2 bottles of beer.\n"
21+
verse(2), "2 bottles of beer on the wall, 2 bottles of beer.\n"
2722
"Take one down and pass it around, 1 bottle of beer on the wall.\n"
2823
)
2924

@@ -32,27 +27,23 @@ def test_verse_0(self):
3227
verse(0),
3328
"No more bottles of beer on the wall, no more bottles of beer.\n"
3429
"Go to the store and buy some more, "
35-
"99 bottles of beer on the wall.\n"
36-
)
30+
"99 bottles of beer on the wall.\n")
3731

3832
def test_songing_several_verses(self):
3933
self.assertEqual(
40-
song(8, 6),
41-
"8 bottles of beer on the wall, 8 bottles of beer.\n"
34+
song(8, 6), "8 bottles of beer on the wall, 8 bottles of beer.\n"
4235
"Take one down and pass it around, "
4336
"7 bottles of beer on the wall.\n\n"
4437
"7 bottles of beer on the wall, 7 bottles of beer.\n"
4538
"Take one down and pass it around, "
4639
"6 bottles of beer on the wall.\n\n"
4740
"6 bottles of beer on the wall, 6 bottles of beer.\n"
4841
"Take one down and pass it around, "
49-
"5 bottles of beer on the wall.\n\n"
50-
)
42+
"5 bottles of beer on the wall.\n\n")
5143

5244
def test_song_all_the_rest_of_the_verses(self):
5345
self.assertEqual(
54-
song(3),
55-
"3 bottles of beer on the wall, 3 bottles of beer.\n"
46+
song(3), "3 bottles of beer on the wall, 3 bottles of beer.\n"
5647
"Take one down and pass it around, "
5748
"2 bottles of beer on the wall.\n\n"
5849
"2 bottles of beer on the wall, 2 bottles of beer.\n"
@@ -63,8 +54,7 @@ def test_song_all_the_rest_of_the_verses(self):
6354
"no more bottles of beer on the wall.\n\n"
6455
"No more bottles of beer on the wall, no more bottles of beer.\n"
6556
"Go to the store and buy some more, "
66-
"99 bottles of beer on the wall.\n\n"
67-
)
57+
"99 bottles of beer on the wall.\n\n")
6858

6959

7060
if __name__ == '__main__':

exercises/beer-song/example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def _action(current_verse):
1919
if current_verse == 0:
2020
return "Go to the store and buy some more, "
2121
else:
22-
return "Take %s down and pass it around, " % (
23-
"one" if current_verse > 1 else "it"
24-
)
22+
return "Take %s down and pass it around, " % ("one"
23+
if current_verse > 1 else
24+
"it")
2525

2626

2727
def _next_bottle(current_verse):

0 commit comments

Comments
 (0)