From 2392b7d6b900e75655934f4e8591e54d81d14503 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Sun, 18 May 2014 00:15:00 -0700 Subject: [PATCH] test counter utils --- SimPEG/Tests/test_utils.py | 20 ++++++++++++++++++++ SimPEG/Utils/CounterUtils.py | 19 ------------------- docs/api_Utils.rst | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/SimPEG/Tests/test_utils.py b/SimPEG/Tests/test_utils.py index 8e3c034d..6318527a 100644 --- a/SimPEG/Tests/test_utils.py +++ b/SimPEG/Tests/test_utils.py @@ -26,6 +26,26 @@ class TestCheckDerivative(unittest.TestCase): self.assertTrue(not passed, True) +class TestCounter(unittest.TestCase): + def test_simpleFail(self): + class MyClass(object): + def __init__(self, url): + self.counter = Counter() + + @count + def MyMethod(self): + pass + + @timeIt + def MySecondMethod(self): + pass + + c = MyClass('blah') + for i in range(100): c.MyMethod() + for i in range(300): c.MySecondMethod() + c.counter.summary() + self.assertTrue(True) + class TestSequenceFunctions(unittest.TestCase): def setUp(self): diff --git a/SimPEG/Utils/CounterUtils.py b/SimPEG/Utils/CounterUtils.py index fd9b7727..9cd34d2c 100644 --- a/SimPEG/Utils/CounterUtils.py +++ b/SimPEG/Utils/CounterUtils.py @@ -93,22 +93,3 @@ def timeIt(f): if type(counter) is Counter: counter.countToc(self.__class__.__name__+'.'+f.__name__) return out return wrapper - - -if __name__ == '__main__': - class MyClass(object): - def __init__(self, url): - self.counter = Counter() - - @count - def MyMethod(self): - pass - - @timeIt - def MySecondMethod(self): - pass - - c = MyClass('blah') - for i in range(100): c.MyMethod() - for i in range(300): c.MySecondMethod() - c.counter.summary() diff --git a/docs/api_Utils.rst b/docs/api_Utils.rst index 0ea3e22e..7903cdc4 100644 --- a/docs/api_Utils.rst +++ b/docs/api_Utils.rst @@ -51,3 +51,39 @@ Interpolation Utilities :members: :undoc-members: +Counter Utilities +======================= + +:: + class MyClass(object): + def __init__(self, url): + self.counter = Counter() + + @count + def MyMethod(self): + pass + + @timeIt + def MySecondMethod(self): + pass + + c = MyClass('blah') + for i in range(100): c.MyMethod() + for i in range(300): c.MySecondMethod() + c.counter.summary() + +:: + + Counters: + MyClass.MyMethod : 100 + + Times: mean sum + MyClass.MySecondMethod : 1.70e-06, 5.10e-04, 300x + +The API +------- + +.. automodule:: SimPEG.Utils.CounterUtils + :members: + :undoc-members: +