Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: third_party/typ/typ/stats.py

Issue 627763002: Add new 'typ' python testing framework to third_party/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: upload to typ v0.8.1, update README.chromium Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/typ/typ/stats.py
diff --git a/third_party/typ/typ/stats.py b/third_party/typ/typ/stats.py
new file mode 100644
index 0000000000000000000000000000000000000000..0cd408dc76a37cdba775fba55b25ebf0ee9e03c0
--- /dev/null
+++ b/third_party/typ/typ/stats.py
@@ -0,0 +1,83 @@
+# Copyright 2014 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class Stats(object):
+
+ def __init__(self, status_format, time_fn, size):
+ self.fmt = status_format
+ self.finished = 0
+ self.started = 0
+ self.total = 0
+ self.started_time = time_fn()
+ self._times = []
+ self._size = size
+ self._time = time_fn
+ self._times.append(self.started_time)
+
+ def add_time(self):
+ if len(self._times) > self._size:
+ self._times.pop(0)
+ self._times.append(self._time())
+
+ def format(self):
+ # Too many statements pylint: disable=R0915
+ out = ''
+ p = 0
+ end = len(self.fmt)
+ while p < end:
+ c = self.fmt[p]
+ if c == '%' and p < end - 1:
+ cn = self.fmt[p + 1]
+ if cn == 'c':
+ elapsed = self._times[-1] - self._times[0]
+ if elapsed > 0:
+ out += '%5.1f' % ((len(self._times) - 1) / elapsed)
+ else:
+ out += '-'
+ elif cn == 'e':
+ now = self._time()
+ assert now >= self.started_time
+ out += '%-5.3f' % (now - self.started_time)
+ elif cn == 'f':
+ out += str(self.finished)
+ elif cn == 'o':
+ now = self._time()
+ if now > self.started_time:
+ out += '%5.1f' % (self.finished * 1.0 /
+ (now - self.started_time))
+ else:
+ out += '-'
+ elif cn == 'p':
+ if self.total:
+ out += '%5.1f' % (self.started * 100.0 / self.total)
+ else:
+ out += '-'
+ elif cn == 'r':
+ out += str(self.started - self.finished)
+ elif cn == 's':
+ out += str(self.started)
+ elif cn == 't':
+ out += str(self.total)
+ elif cn == 'u':
+ out += str(self.total - self.finished)
+ elif cn == '%':
+ out += '%'
+ else:
+ out += c + cn
+ p += 2
+ else:
+ out += c
+ p += 1
+ return out

Powered by Google App Engine
This is Rietveld 408576698