Merge lp:~noise/ubuntu-rest-scopes/fix-avoidable-query into lp:ubuntu-rest-scopes

Proposed by Bret Barker
Status: Merged
Approved by: Bret Barker
Approved revision: 447
Merged at revision: 453
Proposed branch: lp:~noise/ubuntu-rest-scopes/fix-avoidable-query
Merge into: lp:ubuntu-rest-scopes
Diff against target: 56 lines (+23/-4)
2 files modified
src/tests/test_utils.py (+18/-0)
src/utils.py (+5/-4)
To merge this branch: bzr merge lp:~noise/ubuntu-rest-scopes/fix-avoidable-query
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Review via email: mp+255566@code.launchpad.net

Commit message

fix off-by-one error in avoidable query check; fix typo in constant

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~noise/ubuntu-rest-scopes/fix-avoidable-query into lp:ubuntu-rest-scopes failed. Below is the output from the failed tests.

src/tests/test_utils.py:77:1: W293 blank line contains whitespace

......................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 358 tests in 15.698s

OK

447. By Bret Barker

pep8 foo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/tests/test_utils.py'
2--- src/tests/test_utils.py 2015-03-31 15:03:35 +0000
3+++ src/tests/test_utils.py 2015-04-08 19:58:47 +0000
4@@ -70,3 +70,21 @@
5 def test_too_repeated_twice(self):
6 q = u"adjskajhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmb,mb,mb,mb,hkkkkkkkkkkkkkkkkkkkkkkkkkpouiud"
7 self.assertTrue(utils.avoidable_query(q))
8+
9+ def test_simple_repeated_5(self):
10+ q = u"x" * utils.MAX_REPEATED_IN_A_ROW
11+ self.assertFalse(utils.avoidable_query(q))
12+
13+ def test_simple_repeated_6(self):
14+ q = u"x" * (utils.MAX_REPEATED_IN_A_ROW + 1)
15+ self.assertTrue(utils.avoidable_query(q))
16+
17+ def test_simple_repeated_7(self):
18+ q = u"x" * (utils.MAX_REPEATED_IN_A_ROW + 2)
19+ self.assertTrue(utils.avoidable_query(q))
20+
21+ def test_simple_repeated_again(self):
22+ q = u"x" * utils.MAX_REPEATED_IN_A_ROW
23+ q += u"yz"
24+ q += u"x" * (utils.MAX_REPEATED_IN_A_ROW + 1)
25+ self.assertTrue(utils.avoidable_query(q))
26
27=== modified file 'src/utils.py'
28--- src/utils.py 2015-03-31 15:03:35 +0000
29+++ src/utils.py 2015-04-08 19:58:47 +0000
30@@ -19,7 +19,7 @@
31
32 # limits for the avoidable query function
33 MAX_QUERY_LENGTH = 100
34-MAX_REPETEAD_IN_A_ROW = 5
35+MAX_REPEATED_IN_A_ROW = 5
36
37
38 def full_icon_url(name):
39@@ -82,13 +82,14 @@
40 return True
41
42 # detect a "lot of same letter in the row"
43- cnt = 0
44+ cnt = 1
45 prev = None
46 for char in query:
47 if char == prev:
48 cnt += 1
49- if cnt > MAX_REPETEAD_IN_A_ROW:
50+ if cnt > MAX_REPEATED_IN_A_ROW:
51 return True
52 else:
53- cnt = 0
54+ cnt = 1
55 prev = char
56+ return False

Subscribers

People subscribed via source and target branches