예제 #1
0
    def test_externalize_reacts_to_exceptions(self):
        """If unhandled, exceptions in externalize hang forever. Catch them."""
        def fail():

            raise ValueError()

        test = BasicProfile('', '')
        with self.assertRaises(ValueError):

            test._externalize(fail)
예제 #2
0
    def test_memory_behaves_resonably(self):
        """Check that obviously more consuming code is measured as bigger."""

        test1 = BasicProfile('for x in list(range(1)): pass')
        test2 = BasicProfile('for x in list(range(100000)): pass')

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

        self.assertTrue(mem1.max < mem2.max)
예제 #3
0
    def test_time_behaves_reasonably(self):
        """Check that obviously longer code is measured as longer running."""

        test1 = BasicProfile('for x in range(10): pass')
        test2 = BasicProfile('for x in range(100000): pass')

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

        self.assertTrue(time1 < time2)
예제 #4
0
    def test_externalize_reacts_to_exceptions(self):
        """If unhandled, exceptions in externalize hang forever. Catch them."""

        def fail():

            raise ValueError()

        test = BasicProfile('','')
        with self.assertRaises(ValueError):

            test._externalize(fail)
예제 #5
0
    def test_externalize_runs_somewhere_else(self):

        success = True

        def toggle():

            # This will only affect the success variable above if the code
            # is executed in the same Python process as the test.
            global success
            success = False

        test = BasicProfile('', '')
        test._externalize(toggle)
        self.assertTrue(success)
예제 #6
0
    def test_externalize_runs_somewhere_else(self):

        success = True

        def toggle():

            # This will only affect the success variable above if the code
            # is executed in the same Python process as the test.
            global success
            success = False

        test = BasicProfile('', '')
        test._externalize(toggle)
        self.assertTrue(success)
예제 #7
0
    def test_call_runs_both(self):

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

        self.assertTrue(results.runtime > 0)
        self.assertTrue(results.memory.max > 0)
예제 #8
0
    def test_memory_behaves_resonably(self):
        """Check that obviously more consuming code is measured as bigger."""

        test1 = BasicProfile('for x in list(range(1)): pass')
        test2 = BasicProfile('for x in list(range(100000)): pass')

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

        self.assertTrue(mem1.max < mem2.max)
예제 #9
0
    def test_time_behaves_reasonably(self):
        """Check that obviously longer code is measured as longer running."""

        test1 = BasicProfile('for x in range(10): pass')
        test2 = BasicProfile('for x in range(100000): pass')

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

        self.assertTrue(time1 < time2)