Exemplo n.º 1
0
    def test_externalize_reacts_to_exceptions(self):
        """If unhandled, exceptions in externalize hang forever. Catch them."""

        def fail():

            raise Exception()

        test = BasicPerfTest('','')
        with self.assertRaises(Exception):

            test._externalize(fail)
Exemplo n.º 2
0
    def test_externalize_runs_somewhere_else(self):

        success = True

        def toggle():

            global success
            success = False

        test = BasicPerfTest('', '')
        test._externalize(toggle)
        self.assertTrue(success)
Exemplo n.º 3
0
    def test_profile_runs_both(self):

        test = BasicPerfTest('for x in list(range(10)): pass')
        results = test(samples=100)

        self.assertTrue(results.runtime.runtime > 0)
        self.assertTrue(results.memory.max > 0)
Exemplo n.º 4
0
    def test_memory_behaves_resonably(self):
        """Check that obviously more consuming code is measured as bigger."""

        test1 = BasicPerfTest('for x in list(range(1)): pass')
        test2 = BasicPerfTest('for x in list(range(10000)): pass')

        mem1 = test1.memory()
        mem2 = test2.memory()

        self.assertTrue(mem1.max < mem2.max)
Exemplo n.º 5
0
    def test_time_behaves_reasonably(self):
        """Check that obviously longer code is measured as longer running."""

        test1 = BasicPerfTest('for x in range(10): pass')
        test2 = BasicPerfTest('for x in range(10000): pass')

        time1 = test1.time(samples=100)
        time2 = test2.time(samples=100)

        self.assertTrue(time1.runtime < time2.runtime)