Browse Source

PEP8/Pyflakes clean up

Alois Mahdal 10 years ago
parent
commit
6f2cfddb4d
2 changed files with 28 additions and 42 deletions
  1. 1
    1
      setup.py
  2. 27
    41
      sznqalibs/hoover.py

+ 1
- 1
setup.py View File

7
       author='Seznam.cz, a.s.',
7
       author='Seznam.cz, a.s.',
8
       author_email='opensource@firma.seznam.cz',
8
       author_email='opensource@firma.seznam.cz',
9
       url='https://github.com/seznam/szn-qalibs',
9
       url='https://github.com/seznam/szn-qalibs',
10
-      packages=['sznqalibs',],
10
+      packages=['sznqalibs', ],
11
       test_suite="tests",
11
       test_suite="tests",
12
       )
12
       )

+ 27
- 41
sznqalibs/hoover.py View File

12
 from copy import deepcopy
12
 from copy import deepcopy
13
 
13
 
14
 
14
 
15
-###############################################################################
16
-## The Motor                                                                 ##
17
-###############################################################################
15
+# ########################################################################### #
16
+# ## The Motor                                                             ## #
17
+# ########################################################################### #
18
 
18
 
19
 def regression_test(argsrc, tests, driver_settings, cleanup_hack=None,
19
 def regression_test(argsrc, tests, driver_settings, cleanup_hack=None,
20
                     apply_hacks=None, on_next=None):
20
                     apply_hacks=None, on_next=None):
69
         on_next(argset, last_argset)
69
         on_next(argset, last_argset)
70
         counter.add('on_next', time.time() - on_start)
70
         counter.add('on_next', time.time() - on_start)
71
 
71
 
72
-        ## load the data first, only once for each driver
72
+        # # load the data first, only once for each driver
73
         #
73
         #
74
         data = {}
74
         data = {}
75
         for aclass in all_classes:
75
         for aclass in all_classes:
151
     return d.data
151
     return d.data
152
 
152
 
153
 
153
 
154
-###############################################################################
155
-## The Pattern                                                               ##
156
-###############################################################################
154
+# ########################################################################### #
155
+# ## The Pattern                                                           ## #
156
+# ########################################################################### #
157
 
157
 
158
 class _BaseRuleOp():
158
 class _BaseRuleOp():
159
 
159
 
213
         return bool(op(items, item_ok))
213
         return bool(op(items, item_ok))
214
 
214
 
215
 
215
 
216
-###############################################################################
217
-## The Path                                                                  ##
218
-###############################################################################
216
+# ########################################################################### #
217
+# ## The Path                                                              ## #
218
+# ########################################################################### #
219
 
219
 
220
 class DictPath():
220
 class DictPath():
221
     """Mixin that adds "path-like" behavior to the top dict of dicts.
221
     """Mixin that adds "path-like" behavior to the top dict of dicts.
275
             subdct = dct[frag]
275
             subdct = dct[frag]
276
             return cls.__delitem(subdct, rest)
276
             return cls.__delitem(subdct, rest)
277
 
277
 
278
-    ## public methods
278
+    # # public methods
279
     #
279
     #
280
 
280
 
281
     def getpath(self, path):
281
     def getpath(self, path):
304
             return False
304
             return False
305
 
305
 
306
 
306
 
307
-###############################################################################
308
-## The Case                                                                  ##
309
-###############################################################################
307
+# ########################################################################### #
308
+# ## The Case                                                              ## #
309
+# ########################################################################### #
310
 
310
 
311
 class TinyCase(dict, DictPath):
311
 class TinyCase(dict, DictPath):
312
     """Abstraction of the smallest unit of testing.
312
     """Abstraction of the smallest unit of testing.
480
         return matched
480
         return matched
481
 
481
 
482
 
482
 
483
-###############################################################################
484
-## Drivers                                                                   ##
485
-###############################################################################
483
+# ########################################################################### #
484
+# ## Drivers                                                               ## #
485
+# ########################################################################### #
486
 
486
 
487
 class DriverError(Exception):
487
 class DriverError(Exception):
488
     """Error encountered when obtaining driver data"""
488
     """Error encountered when obtaining driver data"""
705
         self.data = True
705
         self.data = True
706
 
706
 
707
 
707
 
708
-###############################################################################
709
-## Helpers                                                                   ##
710
-###############################################################################
708
+# ########################################################################### #
709
+# ## Helpers                                                               ## #
710
+# ########################################################################### #
711
 
711
 
712
 class StatCounter(object):
712
 class StatCounter(object):
713
     """A simple counter with formulas support."""
713
     """A simple counter with formulas support."""
728
         }
728
         }
729
 
729
 
730
         ##
730
         ##
731
-        ## Formulas.  A lot of them.
732
-        ##
733
-
734
-        ## cumulative duration/overhead; just round to ms
731
+        # Formulas
735
         #
732
         #
733
+
734
+        # cumulative duration/overhead; just round to ms
736
         self.add_formula(dname + '_overhead',
735
         self.add_formula(dname + '_overhead',
737
                          lambda g, d: int(1000 * d[dname]['overhead']))
736
                          lambda g, d: int(1000 * d[dname]['overhead']))
738
         self.add_formula(dname + '_duration',
737
         self.add_formula(dname + '_duration',
739
                          lambda g, d: int(1000 * d[dname]['duration']))
738
                          lambda g, d: int(1000 * d[dname]['duration']))
740
 
739
 
741
-        ## average (per driver call) overhead/duration
742
-        #
740
+        # average (per driver call) overhead/duration
743
         self.add_formula(
741
         self.add_formula(
744
             dname + '_overhead_per_call',
742
             dname + '_overhead_per_call',
745
             lambda g, d: int(1000 * d[dname]['overhead'] / d[dname]['calls'])
743
             lambda g, d: int(1000 * d[dname]['overhead'] / d[dname]['calls'])
749
             lambda g, d: int(1000 * d[dname]['duration'] / d[dname]['calls'])
747
             lambda g, d: int(1000 * d[dname]['duration'] / d[dname]['calls'])
750
         )
748
         )
751
 
749
 
752
-        ## grand totals in times: driver time, loop overhead
753
-        #
754
         def gtotal_drivertime(g, d):
750
         def gtotal_drivertime(g, d):
755
             driver_time = (sum(s['overhead'] for s in d.values())
751
             driver_time = (sum(s['overhead'] for s in d.values())
756
                            + sum(s['duration'] for s in d.values()))
752
                            + sum(s['duration'] for s in d.values()))
762
             age = int(1000 * (time.time() - self._born))
758
             age = int(1000 * (time.time() - self._born))
763
             return age - driver_time - onnext_time
759
             return age - driver_time - onnext_time
764
 
760
 
761
+        # grand totals in times: driver time, loop overhead
765
         self.add_formula('gtotal_drivertime', gtotal_drivertime)
762
         self.add_formula('gtotal_drivertime', gtotal_drivertime)
766
         self.add_formula('gtotal_loop_overhead', gtotal_loop_overhead)
763
         self.add_formula('gtotal_loop_overhead', gtotal_loop_overhead)
767
         self.add_formula('gtotal_loop_onnext',
764
         self.add_formula('gtotal_loop_onnext',
768
                          lambda g, d: int(1000 * g['on_next']))
765
                          lambda g, d: int(1000 * g['on_next']))
769
 
766
 
770
-        ## average (per driver call) overhead/duration
771
-        #
767
+        # average (per driver call) overhead/duration
772
         self.add_formula(
768
         self.add_formula(
773
             'cases_hacked',
769
             'cases_hacked',
774
             lambda g, d: round(100 * float(g['hacked_cases']) / g['cases'], 2)
770
             lambda g, d: round(100 * float(g['hacked_cases']) / g['cases'], 2)
884
 
880
 
885
     def _insert(self, errstr, argset):
881
     def _insert(self, errstr, argset):
886
         """Insert the argset into DB."""
882
         """Insert the argset into DB."""
887
-        if not errstr in self._db:
883
+        if errstr not in self._db:
888
             self._db[errstr] = []
884
             self._db[errstr] = []
889
         self._db[errstr].append(argset)
885
         self._db[errstr].append(argset)
890
 
886
 
997
                     cw.writerow(argset)
993
                     cw.writerow(argset)
998
 
994
 
999
 
995
 
1000
-## ............................................................................
1001
-## dataMatch -- a data structure matcher
1002
-##
1003
-#
1004
-
1005
 def dataMatch(pattern, data, rmax=10, _r=0):
996
 def dataMatch(pattern, data, rmax=10, _r=0):
1006
     """Check if data structure matches a pattern data structure.
997
     """Check if data structure matches a pattern data structure.
1007
 
998
 
1216
     return "\n".join(compress([line for line in udiff]))
1207
     return "\n".join(compress([line for line in udiff]))
1217
 
1208
 
1218
 
1209
 
1219
-#
1220
-## Cartman - create dict arguments from dicts of available values (iterables)
1221
-#            and a defined scheme
1222
-#
1223
-
1224
 class Cartman(object):
1210
 class Cartman(object):
1225
     """Create argument sets from ranges (or ay iterators) of values.
1211
     """Create argument sets from ranges (or ay iterators) of values.
1226
 
1212