-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* benchmark-base-case * up-version-to-0.2.10
- Loading branch information
Showing
8 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from contesto import ContestoTestCase, config | ||
from contesto.utils.log import log | ||
|
||
|
||
class BenchmarkBaseCase(ContestoTestCase): | ||
def __init__(self, test_name='runTest'): | ||
super(BenchmarkBaseCase, self).__init__(test_name) | ||
self.run_count = config.benchmark.get('run_count', 1) | ||
self._single_method = getattr(self, self._testMethodName) | ||
setattr(self, self._testMethodName, self.run_multiple_times) | ||
|
||
def run_multiple_times(self): | ||
for i in range(1, self.run_count + 1): | ||
log.debug('Benchmark iter {}'.format(i)) | ||
try: | ||
res = self._single_method() | ||
except: | ||
log.exception('Benchmark iter {} exception:'.format(i)) | ||
raise | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ platform: ANY | |
[browsermobproxy] | ||
enabled: 0 | ||
url: localhost:8080 | ||
|
||
[benchmark] | ||
run_count: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from contesto import BenchmarkBaseCase | ||
|
||
|
||
class TestBenchmarkExamples(BenchmarkBaseCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
print('\nmake setupclass') | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
print('make teardownclass') | ||
|
||
def setUp(self): | ||
print('\tmake setup') | ||
|
||
def tearDown(self): | ||
print('\tmake teardown') | ||
|
||
def test_benchmark_app_start(self): | ||
""" | ||
AppStart scenario example ("do nothing") | ||
""" | ||
print('\t\tHey! I\'m app-start scenario!') | ||
|
||
def test_benchmark_search(self): | ||
""" | ||
Search scenario example | ||
""" | ||
print('\t\tHey! I\'m search scenario!') | ||
print('\t\tSearching \'beer\'') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding: utf-8 | ||
|
||
try: | ||
from mock import Mock | ||
except ImportError: | ||
from unittest.mock import Mock | ||
|
||
import unittest | ||
|
||
from contesto import BenchmarkBaseCase, config | ||
|
||
|
||
def make(): | ||
class TestFakeBenchmark(BenchmarkBaseCase): | ||
mock = Mock() | ||
|
||
@classmethod | ||
def _create_session(cls, *args, **kwargs): | ||
return Mock() | ||
|
||
def test_method(self): | ||
self.mock() | ||
|
||
return TestFakeBenchmark('test_method') | ||
|
||
|
||
class TestBenchmarkBaseCase(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls._config_benchmark_run_count = config.benchmark["run_count"] | ||
config.benchmark["run_count"] = 5 | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
config.benchmark["run_count"] = cls._config_benchmark_run_count | ||
|
||
def test_multiple_run(self): | ||
benchmark = make() | ||
benchmark.run() | ||
self.assertEqual(benchmark.mock.call_count, 5) |