def on_teardown(self, suite): if not suite.config.VERBOSE: 'on_teardown from suite layer' # for example def on_any_error(self, error, suite, result): pass def on_error(self, error, suite, result): pass def on_context_error(self, error, suite, result): pass suite = Suite(__name__, layers=[SuiteLayerExample()]) @suite.register def test_of_suite(case): case.assertion.true(hasattr(suite, 'on_init_was_call')) case.assertion.true(hasattr(suite, 'on_mount_was_call')) case.assertion.true(hasattr(suite, 'on_run_was_call')) class ExampleSuite(Suite): __layers__ = (SuiteLayerExample(), ) my_suite = ExampleSuite(__name__ + '.example_suite')
# -*- coding: utf-8 -*- from seismograph import Suite, Case, CaseLayer suite = Suite(__name__) class ExampleCaseLayer(CaseLayer): def on_init(self, case): setattr(case, 'on_init_was_call', True) def on_setup(self, case): if not case.config.VERBOSE: case.print_hello() def on_teardown(self, case): if not case.config.VERBOSE: case.print_bye() def on_run(self, case): setattr(case, 'on_run_was_call', True) # for example def on_skip(self, case, reason, result): pass def on_any_error(self, error, case, result, tb, timer): pass def on_error(self, error, case, result, tb, timer): pass
# -*- coding: utf-8 -*- from seismograph import Suite from seismograph.ext import selenium suite = Suite(__name__, require=['selenium']) @suite.register def test_google_search(case): with case.ext('selenium') as browser: browser.router.go_to('/') browser.input(name='q').set('python') browser.button(name='btnG').click() selenium.assertion.text_exist(browser, 'python') @suite.register(case_class=selenium.Case, static=True) def test_google_search_static(browser): browser.router.go_to('/') browser.input(name='q').set('python') browser.button(name='btnG').click() selenium.assertion.text_exist(browser, 'python')
# -*- coding: utf-8 -*- from seismograph import Case, Suite suite = Suite(__name__, require=['mocker']) @suite.register class TestMocksFromFiles(Case): server = None def setup(self): self.server = self.ext('mocker') self.server.start() def teardown(self): self.server.stop() def test_hello_get(self): response = self.server.client.get('/hello') self.assertion.equal(response.status_code, 200) self.assertion.equal(response.headers['Server'], 'nginx/1.2.1') data = response.json() self.assertion.is_instance(data['data'], list) self.assertion.equal(data['test']['test'], 3.5) self.assertion.equal(data['hello'], 'hello world!') def test_hello_put(self):
# -*- coding: utf-8 -*- from seismograph import Suite from seismograph.ext.alchemy.exceptions import InvalidBindKey from .models import UsersModel suite = Suite(__name__, require=['db']) @suite.register def simple_test(case): db = case.ext('db') def incorrect_bind_key(): with db.read('incorrect_bind_key'): execute('SELECT * FROM PLUGINS').fetchall() case.assertion.raises(InvalidBindKey, incorrect_bind_key) with db.read() as execute: result = execute('SELECT * FROM PLUGINS').fetchall() case.assertion.greater(len(result), 0) @suite.register def test_model(case): db = case.ext('db') def incorrect_bind_key():