Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/filterhits/test/geometrical_mean_tests.py

Issue 4615801646612480: Issue 395 - Filter hits statistics backend (Closed)
Left Patch Set: Created base class for tests and reverted earlier content-type change. Created April 1, 2015, 7:01 p.m.
Right Patch Set: Addressed further comments from Sebastian. Created April 2, 2015, 10:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/filterhits/test/db_tests.py ('k') | sitescripts/filterhits/test/log_tests.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 class GeometricalMeanTestCase(test_helpers.FilterhitsTestCase): 70 class GeometricalMeanTestCase(test_helpers.FilterhitsTestCase):
71 longMessage = True 71 longMessage = True
72 maxDiff = None 72 maxDiff = None
73 73
74 def geometrical(self, interval, new, new_timestamp, old, old_timestamp): 74 def geometrical(self, interval, new, new_timestamp, old, old_timestamp):
75 delta_divby_interval = (new_timestamp - old_timestamp) / 1000 / float(interv al) 75 delta_divby_interval = (new_timestamp - old_timestamp) / 1000 / float(interv al)
76 return long(round(old ** (1 - delta_divby_interval) * new ** delta_divby_int erval)) 76 return long(round(old ** (1 - delta_divby_interval) * new ** delta_divby_int erval))
77 77
78 def test_calculations(self): 78 def test_calculations(self):
79 if not self.db:
80 raise unittest.SkipTest("Not connected to test DB.")
81
82 interval = 86400 79 interval = 86400
83 80
84 # Tables should be empty to start with 81 # Tables should be empty to start with
85 self.assertEqual(db.query(self.db, "SELECT * FROM filters"), ()) 82 self.assertEqual(db.query(self.db, "SELECT * FROM filters"), ())
86 self.assertEqual(db.query(self.db, "SELECT * FROM frequencies"), ()) 83 self.assertEqual(db.query(self.db, "SELECT * FROM frequencies"), ())
87 # First batch 84 # First batch
88 db.write(self.db, geometrical_mean.update(interval, test_data[0])) 85 db.write(self.db, geometrical_mean.update(interval, test_data[0]))
89 self.assertEqual(db.query(self.db, "SELECT * FROM filters"), 86 self.assertEqual(db.query(self.db, "SELECT * FROM filters"),
90 (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), 87 (("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"),
91 u"##.top-box-right-ad"),)) 88 u"##.top-box-right-ad"),))
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 14L, datetime.utcfromtimestamp(1415032601175 / 1000)), 157 14L, datetime.utcfromtimestamp(1415032601175 / 1000)),
161 ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"yahoo.com", 158 ("8c5ea548436c61f05536e205a29ada6204f603b0".decode("hex"), u"yahoo.com",
162 self.geometrical(interval, 43, 1415045194098, 159 self.geometrical(interval, 43, 1415045194098,
163 self.geometrical(interval, 27, 1414917270343, 160 self.geometrical(interval, 27, 1414917270343,
164 14, 1414859271125), 161 14, 1414859271125),
165 1414917270343), 162 1414917270343),
166 datetime.utcfromtimestamp(1415045194098 / 1000)))) 163 datetime.utcfromtimestamp(1415045194098 / 1000))))
167 164
168 if __name__ == "__main__": 165 if __name__ == "__main__":
169 unittest.main() 166 unittest.main()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld