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
=== modified file 'src/tests/test_utils.py'
--- src/tests/test_utils.py 2015-03-31 15:03:35 +0000
+++ src/tests/test_utils.py 2015-04-08 19:58:47 +0000
@@ -70,3 +70,21 @@
70 def test_too_repeated_twice(self):70 def test_too_repeated_twice(self):
71 q = u"adjskajhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmb,mb,mb,mb,hkkkkkkkkkkkkkkkkkkkkkkkkkpouiud"71 q = u"adjskajhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmb,mb,mb,mb,hkkkkkkkkkkkkkkkkkkkkkkkkkpouiud"
72 self.assertTrue(utils.avoidable_query(q))72 self.assertTrue(utils.avoidable_query(q))
73
74 def test_simple_repeated_5(self):
75 q = u"x" * utils.MAX_REPEATED_IN_A_ROW
76 self.assertFalse(utils.avoidable_query(q))
77
78 def test_simple_repeated_6(self):
79 q = u"x" * (utils.MAX_REPEATED_IN_A_ROW + 1)
80 self.assertTrue(utils.avoidable_query(q))
81
82 def test_simple_repeated_7(self):
83 q = u"x" * (utils.MAX_REPEATED_IN_A_ROW + 2)
84 self.assertTrue(utils.avoidable_query(q))
85
86 def test_simple_repeated_again(self):
87 q = u"x" * utils.MAX_REPEATED_IN_A_ROW
88 q += u"yz"
89 q += u"x" * (utils.MAX_REPEATED_IN_A_ROW + 1)
90 self.assertTrue(utils.avoidable_query(q))
7391
=== modified file 'src/utils.py'
--- src/utils.py 2015-03-31 15:03:35 +0000
+++ src/utils.py 2015-04-08 19:58:47 +0000
@@ -19,7 +19,7 @@
1919
20# limits for the avoidable query function20# limits for the avoidable query function
21MAX_QUERY_LENGTH = 10021MAX_QUERY_LENGTH = 100
22MAX_REPETEAD_IN_A_ROW = 522MAX_REPEATED_IN_A_ROW = 5
2323
2424
25def full_icon_url(name):25def full_icon_url(name):
@@ -82,13 +82,14 @@
82 return True82 return True
8383
84 # detect a "lot of same letter in the row"84 # detect a "lot of same letter in the row"
85 cnt = 085 cnt = 1
86 prev = None86 prev = None
87 for char in query:87 for char in query:
88 if char == prev:88 if char == prev:
89 cnt += 189 cnt += 1
90 if cnt > MAX_REPETEAD_IN_A_ROW:90 if cnt > MAX_REPEATED_IN_A_ROW:
91 return True91 return True
92 else:92 else:
93 cnt = 093 cnt = 1
94 prev = char94 prev = char
95 return False

Subscribers

People subscribed via source and target branches